1 | /* IcedTeaJavaRequestProcessor.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 ICEDTEAJAVAREQUEST_H_
|
---|
40 | #define ICEDTEAJAVAREQUEST_H_
|
---|
41 |
|
---|
42 | #include <errno.h>
|
---|
43 | #include <stdlib.h>
|
---|
44 | #include <unistd.h>
|
---|
45 | #include <vector>
|
---|
46 |
|
---|
47 | #include "IcedTeaNPPlugin.h"
|
---|
48 | #include "IcedTeaPluginUtils.h"
|
---|
49 |
|
---|
50 | #define REQUESTTIMEOUT 180
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * This struct holds data specific to a Java operation requested by the plugin
|
---|
54 | */
|
---|
55 | typedef struct java_request
|
---|
56 | {
|
---|
57 | // Instance id (if applicable)
|
---|
58 | int instance;
|
---|
59 |
|
---|
60 | // Context id (if applicable)
|
---|
61 | int context;
|
---|
62 |
|
---|
63 | // request specific data
|
---|
64 | std::vector<std::string>* data;
|
---|
65 |
|
---|
66 | // source of the request
|
---|
67 | std::string* source;
|
---|
68 |
|
---|
69 | } JavaRequest;
|
---|
70 |
|
---|
71 | /* Creates a argument on java-side with appropriate type */
|
---|
72 | void createJavaObjectFromVariant(NPP instance, NPVariant variant, std::string* id);
|
---|
73 |
|
---|
74 | /* Returns the type of array based on the given element */
|
---|
75 | void getArrayTypeForJava(NPP instance, NPVariant element, std::string* type);
|
---|
76 |
|
---|
77 | class JavaRequestProcessor : BusSubscriber
|
---|
78 | {
|
---|
79 | private:
|
---|
80 | // instance and references are constant throughout this objects
|
---|
81 | // lifecycle
|
---|
82 | int instance;
|
---|
83 | int reference;
|
---|
84 | bool result_ready;
|
---|
85 | JavaResultData* result;
|
---|
86 |
|
---|
87 | /* Post message on bus and wait */
|
---|
88 | void postAndWaitForResponse(std::string message);
|
---|
89 |
|
---|
90 | // Call a method, static or otherwise, depending on supplied arg
|
---|
91 | JavaResultData* call(std::string source, bool isStatic,
|
---|
92 | std::string objectID, std::string methodName,
|
---|
93 | std::vector<std::string> args);
|
---|
94 |
|
---|
95 | // Set a static/non-static field to given value
|
---|
96 | JavaResultData* set(std::string source,
|
---|
97 | bool isStatic,
|
---|
98 | std::string classID,
|
---|
99 | std::string objectID,
|
---|
100 | std::string fieldName,
|
---|
101 | std::string value_id);
|
---|
102 |
|
---|
103 | /* Resets the results */
|
---|
104 | void resetResult();
|
---|
105 |
|
---|
106 | public:
|
---|
107 | JavaRequestProcessor();
|
---|
108 | ~JavaRequestProcessor();
|
---|
109 | virtual bool newMessageOnBus(const char* message);
|
---|
110 |
|
---|
111 | /* Increments reference count by 1 */
|
---|
112 | void addReference(std::string object_id);
|
---|
113 |
|
---|
114 | /* Decrements reference count by 1 */
|
---|
115 | void deleteReference(std::string object_id);
|
---|
116 |
|
---|
117 | /* Returns the toString() value, given an object identifier */
|
---|
118 | JavaResultData* getToStringValue(std::string object_id);
|
---|
119 |
|
---|
120 | /* Returns the value, given an object identifier */
|
---|
121 | JavaResultData* getValue(std::string object_id);
|
---|
122 |
|
---|
123 | /* Returns the string, given the identifier */
|
---|
124 | JavaResultData* getString(std::string string_id);
|
---|
125 |
|
---|
126 | /* Returns the field object */
|
---|
127 | JavaResultData* getField(std::string source,
|
---|
128 | std::string classID,
|
---|
129 | std::string objectID,
|
---|
130 | std::string fieldName);
|
---|
131 |
|
---|
132 | /* Returns the static field object */
|
---|
133 | JavaResultData* getStaticField(std::string source,
|
---|
134 | std::string classID,
|
---|
135 | std::string fieldName);
|
---|
136 |
|
---|
137 | /* Sets the field object */
|
---|
138 | JavaResultData* setField(std::string source,
|
---|
139 | std::string classID,
|
---|
140 | std::string objectID,
|
---|
141 | std::string fieldName,
|
---|
142 | std::string value_id);
|
---|
143 |
|
---|
144 | /* Sets the static field object */
|
---|
145 | JavaResultData* setStaticField(std::string source,
|
---|
146 | std::string classID,
|
---|
147 | std::string fieldName,
|
---|
148 | std::string value_id);
|
---|
149 |
|
---|
150 | /* Returns the field id */
|
---|
151 | JavaResultData* getFieldID(std::string classID, std::string fieldName);
|
---|
152 |
|
---|
153 | /* Returns the static field id */
|
---|
154 | JavaResultData* getStaticFieldID(std::string classID, std::string fieldName);
|
---|
155 |
|
---|
156 | /* Returns the method id */
|
---|
157 | JavaResultData* getMethodID(std::string classID, NPIdentifier methodName,
|
---|
158 | std::vector<std::string> args);
|
---|
159 |
|
---|
160 | /* Returns the static method id */
|
---|
161 | JavaResultData* getStaticMethodID(std::string classID, NPIdentifier methodName,
|
---|
162 | std::vector<std::string> args);
|
---|
163 |
|
---|
164 | /* Calls a static method */
|
---|
165 | JavaResultData* callStaticMethod(std::string source,
|
---|
166 | std::string classID,
|
---|
167 | std::string methodName,
|
---|
168 | std::vector<std::string> args);
|
---|
169 |
|
---|
170 | /* Calls a method on an instance */
|
---|
171 | JavaResultData* callMethod(std::string source,
|
---|
172 | std::string objectID,
|
---|
173 | std::string methodName,
|
---|
174 | std::vector<std::string> args);
|
---|
175 |
|
---|
176 | /* Returns the class of the given object */
|
---|
177 | JavaResultData* getObjectClass(std::string objectID);
|
---|
178 |
|
---|
179 | /* Creates a new object with choosable constructor */
|
---|
180 | JavaResultData* newObject(std::string source,
|
---|
181 | std::string classID,
|
---|
182 | std::vector<std::string> args);
|
---|
183 |
|
---|
184 | /* Creates a new object when constructor is undetermined */
|
---|
185 | JavaResultData* newObjectWithConstructor(std::string source, std::string classID,
|
---|
186 | std::string methodID,
|
---|
187 | std::vector<std::string> args);
|
---|
188 |
|
---|
189 | /* Returns the class ID */
|
---|
190 | JavaResultData* findClass(int plugin_instance_id,
|
---|
191 | std::string name);
|
---|
192 |
|
---|
193 | /* Returns the type class name */
|
---|
194 | JavaResultData* getClassName(std::string objectID);
|
---|
195 |
|
---|
196 | /* Returns the type class id */
|
---|
197 | JavaResultData* getClassID(std::string objectID);
|
---|
198 |
|
---|
199 | /* Returns the length of the array object. -1 if not found */
|
---|
200 | JavaResultData* getArrayLength(std::string objectID);
|
---|
201 |
|
---|
202 | /* Returns the item at the given index for the array */
|
---|
203 | JavaResultData* getSlot(std::string objectID, std::string index);
|
---|
204 |
|
---|
205 | /* Sets the item at the given index to the given value */
|
---|
206 | JavaResultData* setSlot(std::string objectID,
|
---|
207 | std::string index,
|
---|
208 | std::string value_id);
|
---|
209 |
|
---|
210 | /* Creates a new array of given length */
|
---|
211 | JavaResultData* newArray(std::string component_class,
|
---|
212 | std::string length);
|
---|
213 |
|
---|
214 | /* Creates a new string in the Java store */
|
---|
215 | JavaResultData* newString(std::string str);
|
---|
216 |
|
---|
217 | /* Check if package exists */
|
---|
218 | JavaResultData* hasPackage(int plugin_instance_id,
|
---|
219 | std::string package_name);
|
---|
220 |
|
---|
221 | /* Check if method exists */
|
---|
222 | JavaResultData* hasMethod(std::string classID, std::string method_name);
|
---|
223 |
|
---|
224 | /* Check if field exists */
|
---|
225 | JavaResultData* hasField(std::string classID, std::string method_name);
|
---|
226 |
|
---|
227 | /* Check if given object is instance of given class */
|
---|
228 | JavaResultData* isInstanceOf(std::string objectID, std::string classID);
|
---|
229 |
|
---|
230 | /* Returns the instance ID of the java applet */
|
---|
231 | JavaResultData* getAppletObjectInstance(std::string instanceID);
|
---|
232 | };
|
---|
233 |
|
---|
234 | #endif /* ICEDTEAJAVAREQUESTPROCESSOR_H_ */
|
---|