Developer Documentation
Loading...
Searching...
No Matches
RPCWrappers.cc
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
45//#include "RPCWrappersHelper.hh"
46
47#include <QMetaType>
48
49#include <QApplication>
50
51namespace RPC {
52
53
54void callFunctionQVariant( const QString& _plugin, const QString& _functionName , const std::vector< QVariant >& _parameters , QGenericReturnArgument _returnArg) {
55
56 if (_plugin.toLower() == "core" ) {
57 std::cerr << "callFunctionReturnQVariant : Core not supported! Use Pluginfunctions to trigger core functionality!!!" << std::endl;
58 return;
59 }
60
61 std::cerr << "Calling function: " << _plugin.toStdString() << " " << _functionName.toStdString() << std::endl;
62
63 // @TODO, Check the correct thread affinity for the new style function calls
64 // If we get into trouble here, check the old RPCWrappersHelper.
65
66 // RPCHelper h;
67
68 // Qt::ConnectionType connection = Qt::DirectConnection;
69 // if (h.thread() != QApplication::instance()->thread())
70 // {
71 // h.moveToThread(QApplication::instance()->thread());
72 // connection = Qt::BlockingQueuedConnection;
73 // }
74
75 // QScriptValue retVal;
76 // if (!QMetaType::type("std::vector<QScriptValue>"))
77 // qRegisterMetaType< std::vector< QScriptValue > >("ScriptParameters");
78
79 //call _functionName in main thread. blocks, if our function runs in another thread
80
81
82 // Get a list of all the plugins
83 const std::vector<PluginInfo>& plugins = PluginStorage::plugins();
84
85 QObject* plugin = nullptr;
86
87 for ( auto current : plugins ) {
88 if (current.rpcName == _plugin) {
89 plugin = current.plugin;
90 break;
91 }
92 }
93
94 if ( plugin == nullptr ) {
95 std::cerr << "Unable to find plugin " << _plugin.toStdString() << " in callFunctionQVariant"<< std::endl;
96 return;
97 }
98
99
100 QGenericArgument arguments[10];
101
102 // Unpack the arguments from the vector
103 for ( size_t i = 0 ; i < _parameters.size() ; ++i ) {
104 arguments[i] = QGenericArgument(_parameters[i].typeName(),_parameters[i].data());
105 }
106
107 // Add empty arguments for the rest
108 for (size_t i = _parameters.size() ; i < 10; ++i ) {
109 arguments[i] = QGenericArgument();
110 }
111
112
113
114 QMetaObject::invokeMethod(plugin, _functionName.toStdString().c_str(), Qt::DirectConnection, _returnArg,
115 arguments[0],
116 arguments[1],
117 arguments[2],
118 arguments[3],
119 arguments[4],
120 arguments[5],
121 arguments[6],
122 arguments[7],
123 arguments[8],
124 arguments[9]
125 );
126
127}
128
129void callFunction( QString _plugin, QString _functionName) {
130 QGenericReturnArgument unused;
131 std::vector<QVariant> parameters;
132 callFunctionQVariant(_plugin,_functionName,parameters);
133}
134
135}
136
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition Types.cc:154
void callFunction(QString _plugin, QString _functionName)
call a function in another plugin
void callFunctionQVariant(const QString &_plugin, const QString &_functionName, const std::vector< QVariant > &_parameters, QGenericReturnArgument _returnArg)
Call a function provided by a plugin getting multiple parameters as a vector of qvariants.