RPCInterface.hh 6.97 KB
 Jan Möbius committed Aug 05, 2009 1 /*===========================================================================*\  Jan Möbius committed Nov 25, 2010 2 3 * * * OpenFlipper *  Martin Schultz committed Jul 16, 2015 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  * Copyright (c) 2001-2015, RWTH-Aachen University * * Department of Computer Graphics and Multimedia * * All rights reserved. * * www.openflipper.org * * * *---------------------------------------------------------------------------* * This file is part of OpenFlipper. * *---------------------------------------------------------------------------* * * * Redistribution and use in source and binary forms, with or without * * modification, are permitted provided that the following conditions * * are met: * * * * 1. Redistributions of source code must retain the above copyright notice, * * this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. Neither the name of the copyright holder nor the names of its * * contributors may be used to endorse or promote products derived from * * this software without specific prior written permission. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER * * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  Jan Möbius committed Nov 25, 2010 39 * *  Jan Möbius committed Aug 05, 2009 40 41 \*===========================================================================*/  Jan Möbius committed Jan 08, 2019 42 #pragma once  Jan Möbius committed Aug 29, 2008 43   Jan Möbius committed Feb 25, 2009 44 45 #include  Jan Möbius committed Mar 01, 2011 46 /** \file RPCInterface.hh  Jan Möbius committed Mar 01, 2011 47 48 49 50 51 52 53 54 55 56 57 * * Interface for calling functions across plugins. \ref RPCInterfacePage */ /** \brief Interface to call functions across plugins. * * \ref RPCInterfacePage "Detailed description" * \n * \n * * Interface for all Plugins which do remote procedure calls ( and cross plugin calls).\n  Jan Möbius committed Feb 25, 2009 58 59  * The functions provided in the interface are only used to verify that certain plugins or * functions are available. The actual calls are in the RPCWrappers.hh file.  Jan Möbius committed Aug 29, 2008 60 61 62 */ class RPCInterface {  Mike Kremer committed Feb 10, 2009 63  public:  Jan Möbius committed Feb 25, 2009 64   Mike Kremer committed Feb 10, 2009 65 66 67 68  /// Destructor virtual ~RPCInterface() {}; signals :  Jan Möbius committed Aug 29, 2008 69 70  /** Check if the plugin exists in the current Environment \n  Jan Möbius committed Mar 01, 2011 71  *  Jan Möbius committed Aug 29, 2008 72 73 74  * @param _pluginName Name of the Plugin (has to be the clean version .. no Spaces etc) * @param _exists found or not */  Jan Möbius committed Mar 15, 2011 75  virtual void pluginExists( QString _pluginName , bool& _exists ) {};  Jan Möbius committed Aug 29, 2008 76 77 78 79 80 81 82  /** Check if a plugin exists and provides the given function \n * @param _pluginName Name of the Plugin (has to be the clean version .. no Spaces etc) * @param _functionName requested function * @param _exists found or not */  Jan Möbius committed Mar 15, 2011 83  virtual void functionExists( QString _pluginName , QString _functionName , bool& _exists ) {};  Jan Möbius committed Aug 29, 2008 84 85 86  };  Jan Möbius committed Mar 01, 2011 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 /** \page RPCInterfacePage RPC Interface \image html RPCInterface.png \n The RPCInterface can be used by plugins to call functions from other OpenFlipper plugins. The calls are internally transformed into scripting calls and passed to the other plugins. You can directly connect signals and slots via the \ref pluginConnectionInterfacePage . The interface itself contains two basic functions which can be used to check if another plugin exists (RPCInterface::pluginExists()) or if a specific function exists in another plugin (RPCInterface::functionExists()). Both functions get the clean name of the plugin to check. To get that name, just open the script editor in OpenFlipper which lists all plugins and their available functions. Example Code for plugins: \code bool isPluginAvailable; emit pluginExists ("scripting", isPluginAvailable); \endcode Example Code for functions: \code bool isFunctionAvailable; emit functionExists ("scripting", "showScriptInEditor(QString)", isFunctionAvailable); \endcode In addition to these basic functions there is a set of template functions in RPCWrappers.hh which can be used to directly call a function from another plugin via the scripting system. This requires the parameters to be registered to the QT MetaObject system which is already done for the most common types of variables. For calling a function you can use RPC::callFunction() or RPC::callFunctionValue() if the called function returns a value. These functions get the pluginName and the function name and call the requested function via scripting. It is possible to supply additional parameters to these functions that will be passed to the called function. Example code: \code // call without getting return value RPC::callFunction ("pluginName", "FunctionName"); // call without getting return value and suplying a parameter int parameter1 RPC::callFunction ("pluginName", "FunctionName", parameter1); // call with getting return value which is defined as the template parameter QString parameter2 bool value = RPC::callFunctionValue ("pluginName", "FunctionName", parameter1, parameter2); \endcode To use the RPCInterface:
 Matthias Möller committed Jul 10, 2015 145 146 \note Multithreading: You can call any script function from any thread, but the script will be executed on the main thread.  Jan Möbius committed Mar 01, 2011 147 148 149 */  Jan Möbius committed Aug 29, 2008 150 151 Q_DECLARE_INTERFACE(RPCInterface,"OpenFlipper.RPCInterface/1.0")