Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RPCWrappers.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
58 #ifndef RPCWRAPPERS_HH
59 #define RPCWRAPPERS_HH
60
61 #include <QtScript>
62 #include <vector>
63 #include <OpenFlipper/common/Types.hh>
64
65
70 namespace RPC {
71
72
73 //===========================================================================
79 //===========================================================================
80
84 DLLEXPORT
85 QScriptEngine* getScriptEngine();
86
87
92 DLLEXPORT
93 void setScriptEngine( QScriptEngine* _engine );
94
98 //===========================================================================
103 //===========================================================================
104
110 DLLEXPORT
111 QScriptValue callFunction( QString _plugin, QString _functionName );
112
121 DLLEXPORT
122 QScriptValue callFunction( QString _plugin, QString _functionName , std::vector< QScriptValue > _parameters );
123
126 //===========================================================================
131 //===========================================================================
132
139 template <typename T0>
140 void callFunction( QString _plugin, QString _functionName, T0 _t0) {
141 QScriptEngine* engine = getScriptEngine();
142 std::vector< QScriptValue > parameters;
143 // QVariant bla = qVariantFromValue(_t0);
144 //
145 // IdList list = qVariantValue<IdList>( bla ) ;
146 // std::cerr << "iDList size:" << list.size() << std::endl;;
147 // std::cerr << list[0] << std::endl;
148 // std::cerr << list[1] << std::endl;
149 // std::cerr << "Type id is : " << QMetaType::type("IdList") << std::endl;
150 // engine->globalObject().setProperty("ParameterData22",engine->toScriptValue(list));
151 /*
152 QVariant blubb = engine->globalObject().property("ParameterData22").toVariant();
153 IdList list1 = qVariantValue<IdList>( blubb ) ;
154 std::cerr << "iDList1 size:" << list1.size() << std::endl;;
155 std::cerr << list1[0] << std::endl;
156 std::cerr << list1[1] << std::endl;
157 std::cerr << "Type id is : " << QMetaType::type("IdList") << std::endl;*/
158
159
160 parameters.push_back( engine->toScriptValue(_t0) );
161 callFunction(_plugin,_functionName,parameters);
162 }
163
171 template <typename T0, typename T1>
172 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1) {
173 QScriptEngine* engine = getScriptEngine();
174 std::vector< QScriptValue > parameters;
175 parameters.push_back( engine->toScriptValue( _t0 ) );
176 parameters.push_back( engine->toScriptValue( _t1 ) );
177 callFunction(_plugin,_functionName,parameters);
178 }
179
188 template <typename T0, typename T1 , typename T2>
189 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 ) {
190 QScriptEngine* engine = getScriptEngine();
191 std::vector< QScriptValue > parameters;
192 parameters.push_back( engine->toScriptValue(_t0 ) );
193 parameters.push_back( engine->toScriptValue( _t1 ) );
194 parameters.push_back( engine->toScriptValue( _t2 ) );
195 callFunction(_plugin,_functionName,parameters);
196 }
197
207 template <typename T0, typename T1 , typename T2, typename T3>
208 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 ) {
209 QScriptEngine* engine = getScriptEngine();
210 std::vector< QScriptValue > parameters;
211 parameters.push_back( engine->toScriptValue( _t0 ) );
212 parameters.push_back( engine->toScriptValue( _t1 ) );
213 parameters.push_back( engine->toScriptValue( _t2 ) );
214 parameters.push_back( engine->toScriptValue( _t3 ) );
215 callFunction(_plugin,_functionName,parameters);
216 }
217
228 template <typename T0, typename T1 , typename T2, typename T3, typename T4>
229 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 , T4 _t4) {
230 QScriptEngine* engine = getScriptEngine();
231 std::vector< QScriptValue > parameters;
232 parameters.push_back( engine->toScriptValue( _t0 ) );
233 parameters.push_back( engine->toScriptValue( _t1 ) );
234 parameters.push_back( engine->toScriptValue( _t2 ) );
235 parameters.push_back( engine->toScriptValue( _t3 ) );
236 parameters.push_back( engine->toScriptValue( _t4 ) );
237 callFunction(_plugin,_functionName,parameters);
238 }
239
251 template <typename T0, typename T1 , typename T2, typename T3, typename T4, typename T5>
252 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 , T4 _t4, T5 _t5) {
253 QScriptEngine* engine = getScriptEngine();
254 std::vector< QScriptValue > parameters;
255 parameters.push_back( engine->toScriptValue( _t0 ) );
256 parameters.push_back( engine->toScriptValue( _t1 ) );
257 parameters.push_back( engine->toScriptValue( _t2 ) );
258 parameters.push_back( engine->toScriptValue( _t3 ) );
259 parameters.push_back( engine->toScriptValue( _t4 ) );
260 parameters.push_back( engine->toScriptValue( _t5 ) );
261 callFunction(_plugin,_functionName,parameters);
262 }
263
266 //===========================================================================
272 //===========================================================================
273
280 template <typename ReturnValue >
281 ReturnValue callFunctionValue( QString _plugin, QString _functionName) {
282 return qscriptvalue_cast< ReturnValue >( callFunction(_plugin,_functionName) );
283 }
284
292 template <typename ReturnValue , typename T0>
293 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0) {
294 QScriptEngine* engine = getScriptEngine();
295 std::vector< QScriptValue > parameters;
296 parameters.push_back( engine->toScriptValue( _t0 ) );
297 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
298 }
299
308 template <typename ReturnValue , typename T0, typename T1>
309 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1) {
310 QScriptEngine* engine = getScriptEngine();
311 std::vector< QScriptValue > parameters;
312 parameters.push_back( engine->toScriptValue( _t0 ) );
313 parameters.push_back( engine->toScriptValue( _t1 ) );
314 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
315 }
316
326 template <typename ReturnValue , typename T0, typename T1 , typename T2 >
327 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 ) {
328 QScriptEngine* engine = getScriptEngine();
329 std::vector< QScriptValue > parameters;
330 parameters.push_back( engine->toScriptValue( _t0 ) );
331 parameters.push_back( engine->toScriptValue( _t1 ) );
332 parameters.push_back( engine->toScriptValue( _t2 ) );
333 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
334 }
335
346 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3>
347 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 ) {
348 QScriptEngine* engine = getScriptEngine();
349 std::vector< QScriptValue > parameters;
350 parameters.push_back( engine->toScriptValue( _t0 ) );
351 parameters.push_back( engine->toScriptValue( _t1 ) );
352 parameters.push_back( engine->toScriptValue( _t2 ) );
353 parameters.push_back( engine->toScriptValue( _t3 ) );
354 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
355 }
356
368 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3, typename T4>
369 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3, T4 _t4 ) {
370 QScriptEngine* engine = getScriptEngine();
371 std::vector< QScriptValue > parameters;
372 parameters.push_back( engine->toScriptValue( _t0 ) );
373 parameters.push_back( engine->toScriptValue( _t1 ) );
374 parameters.push_back( engine->toScriptValue( _t2 ) );
375 parameters.push_back( engine->toScriptValue( _t3 ) );
376 parameters.push_back( engine->toScriptValue( _t4 ) );
377 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
378 }
379
392 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3, typename T4, typename T5>
393 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3, T4 _t4 , T5 _t5 ) {
394 QScriptEngine* engine = getScriptEngine();
395 std::vector< QScriptValue > parameters;
396 parameters.push_back( engine->toScriptValue( _t0 ) );
397 parameters.push_back( engine->toScriptValue( _t1 ) );
398 parameters.push_back( engine->toScriptValue( _t2 ) );
399 parameters.push_back( engine->toScriptValue( _t3 ) );
400 parameters.push_back( engine->toScriptValue( _t4 ) );
401 parameters.push_back( engine->toScriptValue( _t5 ) );
402 return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
403 }
404
408 }
409
410 #endif // RPCWRAPPERS_HH
RPC::setScriptEngine
void setScriptEngine(QScriptEngine *_engine)
DONT USE! (Function to set the internal reference to the script Engine)
Definition: RPCWrappers.cc:112
RPC
Definition: RPCWrappers.cc:56
RPC::callFunctionValue
ReturnValue callFunctionValue(QString _plugin, QString _functionName)
call a function in another plugin and get a return parameter
Definition: RPCWrappers.hh:281
RPC::callFunction
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
Definition: RPCWrappers.cc:63
DLLEXPORT
#define DLLEXPORT
Definition: GlobalDefines.hh:107
RPC::getScriptEngine
QScriptEngine * getScriptEngine()
get a pointer to OpenFlippers core scripting engine
Definition: RPCWrappers.cc:116
Types.hh