RPC.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6733 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 09:32:32 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS Core - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 // -------------------- mview
00056 #include "Core.hh"
00057 #include <OpenFlipper/common/Types.hh>
00058 
00059 //== IMPLEMENTATION ==========================================================
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   //Find plugin
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   //Find plugin
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   //execute the expression
00148   bool ok;
00149 
00150   slotCall("var tmpValue=" + _expression + ";", ok);
00151 
00152   if (!ok){
00153     _result = QVariant();
00154     return;
00155   }
00156 
00157   //get the return value
00158   QScriptValue val = scriptEngine_.globalObject().property("tmpValue");
00159 
00160 //   std::cerr << "Type:" << val.toVariant().userType() << std::endl; 
00161 //   std::cerr << "Value:" << val.toVariant().toString().toStdString()<< std::endl;
00162 
00163   _result = val.toVariant();
00164 }
00165 
00166 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .