RPC.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include "Core.hh"
00057 #include <OpenFlipper/common/Types.hh>
00058
00059
00060
00061
00062
00063 void Core::slotPluginExists( QString _pluginName , bool& _exists ) {
00064
00065 for ( int i = 0 ; i < (int)plugins.size(); ++i ) {
00066 if ( plugins[i].rpcName == _pluginName ) {
00067 _exists = true;
00068 return;
00069 }
00070 }
00071
00072 _exists = false;
00073 }
00074
00075 void Core::slotFunctionExists( QString _pluginName , QString _functionName , bool& _exists ) {
00076
00077
00078 int plugin = -1;
00079 for ( int i = 0 ; i < (int)plugins.size(); ++i ) {
00080 if ( plugins[i].rpcName == _pluginName ) {
00081 plugin = i;
00082 break;
00083 }
00084 }
00085
00086 if ( plugin == -1 ) {
00087 _exists = false;
00088 return;
00089 }
00090
00091 _exists = plugins[plugin].rpcFunctions.contains(_functionName);
00092 }
00093
00094 void Core::slotCall( QString _pluginName , QString _functionName , bool& _success ) {
00095
00096
00097 int plugin = -1;
00098 for ( int i = 0 ; i < (int)plugins.size(); ++i ) {
00099 if ( plugins[i].rpcName == _pluginName ) {
00100 plugin = i;
00101 break;
00102 }
00103 }
00104
00105 if ( plugin == -1 ) {
00106 _success = false;
00107 emit log(LOGERR, tr("Unable to call function from Plugin : ") + _pluginName + tr(" ( Plugin not Found! )"));
00108 return;
00109 }
00110
00111 if ( !plugins[plugin].rpcFunctions.contains(_functionName) ) {
00112 _success = false;
00113 emit log(LOGERR, tr("Unable to call function from Plugin : ") + _pluginName);
00114 emit log(LOGERR, tr("Function ") + _functionName + tr(" not found!"));
00115 return;
00116 }
00117
00118 scriptEngine_.evaluate(_pluginName + "." + _functionName );
00119 if ( scriptEngine_.hasUncaughtException() ) {
00120 _success = false;
00121 QScriptValue result = scriptEngine_.uncaughtException();
00122 QString exception = result.toString();
00123 emit log( LOGERR , tr("RPC failed with : ") + exception );
00124 return;
00125 }
00126
00127 _success = true;
00128
00129 }
00130
00131 void Core::slotCall( QString _expression , bool& _success ) {
00132
00133 scriptEngine_.evaluate( _expression );
00134 if ( scriptEngine_.hasUncaughtException() ) {
00135 _success = false;
00136 QScriptValue result = scriptEngine_.uncaughtException();
00137 QString exception = result.toString();
00138 emit log( LOGERR , tr("RPC failed with : ") + exception );
00139 return;
00140 }
00141
00142 _success = true;
00143
00144 }
00145
00146 void Core::slotGetValue(QString _expression, QVariant& _result ){
00147
00148 bool ok;
00149
00150 slotCall("var tmpValue=" + _expression + ";", ok);
00151
00152 if (!ok){
00153 _result = QVariant();
00154 return;
00155 }
00156
00157
00158 QScriptValue val = scriptEngine_.globalObject().property("tmpValue");
00159
00160
00161
00162
00163 _result = val.toVariant();
00164 }
00165
00166