Developer Documentation
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 
51 #pragma once
52 
53 #include <QtScript>
54 #include <vector>
56 
57 
62 namespace RPC {
63 
64 
65 //===========================================================================
71 //===========================================================================
72 
77 QScriptEngine* getScriptEngine();
78 
79 
85 void setScriptEngine( QScriptEngine* _engine );
86 
90 //===========================================================================
95 //===========================================================================
96 
102 DLLEXPORT
103 QScriptValue callFunction( QString _plugin, QString _functionName );
104 
113 DLLEXPORT
114 QScriptValue callFunction( QString _plugin, QString _functionName , std::vector< QScriptValue > _parameters );
115 
118 //===========================================================================
123 //===========================================================================
124 
131 template <typename T0>
132 void callFunction( QString _plugin, QString _functionName, T0 _t0) {
133  QScriptEngine* engine = getScriptEngine();
134  std::vector< QScriptValue > parameters;
135 // QVariant bla = qVariantFromValue(_t0);
136 //
137 // IdList list = qVariantValue<IdList>( bla ) ;
138 // std::cerr << "iDList size:" << list.size() << std::endl;;
139 // std::cerr << list[0] << std::endl;
140 // std::cerr << list[1] << std::endl;
141 // std::cerr << "Type id is : " << QMetaType::type("IdList") << std::endl;
142 // engine->globalObject().setProperty("ParameterData22",engine->toScriptValue(list));
143 /*
144  QVariant blubb = engine->globalObject().property("ParameterData22").toVariant();
145  IdList list1 = qVariantValue<IdList>( blubb ) ;
146  std::cerr << "iDList1 size:" << list1.size() << std::endl;;
147  std::cerr << list1[0] << std::endl;
148  std::cerr << list1[1] << std::endl;
149  std::cerr << "Type id is : " << QMetaType::type("IdList") << std::endl;*/
150 
151 
152  parameters.push_back( engine->toScriptValue(_t0) );
153  callFunction(_plugin,_functionName,parameters);
154 }
155 
163 template <typename T0, typename T1>
164 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1) {
165  QScriptEngine* engine = getScriptEngine();
166  std::vector< QScriptValue > parameters;
167  parameters.push_back( engine->toScriptValue( _t0 ) );
168  parameters.push_back( engine->toScriptValue( _t1 ) );
169  callFunction(_plugin,_functionName,parameters);
170 }
171 
180 template <typename T0, typename T1 , typename T2>
181 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 ) {
182  QScriptEngine* engine = getScriptEngine();
183  std::vector< QScriptValue > parameters;
184  parameters.push_back( engine->toScriptValue(_t0 ) );
185  parameters.push_back( engine->toScriptValue( _t1 ) );
186  parameters.push_back( engine->toScriptValue( _t2 ) );
187  callFunction(_plugin,_functionName,parameters);
188 }
189 
199 template <typename T0, typename T1 , typename T2, typename T3>
200 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 ) {
201  QScriptEngine* engine = getScriptEngine();
202  std::vector< QScriptValue > parameters;
203  parameters.push_back( engine->toScriptValue( _t0 ) );
204  parameters.push_back( engine->toScriptValue( _t1 ) );
205  parameters.push_back( engine->toScriptValue( _t2 ) );
206  parameters.push_back( engine->toScriptValue( _t3 ) );
207  callFunction(_plugin,_functionName,parameters);
208 }
209 
220 template <typename T0, typename T1 , typename T2, typename T3, typename T4>
221 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 , T4 _t4) {
222  QScriptEngine* engine = getScriptEngine();
223  std::vector< QScriptValue > parameters;
224  parameters.push_back( engine->toScriptValue( _t0 ) );
225  parameters.push_back( engine->toScriptValue( _t1 ) );
226  parameters.push_back( engine->toScriptValue( _t2 ) );
227  parameters.push_back( engine->toScriptValue( _t3 ) );
228  parameters.push_back( engine->toScriptValue( _t4 ) );
229  callFunction(_plugin,_functionName,parameters);
230 }
231 
243 template <typename T0, typename T1 , typename T2, typename T3, typename T4, typename T5>
244 void callFunction( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 , T4 _t4, T5 _t5) {
245  QScriptEngine* engine = getScriptEngine();
246  std::vector< QScriptValue > parameters;
247  parameters.push_back( engine->toScriptValue( _t0 ) );
248  parameters.push_back( engine->toScriptValue( _t1 ) );
249  parameters.push_back( engine->toScriptValue( _t2 ) );
250  parameters.push_back( engine->toScriptValue( _t3 ) );
251  parameters.push_back( engine->toScriptValue( _t4 ) );
252  parameters.push_back( engine->toScriptValue( _t5 ) );
253  callFunction(_plugin,_functionName,parameters);
254 }
255 
258 //===========================================================================
264 //===========================================================================
265 
272 template <typename ReturnValue >
273 ReturnValue callFunctionValue( QString _plugin, QString _functionName) {
274  return qscriptvalue_cast< ReturnValue >( callFunction(_plugin,_functionName) );
275 }
276 
284 template <typename ReturnValue , typename T0>
285 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0) {
286  QScriptEngine* engine = getScriptEngine();
287  std::vector< QScriptValue > parameters;
288  parameters.push_back( engine->toScriptValue( _t0 ) );
289  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
290 }
291 
300 template <typename ReturnValue , typename T0, typename T1>
301 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1) {
302  QScriptEngine* engine = getScriptEngine();
303  std::vector< QScriptValue > parameters;
304  parameters.push_back( engine->toScriptValue( _t0 ) );
305  parameters.push_back( engine->toScriptValue( _t1 ) );
306  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
307 }
308 
318 template <typename ReturnValue , typename T0, typename T1 , typename T2 >
319 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 ) {
320  QScriptEngine* engine = getScriptEngine();
321  std::vector< QScriptValue > parameters;
322  parameters.push_back( engine->toScriptValue( _t0 ) );
323  parameters.push_back( engine->toScriptValue( _t1 ) );
324  parameters.push_back( engine->toScriptValue( _t2 ) );
325  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
326 }
327 
338 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3>
339 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3 ) {
340  QScriptEngine* engine = getScriptEngine();
341  std::vector< QScriptValue > parameters;
342  parameters.push_back( engine->toScriptValue( _t0 ) );
343  parameters.push_back( engine->toScriptValue( _t1 ) );
344  parameters.push_back( engine->toScriptValue( _t2 ) );
345  parameters.push_back( engine->toScriptValue( _t3 ) );
346  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
347 }
348 
360 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3, typename T4>
361 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3, T4 _t4 ) {
362  QScriptEngine* engine = getScriptEngine();
363  std::vector< QScriptValue > parameters;
364  parameters.push_back( engine->toScriptValue( _t0 ) );
365  parameters.push_back( engine->toScriptValue( _t1 ) );
366  parameters.push_back( engine->toScriptValue( _t2 ) );
367  parameters.push_back( engine->toScriptValue( _t3 ) );
368  parameters.push_back( engine->toScriptValue( _t4 ) );
369  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
370 }
371 
384 template <typename ReturnValue , typename T0, typename T1 , typename T2, typename T3, typename T4, typename T5>
385 ReturnValue callFunctionValue( QString _plugin, QString _functionName, T0 _t0 , T1 _t1 , T2 _t2 , T3 _t3, T4 _t4 , T5 _t5 ) {
386  QScriptEngine* engine = getScriptEngine();
387  std::vector< QScriptValue > parameters;
388  parameters.push_back( engine->toScriptValue( _t0 ) );
389  parameters.push_back( engine->toScriptValue( _t1 ) );
390  parameters.push_back( engine->toScriptValue( _t2 ) );
391  parameters.push_back( engine->toScriptValue( _t3 ) );
392  parameters.push_back( engine->toScriptValue( _t4 ) );
393  parameters.push_back( engine->toScriptValue( _t5 ) );
394  return qscriptvalue_cast<ReturnValue>( callFunction(_plugin,_functionName,parameters) );
395 }
396 
400 }
401 
#define DLLEXPORT
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
Definition: RPCWrappers.cc:55
void setScriptEngine(QScriptEngine *_engine)
DONT USE! (Function to set the internal reference to the script Engine)
Definition: RPCWrappers.cc:104
QScriptEngine * getScriptEngine()
get a pointer to OpenFlippers core scripting engine
Definition: RPCWrappers.cc:108
ReturnValue callFunctionValue(QString _plugin, QString _functionName)
call a function in another plugin and get a return parameter
Definition: RPCWrappers.hh:273