Developer Documentation
RPC.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
43
44
45
46
47//=============================================================================
48//
49// CLASS Core - IMPLEMENTATION
50//
51//=============================================================================
52
53
54//== INCLUDES =================================================================
55
56// -------------------- mview
57#include "Core.hh"
58
59//== IMPLEMENTATION ==========================================================
60
61
62
63void Core::slotPluginExists( const QString& _pluginName , bool& _exists ) {
64
65 for ( int i = 0 ; i < (int)plugins().size(); ++i ) {
66 if ( plugins()[i].rpcName == _pluginName ) {
67 _exists = true;
68 return;
69 }
70 }
71
72 _exists = false;
73}
74
75void Core::slotFunctionExists( const QString& _pluginName , const QString& _functionName , bool& _exists ) {
76
77 //Find plugin
78 int plugin = -1;
79 for ( int i = 0 ; i < (int)plugins().size(); ++i ) {
80 if ( plugins()[i].rpcName == _pluginName ) {
81 plugin = i;
82 break;
83 }
84 }
85
86 if ( plugin == -1 ) {
87 _exists = false;
88 return;
89 }
90
91 _exists = plugins()[plugin].rpcFunctions.contains(_functionName);
92}
93
94#if QT_VERSION_MAJOR < 6
95void Core::slotCall( const QString& _pluginName , const QString& _functionName , bool& _success ) {
96
97 //Find plugin
98 int plugin = -1;
99 for ( int i = 0 ; i < (int)plugins().size(); ++i ) {
100 if ( plugins()[i].rpcName == _pluginName ) {
101 plugin = i;
102 break;
103 }
104 }
105
106 if ( plugin == -1 ) {
107 _success = false;
108 emit log(LOGERR, tr("Unable to call function from Plugin : ") + _pluginName + tr(" ( Plugin not Found! )"));
109 return;
110 }
111
112 if ( !plugins()[plugin].rpcFunctions.contains(_functionName) ) {
113 _success = false;
114 emit log(LOGERR, tr("Unable to call function from Plugin : ") + _pluginName);
115 emit log(LOGERR, tr("Function ") + _functionName + tr(" not found!"));
116 return;
117 }
118
119 scriptEngine_.evaluate(_pluginName + "." + _functionName );
120 if ( scriptEngine_.hasUncaughtException() ) {
121 _success = false;
122 QScriptValue result = scriptEngine_.uncaughtException();
123 QString exception = result.toString();
124 emit log( LOGERR , tr("RPC failed with : ") + exception );
125 return;
126 }
127
128 _success = true;
129
130}
131
132void Core::slotCall( const QString& _expression , bool& _success ) {
133
134 scriptEngine_.evaluate( _expression );
135 if ( scriptEngine_.hasUncaughtException() ) {
136 _success = false;
137 QScriptValue result = scriptEngine_.uncaughtException();
138 QString exception = result.toString();
139 emit log( LOGERR , tr("RPC failed with : ") + exception );
140 return;
141 }
142
143 _success = true;
144
145}
146#endif
147
148
149
150//=============================================================================
@ LOGERR
void slotCall(const QString &_pluginName, const QString &_functionName, bool &_success)
Definition: RPC.cc:95
void slotFunctionExists(const QString &_pluginName, const QString &_functionName, bool &_exists)
Check if a function exists.
Definition: RPC.cc:75
std::vector< PluginInfo > & plugins()
Index of Plugins toolbox widget.
Definition: Core.cc:770
QScriptEngine scriptEngine_
Core scripting engine.
Definition: Core.hh:1344
void slotPluginExists(const QString &_pluginName, bool &_exists)
Check if a plugin exists.
Definition: RPC.cc:63
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.