1 | /* IcedTeaPluginRequestProcessor.h
|
---|
2 |
|
---|
3 | Copyright (C) 2009, 2010 Red Hat
|
---|
4 |
|
---|
5 | This file is part of IcedTea.
|
---|
6 |
|
---|
7 | IcedTea is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | IcedTea is distributed in the hope that it will be useful, but
|
---|
13 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with IcedTea; see the file COPYING. If not, write to the
|
---|
19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
20 | 02110-1301 USA.
|
---|
21 |
|
---|
22 | Linking this library statically or dynamically with other modules is
|
---|
23 | making a combined work based on this library. Thus, the terms and
|
---|
24 | conditions of the GNU General Public License cover the whole
|
---|
25 | combination.
|
---|
26 |
|
---|
27 | As a special exception, the copyright holders of this library give you
|
---|
28 | permission to link this library with independent modules to produce an
|
---|
29 | executable, regardless of the license terms of these independent
|
---|
30 | modules, and to copy and distribute the resulting executable under
|
---|
31 | terms of your choice, provided that you also meet, for each linked
|
---|
32 | independent module, the terms and conditions of the license of that
|
---|
33 | module. An independent module is a module which is not derived from
|
---|
34 | or based on this library. If you modify this library, you may extend
|
---|
35 | this exception to your version of the library, but you are not
|
---|
36 | obligated to do so. If you do not wish to do so, delete this
|
---|
37 | exception statement from your version. */
|
---|
38 |
|
---|
39 | #ifndef __ICEDTEAPLUGINREQUESTPROCESSOR_H__
|
---|
40 | #define __ICEDTEAPLUGINREQUESTPROCESSOR_H__
|
---|
41 |
|
---|
42 | #include <map>
|
---|
43 | #include <stdio.h>
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <pthread.h>
|
---|
46 | #include <time.h>
|
---|
47 |
|
---|
48 | #include <npapi.h>
|
---|
49 | #include <npruntime.h>
|
---|
50 |
|
---|
51 | #include "IcedTeaPluginUtils.h"
|
---|
52 | #include "IcedTeaJavaRequestProcessor.h"
|
---|
53 |
|
---|
54 | /* Internal request reference counter */
|
---|
55 | static long internal_req_ref_counter;
|
---|
56 |
|
---|
57 | /* Given a value and type, performs the appropriate Java->JS type
|
---|
58 | * mapping and puts it in the given variant */
|
---|
59 |
|
---|
60 | static void convertToNPVariant(std::string value, std::string type, NPVariant* result_variant);
|
---|
61 |
|
---|
62 | // Internal methods that need to run in main thread
|
---|
63 | void _getMember(void* data);
|
---|
64 | void _setMember(void* data);
|
---|
65 | void _call(void* data);
|
---|
66 | void _eval(void* data);
|
---|
67 | void _getString(void* data);
|
---|
68 | void _loadURL(void* data);
|
---|
69 |
|
---|
70 | void* queue_processor(void* data);
|
---|
71 |
|
---|
72 | #ifdef __OS2__
|
---|
73 | struct QueueProcessorData;
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Processes requests made TO the plugin (by java or anyone else)
|
---|
78 | */
|
---|
79 | class PluginRequestProcessor : public BusSubscriber
|
---|
80 | {
|
---|
81 | private:
|
---|
82 |
|
---|
83 | /* Mutex to ensure that the request queue is accessed synchronously */
|
---|
84 | pthread_mutex_t message_queue_mutex;
|
---|
85 |
|
---|
86 | /* Condition on which the queue processor waits */
|
---|
87 | pthread_cond_t cond_message_available;
|
---|
88 |
|
---|
89 | /* Queue for holding messages that get processed in a separate thread */
|
---|
90 | std::vector< std::vector<std::string*>* >* message_queue;
|
---|
91 |
|
---|
92 | /* Mutex to ensure synchronized writes */
|
---|
93 | pthread_mutex_t syn_write_mutex;
|
---|
94 |
|
---|
95 | /* Dispatch request processing to a new thread for asynch. processing */
|
---|
96 | void dispatch(void* func_ptr (void*), std::vector<std::string>* message, std::string* src);
|
---|
97 |
|
---|
98 | /* Send main window pointer to Java */
|
---|
99 | void sendWindow(std::vector<std::string*>* message_parts);
|
---|
100 |
|
---|
101 | /* Stores the variant on java side */
|
---|
102 | void storeVariantInJava(NPVariant variant, std::string* result);
|
---|
103 |
|
---|
104 | /* Send member ID to Java */
|
---|
105 | void sendMember(std::vector<std::string*>* message_parts);
|
---|
106 |
|
---|
107 | /* Set member to given value */
|
---|
108 | void setMember(std::vector<std::string*>* message_parts);
|
---|
109 |
|
---|
110 | /* Send string value of requested object */
|
---|
111 | void sendString(std::vector<std::string*>* message_parts);
|
---|
112 |
|
---|
113 | /* Evaluate the given script */
|
---|
114 | void eval(std::vector<std::string*>* message_parts);
|
---|
115 |
|
---|
116 | /* Evaluate the given script */
|
---|
117 | void call(std::vector<std::string*>* message_parts);
|
---|
118 |
|
---|
119 | /* Decrements reference count for given object */
|
---|
120 | void finalize(std::vector<std::string*>* message_parts);
|
---|
121 |
|
---|
122 | /* Loads a URL into the specified target */
|
---|
123 | void loadURL(std::vector<std::string*>* message_parts);
|
---|
124 |
|
---|
125 | public:
|
---|
126 | PluginRequestProcessor(); /* Constructor */
|
---|
127 | ~PluginRequestProcessor(); /* Destructor */
|
---|
128 |
|
---|
129 | /* Process new requests (if applicable) */
|
---|
130 | virtual bool newMessageOnBus(const char* message);
|
---|
131 |
|
---|
132 | /* Thread run method for processing queued messages */
|
---|
133 | #ifdef __OS2__
|
---|
134 | void queueProcessorThread(QueueProcessorData *queue_processor_data);
|
---|
135 | void cancelWait() { pthread_cond_broadcast(&cond_message_available); }
|
---|
136 | #else
|
---|
137 | void queueProcessorThread();
|
---|
138 | #endif
|
---|
139 | };
|
---|
140 |
|
---|
141 | #endif // __ICEDTEAPLUGINREQUESTPROCESSOR_H__
|
---|