diff --git a/CMakeLists.txt b/CMakeLists.txt index 76963686a73b9f68b93ecdc177b2fa0f6b4f3f5d..5ad84af5eecfb71327f9a7f50e14c86b2af58e43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,6 @@ SEARCH_FOR_PTHREAD() ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(include) -ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(doc) ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(share) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 349c0402b7f9f7634f2ca87da234f1c4d7e06b04..fa6ec6ddb81a4a7f3815fa91b4739cee03775975 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -40,20 +40,13 @@ dynamic-graph-api.h entity.h factory.h -interpreter.h -interpreter-helper.h -plugin-loader.h pool.h -import.h exception-abstract.h exception-factory.h exception-signal.h exception-traces.h -functions.h -shell-procedure.h - signal.h signal-array.h signal-base.h diff --git a/include/dynamic-graph/functions.h b/include/dynamic-graph/functions.h deleted file mode 100644 index 40fc4079efc87711de7d660003ccfc7c97124597..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/functions.h +++ /dev/null @@ -1,61 +0,0 @@ -// -*- mode: c++ -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef DYNAMIC_GRAPH_FUNCTIONS_H -# define DYNAMIC_GRAPH_FUNCTIONS_H -# include <iosfwd> -# include <string> - -# include <dynamic-graph/fwd.hh> -# include <dynamic-graph/dynamic-graph-api.h> - -# define STATIC_SHELL_FUNCTION(name) \ - static void name (const std::string cmd, \ - std::istringstream& args, \ - std::ostream& os) - -/*! @ingroup dgraph - \brief This plugin implements a bunch of useful shell commands. - - These include debug commands such as timing and exception catching, - and user interaction commands such as display and beep commands. - For more information, load the plugin and type help on a sot shell. - */ -struct DYNAMIC_GRAPH_DLLAPI ShellFunctions -{ - STATIC_SHELL_FUNCTION (cmdLoadPlugins); - STATIC_SHELL_FUNCTION (cmdTry); - STATIC_SHELL_FUNCTION (cmdDisplayPlugins); - STATIC_SHELL_FUNCTION (cmdDisplayFactory); - STATIC_SHELL_FUNCTION (cmdCommentary); - STATIC_SHELL_FUNCTION (cmdUnplug); - STATIC_SHELL_FUNCTION (cmdClearPlugin); - STATIC_SHELL_FUNCTION (cmdSignalTime); - STATIC_SHELL_FUNCTION (cmdSynchroSignal); - STATIC_SHELL_FUNCTION (cmdEcho); - STATIC_SHELL_FUNCTION (cmdCopy); - STATIC_SHELL_FUNCTION (cmdFreeze); - STATIC_SHELL_FUNCTION (cmdSqueeze); - STATIC_SHELL_FUNCTION (cmdEnableTrace); - STATIC_SHELL_FUNCTION (cmdSetPrompt); - STATIC_SHELL_FUNCTION (cmdSleep); - STATIC_SHELL_FUNCTION (cmdBeep); - STATIC_SHELL_FUNCTION (cmdFlagSet); - STATIC_SHELL_FUNCTION (cmdCompletionList); -}; - -#endif //! DYNAMIC_GRAPH_FUNCTIONS_H diff --git a/include/dynamic-graph/import.h b/include/dynamic-graph/import.h deleted file mode 100644 index 56265c16030e86743ec8f97c3904ba9f8527ad0e..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/import.h +++ /dev/null @@ -1,69 +0,0 @@ -// -*- c++-mode -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef SOT_FACTORY_COMMAND_IMPORT_H -# define SOT_FACTORY_COMMAND_IMPORT_H -# include <iosfwd> -# include <string> -# include <vector> - -# include <boost/filesystem/path.hpp> - -# include <dynamic-graph/fwd.hh> - -namespace dynamicgraph -{ - namespace command - { - namespace - { - /// \brief Vector of Boost.Filesystem paths. - /// - /// Used to store paths where the import statement - /// will look for scripts or plug-ins. - typedef std::vector<boost::filesystem::path> paths_t; - } // end of anonymous namespace. - - /// \brief Implement sot interpretor import command. - /// - /// The import command sources a file and searches automatically - /// for it in the importPaths. - void import (Interpreter& interpretor, - const std::string& cmdLine, - std::istringstream& cmdArg, - std::ostream& os); - - /// \brief Implement sot interpretor pushImportPaths command. - /// - /// Append a path to importPaths. - void pushImportPaths (Interpreter& interpretor, - const std::string& cmdLine, - std::istringstream& cmdArg, - std::ostream& os); - - /// \brief Implement sot interpretor popImportPaths command. - /// - /// Drop the last path of importPaths. - void popImportPaths (Interpreter& interpretor, - const std::string& cmdLine, - std::istringstream& cmdArg, - std::ostream& os); - - } // end of namespace command. -} // end of namespace sot. - -#endif //! SOT_FACTORY_COMMAND_IMPORT_H diff --git a/include/dynamic-graph/interpreter-helper.h b/include/dynamic-graph/interpreter-helper.h deleted file mode 100644 index 4b5a4122e3fcb4031a9a44a523e81805ab9c3651..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/interpreter-helper.h +++ /dev/null @@ -1,124 +0,0 @@ -// -*- mode: c++ -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef DYNAMIC_GRAPH_INTERPRETER_HELPER_H -# define DYNAMIC_GRAPH_INTERPRETER_HELPER_H -# include <iosfwd> -# include <string> - -# include <dynamic-graph/fwd.hh> -# include <dynamic-graph/plugin-loader.h> - -namespace dynamicgraph -{ - /*! @ingroup dgraph - \brief This class implements the first level interpretor - to control basic functionnalities of the plugins. - - It provides a shell allowing to : - \li load plugin libraries, - \li create instances of plugin, - \li destroy the plugins, - \li unload the libraries, - \li set a signal, - \li get a signal, - \li compute a signal, - */ - class DYNAMIC_GRAPH_DLLAPI InterpreterHelper - { - public: - InterpreterHelper () - {} - - /*! \name Implements the commands. - @{ - */ - /*! \brief Instanciate an object - Extracts the name and the class of the object, verifies it is unique, - and creates the instance if this is the case. - */ - void cmdNew (const std::string& className, - const std::string& objName, - std::ostream& os); - - /*! \brief Destroy the object. - Destroy the object objName. - */ - void cmdDestroy (const std::string& objName, - std::ostream& os); - - /*! \brief Connect two signals. - Connect the input signal obj1.signame1 to the output signal - obj2.signame2. - \param[in] obj1 The input object. - \param[in] obj2 The output object. - \param[in] signame1 The input object's signal name - \param[in] signame2 The output object's signal name - \param[out] os The output stream for logging and error output - */ - void cmdPlug (const std::string& obj1, const std::string & signame1, - const std::string& obj2, const std::string & signame2, - std::ostream& os); - - /*! \brief Load a dynamic library which includes a plugin. - Extracts the name first and the directory in second from cmdArg - to load the dynamic library. - */ - void cmdLoadPlugin (const std::string& directory, - const std::string& pluginName, - std::ostream& os); - - /*! \brief Unload a dynamic library which includes a plugin. - Extracts the name to unload the dynamic library. - */ - void cmdUnloadPlugin (const std::string& pluginName, - std::ostream& os); - - /*! \brief Set a signal [obj.signal] to a value [value] - with cmdArg = "[obj.signal] [value]" - */ - void cmdSetSignal (const std::string& objname, - const std::string& signame, - const std::string& cmdArg, - std::ostream& os); - - /*! \brief Display the value of the signal [obj.signal] - with cmdArg = "[obj.signal]" - */ - void cmdGetSignal (const std::string& objname, - const std::string& signame, - std::ostream& os); - - /*! \brief Compute the value of the signal [signame=obj.signal] at - time [time] with cmdArg = "[obj.signal] [time]" - */ - void cmdComputeSignal (const std::string& objname, - const std::string& signame, - const int &time, - std::ostream& os); - - protected: - /// \brief The plugin loader. - PluginLoader dlPtr; - }; - - -} // end of namespace dynamicgraph - - - -#endif //! DYNAMIC_GRAPH_INTERPRETER_HELPER_H diff --git a/include/dynamic-graph/interpreter.h b/include/dynamic-graph/interpreter.h deleted file mode 100644 index 95866c02d7f735dc959d2839cad0ec8473df847f..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/interpreter.h +++ /dev/null @@ -1,192 +0,0 @@ -// -*- mode: c++ -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef DYNAMIC_GRAPH_INTERPRETER_H -# define DYNAMIC_GRAPH_INTERPRETER_H -# include <string> -# include <map> -# include <sstream> - -# include <boost/function.hpp> -# include <boost/bind.hpp> - -# include <dynamic-graph/fwd.hh> -# include <dynamic-graph/signal-base.h> -# include <dynamic-graph/exception-factory.h> -# include <dynamic-graph/pool.h> -# include <dynamic-graph/dynamic-graph-api.h> - -# define SHELL_FUNCTION_REGISTERER(name, fun) \ - extern "C" { \ - ::dynamicgraph::ShellFunctionRegisterer \ - reg (name, boost::bind (fun, _1, _2, _3)); \ - } - -namespace dynamicgraph -{ - /*! @ingroup dgraph - \brief This class implements the first level interpretor - to control basic functionnalities of the plugins. - - It provides a shell allowing to : - \li load plugin libraries, - \li create instances of plugin, - \li destroy the plugins, - \li unload the libraries, - \li set a signal, - \li get a signal, - \li run scripts, - \li compute a signal, - \li act as a proxy for the commands of the plugins. - */ - class DYNAMIC_GRAPH_DLLAPI Interpreter - { - public: - /*! \brief Type of a basic function for the shell. - Such function returns a void and takes 3 arguments: - \li the functionnality (i.e. the method) it provides to the shell, - \li a stream of input string to pass when called, - \li an output stream for display. - */ - typedef boost::function3<void, - const std::string&, - std::istringstream&, - std::ostream&> ShellBasicFunction; - - protected: - /*! \brief This type defines a sorted set of basic functions with a unique key. */ - typedef std::map<std::string, ShellBasicFunction> FunctionMap; - /*! Instance of this type. */ - FunctionMap functionMap; - - public: - /*! \brief Default constructor - \par[in] dlPtr: a plugin loader to perform the actions provided by this shell. - */ - Interpreter( PluginLoader* dlPtr=NULL ); - - typedef PluginLoader * sotPluginLoaderPTR; - /*! \brief The plugin loader */ - sotPluginLoaderPTR dlPtr; - - protected: - bool initDone; // Debug - public: - std::string prompt; - static const std::string PROMPT_DEFAULT; - - public: - /*! \brief Register a function at the upper level of the shell. - \par[in] funname: The function's name, - \par[in] fun: The pointer to the function. - */ - void registerFunction( const std::string& funname, const ShellBasicFunction& fun ); - bool deregisterFunction( const std::string& funname ); - - - /*! \brief Set the reference of the plugin loader. */ - void referencePluginLoader( PluginLoader* dl__ ) - { dlPtr = dl__; } - - public: - - /*! \name Implements the commands. - @{ - */ - /*! \brief Instanciante an object - Extracts the name and the class of the object, verifies it is unique, - and creates the instance if this is the case. - */ - void cmdNew( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Destroy the object. - Extracts the name for cmdArg and destroy the object. - */ - void cmdDestroy( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Connect two signals. - Connect an input signal to an output one. - */ - void cmdPlug( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Load a dynamic library which includes a plugin. - Extracts the name first and the directory in second from cmdArg - to load the dynamic library. - */ - void cmdLoadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Unload a dynamic library which includes a plugin. - Extracts the name to unload the dynamic library. - */ - void cmdUnloadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Ask to each register function to display its help. */ - void cmdHelp( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Run a script */ - void cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Set a signal [obj.signal] to a value [value] - with cmdArg = "[obj.signal] [value]" - */ - void cmdSetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Display the value of the signal [obj.signal] - with cmdArg = "[obj.signal]" - */ - void cmdGetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Compute the value of the signal [obj.signal] at time [time] - with cmdArg = "[obj.signal] [time]" - */ - void cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Entry point to treat a command. */ - void cmd( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Extract the object name and the function name from a command. */ - static bool objectNameParser( std::istringstream& cmdparse, - std::string& objName,std::string& funName ); - - /*! @} */ - - public: - /*! \brief Method to start the shell. - \par[in] sin: The input stream from which the command will be extracted. - \par[out] sout: The output stream to which the result will be displayed. - \par[in] prompt: The prompt to be displayed. - - */ - void shell( std::istream& sin, std::ostream& sout, const std::string& prompt="" ); - void writeCompletionList(std::ostream& os); - - - }; - - /*! \brief Class for automatic registration of shell functions. - * Use the macro DYNAMIC-GRAPH_SHELL_FUNCTION_REGISTERER(name, fun) in a .cpp file - * to register functions on plugin load. - */ - class DYNAMIC_GRAPH_DLLAPI ShellFunctionRegisterer - { - public: - ShellFunctionRegisterer (const std::string& funName, - const Interpreter::ShellBasicFunction& f); - }; - - DYNAMIC_GRAPH_DLLAPI extern Interpreter g_shell; - -} // end of namespace dynamicgraph. - -#endif //! DYNAMIC_GRAPH_INTERPRETER_H diff --git a/include/dynamic-graph/plugin-loader.h b/include/dynamic-graph/plugin-loader.h deleted file mode 100644 index 64a0274f5c5451c6176a8870d3d28779f1013f38..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/plugin-loader.h +++ /dev/null @@ -1,111 +0,0 @@ -// -*- mode: c++ -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef DYNAMIC_GRAPH_PLUGIN_LOADER_H -# define DYNAMIC_GRAPH_PLUGIN_LOADER_H -# include <list> -# include <string> -# include <map> - -# include <dynamic-graph/fwd.hh> -# include <dynamic-graph/dynamic-graph-api.h> - -namespace dynamicgraph -{ - /*! @ingroup dgraph - - \brief Loads plugins from dynamic libraries (usually .so or .dll - files). - - The sotPluginLoader can be made to load individual plugins by - specifying their filenames to addPlugin () or reading them from a - configuration file (loadPluginlist). Once loaded, the plugins - register themselves to the sotFactory and the related objects can - subsequently be instantiated by the sotInterpretor for example. - - */ - class DYNAMIC_GRAPH_DLLAPI PluginLoader - { - public: - /*! \brief Default constructor. */ - PluginLoader (); - ~PluginLoader (); - - /*! \brief Set the directory from which to load the dynamic libraries - containing the plugins. */ - const std::string& setDirectory (const std::string& n); - /*! \brief Get the directory from which to load the dynamic libraries - containing the plugins. */ - const std::string& getDirectory () const; - - /*! \brief Adds a list of plugins - - It is done by reading the file configFile which contains for - each line a plugin name. - - \par[in] configFile: The name of the file which contains the - plugins name. - \par[in] dir: The name of the directory which contains the - dynamic libraries. - */ - void loadPluginList (const std::string& configFile, - const std::string& dir = ""); - - /*! \brief Adds a single plugin */ - void addPlugin (const std::string& name, - const std::string& dir = ""); - - /*! \brief Load the plugins previously added */ - void loadPlugins (); - - /*! \brief Remove from the user memory the dynamic library related - to the plugin. */ - void unloadPlugin (const std::string& plugname); - - /*! \brief Remove all the dynamic libraries related to the plugins. - For non-re-entrant plugins this method HAS TO be called. */ - void unloadAllPlugins (); - - const std::map<std::string, std::string>& getLoadedPluginNames () const - { - return loadedPluginNames; - } - - const std::string& searchPlugin (const std::string& plugname); - - protected: - /*! \brief Directory from where the dynamic libraries are loaded. */ - std::string pluginDirectory; - - /*! \brief List of plugin names given by their name postfixed to - the directory. */ - std::list< std::string > pluginNames; - - /*! \brief If a plugin has been loaded then this map contains - the name of the plugin. - \note This field looks useless. - */ - std::map<std::string, std::string> loadedPluginNames; - - /*! \brief Keeps a reference to the library according to the name of the - plugin. */ - PluginRefMap* pluginRefs; - }; - -} // end of namespace dynamicgraph. - -#endif //! DYNAMIC_GRAPH_PLUGIN_LOADER_H diff --git a/include/dynamic-graph/pool.h b/include/dynamic-graph/pool.h index 558884337f104d14a24d0fc1b50660c6f9e79e81..4c4cd1acb02141c151db40af90156371da122c45 100644 --- a/include/dynamic-graph/pool.h +++ b/include/dynamic-graph/pool.h @@ -88,10 +88,6 @@ namespace dynamicgraph void clearPlugin (const std::string& name); /*! @} */ - - /*! \brief Get a reference to a signal. */ - SignalBase<int>& getSignal (std::istringstream& sigpath); - /*! \brief This method looks for the object named objectName, and ask to provide the function functionName with the arguments cmdArg. If the method of the object displays some information this will diff --git a/include/dynamic-graph/shell-procedure.h b/include/dynamic-graph/shell-procedure.h deleted file mode 100644 index 8b865087ac318a3f4a0c855946ea1fa97b1f7049..0000000000000000000000000000000000000000 --- a/include/dynamic-graph/shell-procedure.h +++ /dev/null @@ -1,97 +0,0 @@ -// -*- mode: c++ -*- -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#ifndef DYNAMIC_GRAPH_SHELL_PROCEDURE_H -# define DYNAMIC_GRAPH_SHELL_PROCEDURE_H -# include <string> -# include <map> -# include <sstream> -# include <list> -# include <vector> - -# include <dynamic-graph/exception-factory.h> -# include <dynamic-graph/interpreter.h> -# include <dynamic-graph/config-shell-procedure.hh> - -/// \ingroup dgraph -/// -/// \brief This plugin exposes shell commands relative to the script -/// language constructs such as procedures and for loops. -/// -/// For more information, load the plugin and type help in a shell. -class DG_SHELLPROCEDURE_DLLAPI ShellProcedure -{ - public: - /// \brief Symbolizes a function call in the dynamic-graph language. - struct Instruction - { - /// \brief Command name. - std::string cmd; - /// \brief Arguments lists. - std::vector<std::string> args; - - std::vector<int> params; - }; - - /// \brief Symbolizes a procedure in the dynamic-graph language. - struct Procedure - { - /// \brief Store the procedure body. - std::list<Instruction> instructions; - /// \brief Store the procedure arguments. - std::vector<std::string> params; - - /// \brief Reset the procedure. - void clear () - { - instructions.clear (); - params.clear (); - } - }; - - /// \brief Map procedure name to their body. - typedef std::map<std::string, Procedure> ProcedureList; - - public: - std::string procName; - ProcedureList procedureList; - Procedure currentProc; - - public: - void cmdStartProcedure (const std::string& cmd, - std::istringstream& args, - std::ostream& os); - - void cmdContinueProcedure (const std::string& cmd, - std::istringstream& args, - std::ostream& os); - - void cmdEndProcedure (const std::string& cmd, - std::istringstream& args, - std::ostream& os); - - void cmdProcedure (const std::string& procname, - const std::string& cmd, - std::istringstream& args, - std::ostream& os); - - static void cmdFor (const std::string& cmd, - std::istringstream& args, - std::ostream& os); -}; - -#endif //! DYNAMIC_GRAPH_SHELL_PROCEDURE_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55548914ee5843a3ed5509fae297f3f467184092..0eb379162d9d4b52e26868449668fa8edd069748 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,19 +32,13 @@ ADD_LIBRARY(${LIBRARY_NAME} dgraph/entity.cpp dgraph/factory.cpp - dgraph/interpreter.cpp - dgraph/interpreter-helper.cpp - dgraph/plugin-loader.cpp dgraph/pool.cpp - dgraph/import.cpp exception/exception-abstract.cpp exception/exception-factory.cpp exception/exception-signal.cpp exception/exception-traces.cpp - shell/functions.cpp - signal/signal-array.cpp signal/signal-caster.cpp @@ -69,9 +63,6 @@ INSTALL(TARGETS ${LIBRARY_NAME} ### Plugins #################################### SET(plugins_list - plugins/shell-procedure - plugins/shell-functions - debug/contiifstream traces/tracer traces/tracer-real-time ) diff --git a/src/dgraph/import.cpp b/src/dgraph/import.cpp deleted file mode 100644 index dab1c57297473656e216e5b6cef0a2b9810e15d2..0000000000000000000000000000000000000000 --- a/src/dgraph/import.cpp +++ /dev/null @@ -1,362 +0,0 @@ -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#include <cassert> - -#include <iostream> -#include <fstream> -#include <sstream> -#include <string> -#include <vector> - -#include <boost/algorithm/string.hpp> -#include <boost/filesystem.hpp> -#include <boost/foreach.hpp> -#include <boost/format.hpp> - -#include <dynamic-graph/debug.h> -#include <dynamic-graph/exception-abstract.h> -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/import-default-paths.h> -#include <dynamic-graph/import.h> -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/plugin-loader.h> - -// The default import paths has to be passed from the build system -// as a -D flag for instance. -// It contains the absolute path to the default directory where -// the scripts will be searched. -#ifndef DG_IMPORT_DEFAULT_PATHS -# error "Default import path is not defined." -#endif //! DG_IMPORT_DEFAULT_PATHS - -static const char* ENV_DG_PATH = "DG_PATH"; - - -// Define OS specific extensions for shared libraries. -#ifdef _WIN32 -static const char* SHARED_LIBRARY_EXT = ".dll"; -#elif __APPLE__ -static const char* SHARED_LIBRARY_EXT = ".dylib"; -#else -static const char* SHARED_LIBRARY_EXT = ".so"; -#endif - -namespace dynamicgraph -{ - namespace command - { - namespace - { - /// Initialize import paths list (called during static initialization). - paths_t initializePaths (); - - /// \brief Import paths list. - /// - /// This vector of string is similar to Unix variables such as - /// PATH. It contains all paths that are used to search when - /// importing a script. - /// - /// The look-up is made from right to left: - /// - /// On Unix: - /// importPaths = A:B:C - /// On Microsoft Windows: - /// importPaths = A;B;C - /// - /// When typing "import foo", C will be searched first then B - /// and A. The search stops when the file is found. - paths_t importPaths = initializePaths (); - - /// \brief Already imported paths to avoid multiple inclusion. - paths_t alreadyImportedPaths; - - /// Search for a module. - /// - /// Returns the module full absolute path or an empty string if - /// it cannot be found. - boost::filesystem::path searchModule (const std::string& module); - - /// \brief Remove quotes from a string. - /// - /// Transform strings such as "foo" or 'foo' into foo. - void removeQuotes (std::string& msg); - - paths_t initializePaths () - { - // Split the environment variable. - std::string environmentSeparator; - - // On Microsoft Windows, environment variables are splitted along - // the ``;'' character. It is ``:'' on *NIX systems. -#if defined _WIN32 || defined __CYGWIN__ - environmentSeparator = ";"; -#else - environmentSeparator = ":"; -#endif // defined _WIN32 || defined __CYGWIN__ - - - // Declare variables that will be returned. - paths_t importPaths; - - // Split the built-in values. - std::vector<std::string> splittedDefaultPaths; - boost::split (splittedDefaultPaths, - DG_IMPORT_DEFAULT_PATHS, - boost::is_any_of (environmentSeparator)); - - // Insert them back. - { - std::back_insert_iterator<paths_t> bi (importPaths); - std::copy (splittedDefaultPaths.begin (), - splittedDefaultPaths.end (), bi); - } - - // Search for the environment variable value. - char* ScriptPath = getenv (ENV_DG_PATH); - if (!ScriptPath) - return importPaths; - - std::vector<std::string> splittedEnvironmentVariable; - boost::split (splittedEnvironmentVariable, ScriptPath, - boost::is_any_of (environmentSeparator)); - - // Insert it back - std::back_insert_iterator<paths_t> bi (importPaths); - std::copy (splittedEnvironmentVariable.begin (), - splittedEnvironmentVariable.end (), bi); - return importPaths; - } - - boost::filesystem::path searchModule (const std::string& module) - { - // To ensure correct priorities, the traversal has to - // done left to right. - typedef paths_t::const_iterator citer_t; - for (citer_t it = importPaths.begin (); - it != importPaths.end (); ++it) - { - const boost::filesystem::path& dir = *it; - if (!boost::filesystem::is_directory (dir)) - continue; - - boost::filesystem::path path = dir / module; - boost::filesystem::path pathPlugin = path; - pathPlugin.replace_extension (SHARED_LIBRARY_EXT); - - if (boost::filesystem::exists (pathPlugin) - && !boost::filesystem::is_directory (pathPlugin)) - return pathPlugin; - - if (boost::filesystem::exists (path) - && !boost::filesystem::is_directory (path)) - return path; - } - - return boost::filesystem::path (); - } - - void removeQuotes (std::string& msg) - { - if ((msg[0] == '"' && msg[msg.length () - 1] == '"') - || (msg[0] == '\'' && msg[msg.length () - 1] == '\'')) - msg = msg.substr (1, msg.length () - 2); - } - - void importScript (dynamicgraph::Interpreter& interpreter, - const boost::filesystem::path& path, - std::ifstream& file, - std::ostream& os) - { - int lineIdx = 0; - try - { - while (file.good ()) - { - dgDEBUGIN (15); - ++lineIdx; - - std::string line; - std::getline (file, line); - if (line.empty ()) - continue; - - std::istringstream iss (line); - std::string currentCmdName; - std::string currentCmdArgs; - if (iss >> currentCmdName) - { - std::getline (iss, currentCmdArgs); - boost::format fmt ("Run ``%1%'' with args ``%2%''"); - fmt % currentCmdName % currentCmdArgs; - dgDEBUG(25) << fmt.str () << std::endl; - std::istringstream issArgs (currentCmdArgs); - interpreter.cmd (currentCmdName, issArgs, os); - } - dgDEBUGOUT (15); - } - } - catch (ExceptionAbstract& exc) - { - // FIXME: come on... - std::string& msg = - const_cast<std::string&> (exc.getStringMessage ()); - boost::format fmt (" (in line %1% of file ``%2%'')"); - fmt % lineIdx % path.file_string (); - msg = msg + fmt.str (); - std::cout << msg << std::endl; - throw; - } - } - - void importPlugin (dynamicgraph::Interpreter& interpreter, - const boost::filesystem::path& path, - std::ostream&) - { - if (!interpreter.dlPtr) - { - DG_THROW ExceptionFactory - (ExceptionFactory::DYNAMIC_LOADING, - "No plug-in loader available."); - return; - } - interpreter.dlPtr->addPlugin (path.filename (), - path.parent_path ().file_string ()); - interpreter.dlPtr->loadPlugins (); - } - } // end of anonymous namespace. - - void import (dynamicgraph::Interpreter& interpreter, - const std::string& cmdLine, - std::istringstream& cmdArg, - std::ostream& os) - { - if (cmdLine == "help") - { - os << " - import <script.txt>\t\t\t\tImport the script." - << std::endl - << "\t\t\t\tBehaves like run but searches for files" - << " in default script directories." - << std::endl; - return; - } - - dgDEBUGIN(15); - - std::string module; - cmdArg >> module; - - // Get rid of quotes. - removeQuotes (module); - - // Get the absolute path of the module. - boost::filesystem::path path = searchModule (module); - - // Check that the module can be opened. - std::ifstream file (path.file_string ().c_str ()); - if (!boost::filesystem::is_regular_file (path) - || !file.is_open () || !file.good ()) - { - std::string scriptDirectories; - - if (importPaths.empty ()) - scriptDirectories = "empty"; - else - { - BOOST_FOREACH (const boost::filesystem::path& path, importPaths) - { - scriptDirectories += path.file_string (); - scriptDirectories += ", "; - } - scriptDirectories = scriptDirectories.substr - (0, scriptDirectories.length () - 2); - } - - boost::format fmt - ("failed to import module ``%1%'' (import paths: %2%)."); - fmt % module; - fmt % scriptDirectories; - DG_THROW ExceptionFactory - (ExceptionFactory::READ_FILE, fmt.str ()); - return; - } - - // If the module has already been imported, do not import it - // again. - if (std::find (alreadyImportedPaths.begin (), - alreadyImportedPaths.end (), - path) != alreadyImportedPaths.end ()) - return; - - if (path.extension () != SHARED_LIBRARY_EXT) - importScript (interpreter, path, file, os); - else - importPlugin (interpreter, path, os); - - alreadyImportedPaths.push_back (path); - - dgDEBUGOUT(15); - } - - void pushImportPaths (dynamicgraph::Interpreter&, - const std::string& cmdLine, - std::istringstream& cmdArg, - std::ostream& os) - { - if (cmdLine == "help") - { - os << " - pushImportPaths <path>\t\t\t\tAdd path to default directories." - << std::endl; - return; - } - std::string path; - cmdArg >> path; - removeQuotes (path); - if (path.empty ()) - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "pushImportPaths expects exactly one argument."); - - if (!cmdArg.eof ()) - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "pushImportPaths expects exactly one argument."); - - importPaths.push_back (path); - } - - void popImportPaths (dynamicgraph::Interpreter&, - const std::string& cmdLine, - std::istringstream&, - std::ostream& os) - { - if (cmdLine == "help") - { - os << " - popImportPaths <path>\t\t\t\tDrop path from default directories." - << std::endl; - return; - } - if (!importPaths.empty ()) - importPaths.pop_back (); - else - //FIXME: get a better error code for this. - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "Vector is already empty."); - } - - } // end of namespace command. -} // end of namespace sot. diff --git a/src/dgraph/interpreter-helper.cpp b/src/dgraph/interpreter-helper.cpp deleted file mode 100644 index bc459c4699106aabfce513b6bd12cffd1dcbee4e..0000000000000000000000000000000000000000 --- a/src/dgraph/interpreter-helper.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#include <dynamic-graph/debug.h> -#include <dynamic-graph/entity.h> -#include <dynamic-graph/factory.h> -#include <dynamic-graph/interpreter-helper.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/pool.h> -#include <dynamic-graph/signal-base.h> - -namespace dynamicgraph -{ - void - InterpreterHelper::cmdPlug (const std::string& obj1, - const std::string& signame1, - const std::string& obj2, - const std::string& signame2, - std::ostream&) - { - dgDEBUG (20) << "Get Ent1 <" << obj1 << "> ." << std::endl; - Entity& ent1 = g_pool.getEntity (obj1); - dgDEBUG (20) << "Get Sig1 <" << signame1 << "> ." << std::endl; - SignalBase<int>& sig1 = ent1.getSignal (signame1); - - dgDEBUG (20) << "Get Ent2 <" << obj2 << "> ." << std::endl; - Entity& ent2 = g_pool.getEntity (obj2); - dgDEBUG (20) << "Get Sig2 <" << signame2 << "> ." << std::endl; - SignalBase<int>& sig2 = ent2.getSignal (signame2); - - dgDEBUG (25) << "Plug..." << std::endl; - sig2.plug (&sig1); - } - - void - InterpreterHelper::cmdNew (const std::string& className, - const std::string& objName, - std::ostream& os) - { - dgDEBUG(15) << "New <" << className << "> requested." << std::endl; - if (g_factory.existEntity (className)) - { - dgDEBUG(15) << "New entity<" << className << "> " - << objName << std::endl; - g_factory.newEntity (className, objName); - } - else - os << " !! Class <" << className << "> does not exist." << std::endl; - } - - - void - InterpreterHelper::cmdDestroy (const std::string& objName, std::ostream&) - { - dgDEBUG(15) << "Destroy <" << objName << "> requested." << std::endl; - delete &(g_pool.getEntity (objName)); - } - - void - InterpreterHelper::cmdLoadPlugin (const std::string& directory, - const std::string& pluginName, - std::ostream&) - { - if (directory.length () != 0) - dlPtr.setDirectory (directory); - dlPtr.addPlugin (pluginName); - - try - { - dgDEBUG(15) << "Try to load " << pluginName<< std::endl; - dlPtr.loadPlugins (); - } - catch (const ExceptionAbstract& e) - { - dgDEBUG(5) << e << std::endl; - throw; - } - } - - void - InterpreterHelper::cmdUnloadPlugin (const std::string& pluginName, - std::ostream&) - { - dgDEBUGIN (15); - try - { - dgDEBUG (25) << "Try short name " << pluginName << std::endl; - const std::string& fullname = dlPtr.searchPlugin (pluginName); - dgDEBUG(25) << "Full name " << fullname << std::endl; - dlPtr.unloadPlugin (fullname); - } - catch (...) - { - dgDEBUG(25) << "Full name " << pluginName << std::endl; - dlPtr.unloadPlugin (pluginName); - } - - dgDEBUGOUT (15); - } - - void - InterpreterHelper::cmdSetSignal (const std::string& objname, - const std::string& signame, - const std::string& value, - std::ostream&) - { - dgDEBUGIN (15); - - Entity& obj = g_pool.getEntity (objname); - SignalBase<int>& sig = obj.getSignal (signame); - - std::istringstream cmdArg (value); - sig.set (cmdArg); - - dgDEBUGOUT (15); - } - - void - InterpreterHelper::cmdGetSignal (const std::string& objname, - const std::string& signame, - std::ostream& os) - { - dgDEBUGIN (15); - - Entity& obj = g_pool.getEntity (objname); - SignalBase<int>& sig = obj.getSignal (signame); - - os << signame << " = "; - sig.get (os); - - dgDEBUGOUT (15); - } - - void - InterpreterHelper::cmdComputeSignal (const std::string& objname, - const std::string& signame, - const int& time, - std::ostream&) - { - dgDEBUGIN (15); - Entity& obj = g_pool.getEntity (objname); - SignalBase<int>& sig = obj.getSignal (signame); - - sig.recompute (time); - - dgDEBUGOUT (15); - } -} // end of namespace dynamicgraph. diff --git a/src/dgraph/interpreter.cpp b/src/dgraph/interpreter.cpp deleted file mode 100644 index 64a7ee0681021902d87c60b06ce0246a94b58507..0000000000000000000000000000000000000000 --- a/src/dgraph/interpreter.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -#include <boost/format.hpp> - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/debug.h> -#include <dynamic-graph/import.h> - -/* --- STD --- */ -using namespace std; -using namespace dynamicgraph; - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -const std::string Interpreter::PROMPT_DEFAULT = "> "; - -Interpreter:: -Interpreter( PluginLoader* dl__ ) - : dlPtr(dl__),initDone(false)//,prompt( PROMPT_DEFAULT ) -{ - registerFunction("plug",boost::bind(&Interpreter::cmdPlug,this,_1,_2,_3)); - registerFunction("new",boost::bind(&Interpreter::cmdNew,this,_1,_2,_3)); - registerFunction("destroy",boost::bind(&Interpreter::cmdDestroy,this,_1,_2,_3)); - registerFunction("run",boost::bind(&Interpreter::cmdRun,this,_1,_2,_3)); - registerFunction("loadPlugin",boost::bind(&Interpreter::cmdLoadPlugin,this,_1,_2,_3)); - registerFunction("unloadPlugin",boost::bind(&Interpreter::cmdUnloadPlugin,this,_1,_2,_3)); - registerFunction("help",boost::bind(&Interpreter::cmdHelp,this,_1,_2,_3)); - registerFunction("set",boost::bind(&Interpreter::cmdSetSignal,this,_1,_2,_3)); - registerFunction("get",boost::bind(&Interpreter::cmdGetSignal,this,_1,_2,_3)); - registerFunction("compute",boost::bind(&Interpreter::cmdComputeSignal,this,_1,_2,_3)); - registerFunction("import",boost::bind(&dynamicgraph::command::import,boost::ref(*this),_1,_2,_3)); - registerFunction("pushImportPaths",boost::bind(&dynamicgraph::command::pushImportPaths,boost::ref(*this),_1,_2,_3)); - registerFunction("popImportPaths",boost::bind(&dynamicgraph::command::popImportPaths,boost::ref(*this),_1,_2,_3)); - prompt = PROMPT_DEFAULT; - initDone = true; -} - -void Interpreter:: -registerFunction( const string& funname, - const Interpreter::ShellBasicFunction& fun ) -{ - if( initDone ) {dgDEBUG(15) << "Register " << funname << std::endl;} - FunctionMap::iterator funkey = functionMap.find(funname); - if( funkey != functionMap.end () ) // key does exist - { - if( initDone ) - { - dgDEBUG(15) << "!! Another function already defined with the same name. Overloading " - << "Funname is" <<funname.c_str () << endl; - throw ExceptionFactory( ExceptionFactory::FUNCTION_CONFLICT, - "Another function already defined with the same name. ", - "Funname is <%s>.",funname.c_str () ); - - } - } - else - { -// dgDEBUG(10) << "Register function <"<< funname -// << "> in the shell interpretor." <<endl; - functionMap[funname] = fun; - } -} - - - -bool Interpreter:: -deregisterFunction( const std::string& funname ) -{ - return ( 0!=functionMap.erase(funname) ); -} - - -/* --------------------------------------------------------------------- */ -/* --- NEW ------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -#include <dynamic-graph/factory.h> -using namespace std; -#include <dynamic-graph/entity.h> -#include <dynamic-graph/signal-base.h> - -void Interpreter:: -cmdPlug( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - plug <obj1.sig1> <obj2.sig2>" - << "\t\tPlug sig1 (producer) on sig2 (consumer)." <<endl; - return; - } - string ssig1,ssig2; - cmdArg>>ssig1>>ssig2; - - string obj1,fun1; - string obj2,fun2; - istringstream str1(ssig1),str2(ssig2); - if( (!objectNameParser(str1,obj1,fun1))||(!objectNameParser(str2,obj2,fun2)) ) - { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "Plug function: syntax is plug OBJ1.SIG1 OBJ2.SIG2.", - "(while calling plug %s %s).",ssig1.c_str (), - ssig2.c_str () ); - } - - dgDEBUG(20) << "Get Ent1 <"<<obj1<<"> ."<<endl; - Entity& ent1 = g_pool.getEntity(obj1); - dgDEBUG(20) << "Get Sig1 <"<<fun1<<"> ."<<endl; - SignalBase<int> &sig1 = ent1.getSignal(fun1); - - dgDEBUG(20) << "Get Ent2 <"<<obj2<<"> ."<<endl; - Entity& ent2 = g_pool.getEntity(obj2); - dgDEBUG(20) << "Get Sig2 <"<<fun2<<"> ."<<endl; - SignalBase<int> &sig2 = ent2.getSignal(fun2); - - dgDEBUG(25) << "Plug..."<<endl; - sig2.plug(&sig1); -} - -void Interpreter:: -cmdNew( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - new <class> <object>" - << "\t\t\tCreate a new entity." <<endl; - return; - } - string className; - string objName; - cmdArg >> className >>objName; - dgDEBUG(15) << "New <" << className<<"> requested."<<endl; - if( g_factory.existEntity( className ) ) - { - dgDEBUG(15) << "New entity<"<<className<<"> " <<objName<<std::endl; - g_factory.newEntity(className,objName); - } - else os << " !! Class <" << className << "> does not exist."<<endl; -} - - -void Interpreter:: -cmdDestroy( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - destroy <object>" - << "\t\t\tDestroy an object." <<endl; - return; - } - string objName; cmdArg >> objName; - dgDEBUG(15) << "Destroy <" << objName <<"> requested."<<endl; - delete &( g_pool.getEntity( objName ) ); - -} - - -void Interpreter:: -cmdLoadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - loadPlugin <file.so> <directory>" - << "\t\tLoad the plugin from the specified directory." <<endl; - return; - } - if( NULL!=dlPtr ) - { - string pluginName,directory; - cmdArg >> pluginName; - cmdArg >> directory; - if( directory.length () != 0 ) dlPtr->setDirectory( directory ); - dlPtr ->addPlugin( pluginName ); - - try - { - dgDEBUG(15) << "Try to load " << pluginName<< endl; - dgDEBUG(25)<<"sotShell.dlPtr ="<< this->dlPtr <<endl; - dlPtr->loadPlugins (); - dgDEBUG(25)<<"sotShell.dlPtr ="<< this->dlPtr <<endl; - } - catch (const ExceptionAbstract& e) - { - dgDEBUG(5) << "ExceptionAbstract " << e << endl; - throw; - } - } - else { os << "!! Dynamic loading functionalities not accessible through the shell." <<endl; } -} - -void Interpreter:: -cmdUnloadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, - std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - unloadPlugin <path/file.so>" - << "\t\tUnload the plugin." <<endl; - return; - } - - dgDEBUGIN(15); - if( NULL!=dlPtr ) - { - string pluginName; - cmdArg >> pluginName; - try{ - dgDEBUG(25) << "Try short name " << pluginName << endl; - const std::string& fullname = dlPtr->searchPlugin(pluginName); - dgDEBUG(25) << "Full name " << fullname << endl; - dlPtr->unloadPlugin(fullname); - } - catch(...) - { - dgDEBUG(25) << "Full name " << pluginName << endl; - dlPtr->unloadPlugin(pluginName); - } - } - else { os << "!! Dynamic loading functionalities not accessible through the shell." <<endl; } - - dgDEBUGOUT(15); -} - - -void Interpreter:: -cmdHelp( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - dgDEBUGIN(25); - os << "Help" <<endl; - - std::string procname; bool personalizedHelp = false; - cmdArg >> ws; - if( cmdArg.good () ) - { - const std::streamoff gc = cmdArg.tellg (); - cmdArg >> procname; - cmdArg.seekg(gc); cmdArg.clear (); - personalizedHelp = true; - dgDEBUG(15)<< "Personalized help on <"<< procname<<">"<<gc<<endl; - } - - bool procfund = !personalizedHelp; - for( FunctionMap::const_iterator iter=functionMap.begin (); - iter!=functionMap.end ();++iter ) - { - if( iter->first!="help" ) - if( (! personalizedHelp) || ( procname==iter->first ) ) - { iter->second(cmdLine,cmdArg,os); procfund=true; } - } - if(! procfund ) { os<<" *** Procedure <"<<procname<<"> not found."<<endl; } - dgDEBUGOUT(25); -} - - -void Interpreter:: -cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - run <script.txt>\t\t\t\tRun the script." <<endl; - return; - } - - dgDEBUGIN(15); - - string filename; cmdArg>>filename; - dgDEBUG(25) << "Script <" <<filename<<">"<<endl; - - ifstream script( filename.c_str (),ios::in ); - if(! script.is_open () ) - { - boost::format fmt - ("failed to run file ``%1%'' (file does not exist or is not readable)."); - fmt % filename; - DG_THROW ExceptionFactory (ExceptionFactory::READ_FILE, fmt.str ()); - } - - const int SIZE = 16384; - char line[SIZE]; - int lineIdx = 0; - try - { - for (lineIdx = 1;; ++lineIdx) - { - dgDEBUGIN(15); - - script.getline (line, SIZE); - if (!script.good ()) - break; - - std::string name; - istringstream issTmp (line); - if (issTmp >> name) - { - issTmp.getline (line,SIZE); - std::istringstream iss (line); - - dgDEBUG(25) - << "Run <" << name << "> with args <" << line << ">" - << std::endl; - cmd (name, iss, os); - - dgDEBUGOUT(15); - } - } - } - catch (ExceptionAbstract& exc) - { - //FIXME: exception should be changed instead. - std::string& msg = const_cast<std::string&>(exc.getStringMessage ()); - std::stringstream oss; - oss << " (in line " << lineIdx <<" of file <" << filename << ">)"; - msg = msg + oss.str (); - throw exc; - } - - dgDEBUGOUT(15); - -} - - -void Interpreter:: -cmdSetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - set <obj.signal> <value>\t\t\tSet the signal to the constant value." <<endl; - return; - } - - dgDEBUGIN(15); - - string objname,signame; - objectNameParser(cmdArg,objname,signame); - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); - - cmdArg >> ws; - sig.set( cmdArg ); - - dgDEBUGOUT(15); - -} - -void Interpreter:: -cmdGetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - get <obj.signal> <value>\t\t\tGet the signal to the constant value." <<endl; - return; - } - - dgDEBUGIN(15); - - string objname,signame; - objectNameParser(cmdArg,objname,signame); - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); - - os << signame << " = "; sig.get( os ); - - dgDEBUGOUT(15); - -} - -void Interpreter:: -cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ) -{ - if( cmdLine == "help" ) - { - os << " - compute <obj.sig> <time>\t\t\tRecompute <sig> at time <time> " <<endl; - return; - } - - dgDEBUGIN(15); - - string objname,signame; - objectNameParser(cmdArg,objname,signame); - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); - - int time; cmdArg >> std::ws; - if( cmdArg.good () ) - {cmdArg >> time;} else {time=0;} - sig.recompute( time ); - - dgDEBUGOUT(15); - -} - - -/* --------------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -void Interpreter:: -cmd( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) -{ - istringstream cmdparse(cmdLine.c_str ()); - string obj,fun; - if (cmdLine.find_first_not_of(" ") == string::npos) - {} - else if( objectNameParser( cmdparse,obj,fun ) ) - { - dgDEBUG(15) << "Object <" << obj<< "> function <"<<fun<<">"<<endl; - g_pool.commandLine( obj,fun,cmdArg,os ); - } - else - { - dgDEBUG(15) << "Function <" << cmdLine <<">"<< endl; - FunctionMap::iterator funPtr = functionMap .find( cmdLine ); - if( funPtr == functionMap.end () ) - { - DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_FUNCTION, - "Unknown function."," (while calling <%s>)", - cmdLine.c_str () ); - } - funPtr->second(cmdLine,cmdArg,os); - } - -} - - - -bool Interpreter:: -objectNameParser( istringstream& cmdparse,std::string& objName,std::string& funName ) -{ - const int SIZE=128; - char buffer[SIZE]; - cmdparse >> ws; - cmdparse.getline( buffer,SIZE,'.' ); - if(! cmdparse.good () ) // The callback is not an object method - return false; - - objName = buffer; - //cmdparse.getline( buffer,SIZE ); - //funName = buffer; - cmdparse >> funName; - return true; -} - - - - -void Interpreter:: -shell( std::istream& sin, std::ostream& sout, const std::string& promptUser ) -{ - while( 1 ) - { - if( promptUser.length () ) sout << promptUser; else sout << prompt; - string cmdLine; - const int SIZE = 16384; - char cmdArgs[SIZE]; - sin >>skipws>> cmdLine ; - dgDEBUG(15) << "Cmd <" <<cmdLine<<">"<<endl; - if( cmdLine == "exit" ) break; - if( sin.eof () ) break; - - sin.getline( cmdArgs,SIZE-1 ); - - if( sin.gcount () >= SIZE-2 ) - { - sout << "!! Line size exceeded" << endl; - do{ sin.getline( cmdArgs,SIZE-1 ); } while ( sin.gcount () >= SIZE-2 ); - sout << cmdArgs << endl; - } - else - { - dgDEBUG(15) << "Args <" <<cmdArgs<<">"<<endl; - - istringstream args (cmdArgs); - - try{ cmd(cmdLine,args,sout); } - catch( exception& e ) { dgDEBUG(1) << e.what (); throw; } - catch(...) { dgDEBUG(1) << "!! unknow!." <<endl; throw; } - } - } -} - -ShellFunctionRegisterer:: -ShellFunctionRegisterer( const std::string& funName, - const Interpreter::ShellBasicFunction& f) -{ - dgDEBUGIN(25); - g_shell.registerFunction(funName,f); - dgDEBUGOUT(25); -} - - -void Interpreter::writeCompletionList(std::ostream& os) -{ - for (FunctionMap::iterator iter=functionMap.begin (); - iter != functionMap.end (); ++iter) - { - const std::string & name = iter->first; - os << name << std::endl; - } -} - -namespace dynamicgraph -{ - //! The global g_shell object. - Interpreter g_shell; -} // end of namespace dynamicgraph diff --git a/src/dgraph/plugin-loader.cpp b/src/dgraph/plugin-loader.cpp deleted file mode 100644 index d5cd531de09603c57815a7e0ff8d8c10e52d4384..0000000000000000000000000000000000000000 --- a/src/dgraph/plugin-loader.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -#ifdef WIN32 -#include <Windows.h> -#else -#include <dlfcn.h> -#endif - -/* --- DYNAMIC-GRAPH --- */ -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/debug.h> - - -/* --- STD --- */ -#include <fstream> -#include <sstream> -using namespace std; -using namespace dynamicgraph; - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -class dynamicgraph::PluginRefMap -{ -public: - -#ifdef WIN32 - typedef HMODULE plugin_key_type; -#else - typedef void* plugin_key_type; -#endif - - typedef std::map< std::string,plugin_key_type> KeyMap; - KeyMap keyMap; -}; - - -PluginLoader:: -PluginLoader () -{ - pluginRefs = new PluginRefMap (); -} - -PluginLoader:: -~PluginLoader () -{ - delete pluginRefs; -} - -const std::string& PluginLoader:: -setDirectory( const std::string& n ) -{ - return pluginDirectory = n; -} -const std::string& PluginLoader:: -getDirectory () const -{ - return pluginDirectory; -} - -void PluginLoader:: -loadPluginList( const std::string& configFileName, const std::string& dir ) -{ - dgDEBUGIN(15); - - - string name; - //while (1) - ifstream configFile( configFileName.c_str (),ios::in ); - if(! configFile.is_open ()) - { - DG_THROW ExceptionFactory( ExceptionFactory::READ_FILE, - "File is not open."," (while reading <%s>).", - configFileName.c_str () ); - } - - for(;;) - { - configFile>>name; - if(configFile.eof ()) break; - dgDEBUG(9)<<"Add <"<< name << "> to the list"<<endl; - addPlugin( name,dir); - } - - dgDEBUGOUT(15); -} - -void PluginLoader:: -addPlugin( const std::string& name, const std::string& dir ) -{ - dgDEBUGIN(15); - if( dir.length () ) - pluginNames.push_back( dir +"/"+name ); - else - { pluginNames.push_back( pluginDirectory +"/"+name ); } - dgDEBUGOUT(15); -} - - - - - -/* -------------------------------------------------------------------------- */ -/* --- DYNAMIC LOADER LIB --------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -void PluginLoader:: -loadPlugins () -{ - dgDEBUGIN(15); - - for( list<string>::iterator iter = pluginNames.begin (); - iter!=pluginNames.end ();++iter ) - { - dgDEBUG(9)<<"Load <"<< *iter << "> plugin"<<endl; -#ifndef WIN32 - PluginRefMap::plugin_key_type dlib = dlopen( iter->c_str (),RTLD_NOW|RTLD_GLOBAL); -#else - PluginRefMap::plugin_key_type dlib = LoadLibrary ( iter->c_str ()); -#endif - - dgDEBUG(19)<<"Plugin <"<< *iter << "> loaded "<<endl; - - if( NULL==dlib ) - { - std::string wrongLib = *iter; - pluginNames.erase(iter); - - // FIXME: this line has been added to avoid, since erasing - // an element from a list invalidates the underlying - // iterator. However I am not sure whether loading twice - // the plug-ins is safe or not and should be thoroughly - // tested. - // - // Under Linux this line should have no effect as an - // exception is thrown just after. MS Windows do not raise - // an exception here and must have an incoherent behavior - // anyway... - iter = pluginNames.begin (); -#ifndef WIN32 - dgDEBUG(5) << "Failure while loading: " <<dlerror () <<endl; - DG_THROW ExceptionFactory( ExceptionFactory::DYNAMIC_LOADING, - "Error while dlopen. ","<%s>",dlerror () ); -#else - // Retrieve the system error message for the last-error code - LPTSTR pszMessage; - DWORD dwLastError = GetLastError (); - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwLastError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&pszMessage, - 0, NULL ); - - - dgDEBUG(5) << "Failure while loading: " << pszMessage <<endl; - - std::ostringstream error_of; - error_of << "Error while LoadLibrary (" << wrongLib << ") "; - - DG_THROW ExceptionFactory( ExceptionFactory::DYNAMIC_LOADING, - error_of.str ().c_str (), pszMessage ); - - LocalFree(pszMessage); - -#endif - } - - loadedPluginNames[*iter] = (*iter); - pluginRefs->keyMap[*iter] = dlib; - } - pluginNames.clear (); - - dgDEBUGOUT(15); -} - -/* -------------------------------------------------------------------------- */ -/* --- DYNAMIC UN-LOADER LIB ------------------------------------------------ */ -/* -------------------------------------------------------------------------- */ - - -void PluginLoader:: -unloadPlugin( const std::string& plugname ) -{ - dgDEBUGIN( 15 ); - - PluginRefMap::KeyMap::iterator plugkey = pluginRefs->keyMap.find(plugname); - if( plugkey==pluginRefs->keyMap.end () ) // key does exist - { - throw ExceptionFactory( ExceptionFactory::OBJECT_CONFLICT, - "Plugin not loaded",": <%s>.",plugname.c_str () ); - } - -#ifndef WIN32 - const int errCode = dlclose(plugkey->second); -#else - const int errCode = FreeLibrary(plugkey->second); -#endif - if( errCode ) - { -#ifndef WIN32 - dgDEBUG(1) << "Error while unloading <" << plugname <<"> : " - << dlerror () <<endl; -#else - // Retrieve the system error message for the last-error code - LPTSTR pszMessage; - DWORD dwLastError = GetLastError (); - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwLastError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&pszMessage, - 0, NULL ); - - dgDEBUG(1) << "Error while unloading <" << plugname <<"> : " - << pszMessage <<endl; - - LocalFree(pszMessage); -#endif - } - - //pluginRefs.erase( plugkey ); - - dgDEBUGOUT( 15 ); -} - -const std::string& PluginLoader:: -searchPlugin( const std::string& plugname ) -{ - unsigned int refFound = 0; - const std::string *plugFullName =0; - for( PluginRefMap::KeyMap::iterator iter = pluginRefs->keyMap.begin (); - iter!=pluginRefs->keyMap.end ();++iter ) - { - const std::string &str = iter->first; - size_t found = str.find_last_of("/\\"); - dgDEBUG(15) << " folder: " << str.substr(0,found) << std::endl; - dgDEBUG(15) << " file: " << str.substr(found+1) << std::endl; - if( str.substr(found+1)==plugname ) - { - refFound++; - plugFullName=&iter->first; - } - } - - if( 1!=refFound ) throw 1; - - return *plugFullName; -} - - -void PluginLoader:: -unloadAllPlugins () -{ - dgDEBUGIN( 15 ); - - PluginRefMap::KeyMap::iterator plugkey = pluginRefs->keyMap.begin (); - - while( plugkey!=pluginRefs->keyMap.end () ) - { -#ifndef WIN32 - const int errCode = dlclose(plugkey->second); -#else - const int errCode = FreeLibrary(plugkey->second); -#endif - if( errCode ) - { -#ifndef WIN32 - dgDEBUG(1) << "Error while unloading <" << plugkey->first <<"> : " - << dlerror () <<endl; -#else - // Retrieve the system error message for the last-error code - LPTSTR pszMessage; - DWORD dwLastError = GetLastError (); - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwLastError, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&pszMessage, - 0, NULL ); - - dgDEBUG(1) << "Error while unloading <" << plugkey->first <<"> : " - << pszMessage <<endl; - - LocalFree(pszMessage); -#endif - } - plugkey++; - } - - //pluginRefs.erase( plugkey ); - - dgDEBUGOUT( 15 ); -} diff --git a/src/dgraph/pool.cpp b/src/dgraph/pool.cpp index 5cf7d30c51faa41db903d408670fab6dd74a5824..c7091a558b01865878c0748ca64e459cbde30b02 100644 --- a/src/dgraph/pool.cpp +++ b/src/dgraph/pool.cpp @@ -240,25 +240,6 @@ commandLine( const std::string& objectName,const std::string& functionName, } } - - -#include <dynamic-graph/interpreter.h> - -SignalBase<int>& -PoolStorage:: -getSignal( std::istringstream& sigpath ) -{ - std::string objname,signame; - if(! Interpreter::objectNameParser( sigpath,objname,signame ) ) - { DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_SIGNAL, - "Parse error in signal name" ); } - - Entity& ent = getEntity( objname ); - return ent.getSignal( signame ); -} - - - namespace dynamicgraph { //! The global g_pool object. PoolStorage g_pool; diff --git a/src/shell/functions.cpp b/src/shell/functions.cpp deleted file mode 100644 index 308cfa7e5714626028e7d8a00475032641c370a3..0000000000000000000000000000000000000000 --- a/src/shell/functions.cpp +++ /dev/null @@ -1,598 +0,0 @@ -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#include <fstream> - -#ifdef WIN32 -# include <Windows.h> -#endif // WIN32 - -#include <boost/foreach.hpp> -#include <boost/format.hpp> -#include <boost/numeric/conversion/converter.hpp> - -#include <dynamic-graph/debug.h> -#include <dynamic-graph/entity.h> -#include <dynamic-graph/exception-signal.h> -#include <dynamic-graph/factory.h> -#include <dynamic-graph/functions.h> -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/signal.h> - -using namespace dynamicgraph; - -static const char* NO_PLUGINLOADER_ERROR_MSG = - "!! Dynamic loading functionalities not accessible through the shell."; - -static void sleep_ (unsigned int secs); -static void sleep_ (unsigned int secs) -{ -#ifndef WIN32 - usleep(secs * 1000000); -#else - Sleep (secs * 1000); -#endif //! WIN32 -} - - - -void -ShellFunctions::cmdTry (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - try <cmd...>" - << "\t\t\t\tTry <cmd> and display the caught exception." << std::endl; - return; - } - - std::string cmdLine2; - cmdArg >> cmdLine2; - dgDEBUG(5) << "Try <" << cmdLine2 << ">" << std::endl; - - try - { - g_shell.cmd (cmdLine2,cmdArg,os); - } - catch (const ExceptionAbstract& e) - { - os << "dgERROR catch: " <<std::endl - << e << std::endl; - } - catch(...) - { - os << "Unknown error caught." << std::endl; - } -} - -void -ShellFunctions::cmdLoadPlugins (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - loadPlugins <file.txt> <directory>" - << "\t\tLoad the plugins listed in the file." << std::endl; - return; - } - - if (!g_shell.dlPtr) - { - os << NO_PLUGINLOADER_ERROR_MSG << std::endl; - return; - } - - std::string pluginName, directory; - cmdArg >> pluginName; - cmdArg >> directory; - - dgDEBUG(15) << "Load plugin list <" - << pluginName << "> from dir <" << directory - << ">." << std::endl; - - if (directory.length () != 0) - g_shell.dlPtr->setDirectory (directory); - - g_shell.dlPtr->loadPluginList (pluginName); - g_shell.dlPtr->loadPlugins (); -} - -void -ShellFunctions::cmdClearPlugin (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - clearPlugin <className>" - << "\t\tDestroy all the objects of type <className>." <<std::endl; - return; - } - - std::string pluginName; - cmdArg >> pluginName; - g_pool.clearPlugin (pluginName); -} - -void -ShellFunctions::cmdDisplayPlugins (const std::string cmdLine, - std::istringstream&, - std::ostream& os) -{ - typedef std::pair< std::string,std::string > plugin_t; - - if (cmdLine == "help") - { - os << " - displayPlugins " - << "\t\t\t\tDisplay the name of the loaded plugins." <<std::endl; - return; - } - - if (!g_shell.dlPtr) - { - os << NO_PLUGINLOADER_ERROR_MSG << std::endl; - return; - } - - boost::format fmt ("- <%s>:\t %s"); - BOOST_FOREACH(plugin_t plugin, g_shell.dlPtr->getLoadedPluginNames ()) - { - fmt % plugin.first % plugin.second; - os << fmt.str () << std::endl; - } -} - - -void -ShellFunctions::cmdDisplayFactory (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - "; - g_factory.commandLine(cmdLine,cmdArg,os); - return; - } - - std::string cmd2; - cmdArg >> cmd2; - g_factory.commandLine (cmd2, cmdArg, os); -} - -void -ShellFunctions::cmdCommentary (const std::string cmdLine, - std::istringstream&, - std::ostream& os) -{ - if (cmdLine == "help") - os << " # comment with '#': ignore the end of the line." << std::endl; - return; -} - - -void -ShellFunctions::cmdUnplug (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - unplug <obj2.sig2>" - << "\t\t\t\tPlug on sig2 (consumer) in sig1->sig2." << std::endl; - return; - } - - std::string ssig; - cmdArg>>ssig; - - std::string obj2, fun2; - std::istringstream str2 (ssig); - - if (!Interpreter::objectNameParser(str2, obj2, fun2)) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "Plug function: syntax is unplug OBJ2.SIG2.", - "(while calling plug %s %s).",ssig.c_str ()); - } - - dgDEBUG(20) << "Get Ent2 <" << obj2 << "> ." << std::endl; - Entity& ent2 = g_pool.getEntity (obj2); - dgDEBUG(20) << "Get Sig2 <" << fun2 << "> ." << std::endl; - SignalBase<int>& sig2 = ent2.getSignal (fun2); - - dgDEBUG(25) << "Unplug..." << std::endl; - sig2.unplug (); -} - -void -ShellFunctions::cmdSignalTime (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - signalTime <obj.sig>" - << "\t\t\t\tDisplay the time of sig." << std::endl; - return; - } - - std::string ssig; - cmdArg >> ssig; - - std::string obj2,fun2; - std::istringstream str2 (ssig); - if (!Interpreter::objectNameParser(str2,obj2,fun2)) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "signalTime function: syntax is signalTime OBJ2.SIG2.", - "(while calling signalTime %s).",ssig.c_str ()); - } - - dgDEBUG(20) << "Get Ent2 <" << obj2 << "> ." << std::endl; - Entity& ent2 = g_pool.getEntity (obj2); - dgDEBUG(20) << "Get Sig2 <" << fun2 << "> ." << std::endl; - SignalBase<int>& sig2 = ent2.getSignal (fun2); - - os << sig2.getTime () << std::endl; -} - -void -ShellFunctions::cmdSynchroSignal (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - synchro <obj.sig> [<period>]" - << "\t\t\t\tGet/Set the syncho of a signal <sig>." << std::endl; - return; - } - - std::string ws; - - SignalBase<int>& sig = g_pool.getSignal (cmdArg); - cmdArg >> ws; - - if (!cmdArg.good ()) - { - os << "period = " << sig.getPeriodTime () << std::endl; - return; - } - - int period = 0; - cmdArg >> period; - sig.setPeriodTime (period); - cmdArg >> ws; - if (cmdArg.good ()) - { - /* The sig is recomputed at the given period from the - * current time, at any time T so that T%p==0, p the period. - * By modifying the current time, the sig reomputation is done - * at T s.t. T%p=d, d the desynchro. */ - int currTime = sig.getTime (); - int desynchro; - cmdArg>>desynchro; - sig.setTime (currTime + desynchro); - } -} - -void -ShellFunctions::cmdEcho (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - echo <string>" - << "\t\t\t\tPrint <string. on the standard output." << std::endl; - return; - } - - std::string ws; - cmdArg >> ws; - while (cmdArg.good ()) - { - std::string toPrint; - cmdArg >> toPrint; - os << toPrint << " "; - } - os << std::endl; -} - -void -ShellFunctions::cmdCopy (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - copy <obj1.sig1> <obj2.sig2>" - << "\t\tCopy the value of sig1 to constant value in sig2." - << std::endl; - return; - } - - std::string ssig1, ssig2; - cmdArg >> ssig1 >> ssig2; - - std::istringstream str1 (ssig1), str2 (ssig2); - - try - { - SignalBase<int>& sig1 = g_pool.getSignal (str1); - SignalBase<int>& sig2 = g_pool.getSignal (str2); - - dgDEBUG(25) << "Copy..."<< std::endl; - sig2.plug (&sig1); - sig2.setConstantDefault (); - sig2.plug (&sig2); - } - catch (const ExceptionAbstract&) - { - throw; - } - catch (...) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "Copy: syntax is copy OBJ1.SIG1 OBJ2.SIG2.", - "(while calling copy %s %s).",ssig1.c_str (), - ssig2.c_str ()); - } -} - -void -ShellFunctions::cmdFreeze (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - freeze <obj.sig> " - << "\t\tOn a ptr-sig: save the current value from the source " - << "and unplug the signal." << std::endl; - return; - } - std::string ssig1; - cmdArg >> ssig1; - std::istringstream str1 (ssig1); - - try - { - SignalBase<int>& sig1 = g_pool.getSignal (str1); - - dgDEBUG(25) << "Unplug..."<< std::endl; - sig1.setConstantDefault (); - sig1.plug(&sig1); - } - catch (...) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "Freeze: syntax is freeze OBJ.SIG.", - "(while calling freeze %s ).", ssig1.c_str ()); - } -} - -void -ShellFunctions::cmdSqueeze (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << - " - squeeze <mainObj.mainSig> <squeezeObj.sigIn> <squeezeObj.sigOut>" - << "\t\tIntercalate squeezeObj between mainObj and its source." - << std::endl; - return; - } - - std::string ssigMain, ssigIn, ssigOut; - cmdArg >> ssigMain >> ssigIn >> ssigOut; - std::istringstream strMain(ssigMain); - std::istringstream strIn(ssigIn); - std::istringstream strOut(ssigOut); - - try - { - SignalBase<int>& sigMain = g_pool.getSignal (strMain); - SignalBase<int>& sigIn = g_pool.getSignal (strIn); - SignalBase<int>& sigOut = g_pool.getSignal (strOut); - - SignalBase<int>* sigMainSource = sigMain.getPluged (); - if(sigMainSource == &sigMain) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "The main signal is autopluged (or set constant). ", - "(while calling freeze %s ).",ssigMain.c_str ()); - } - - sigMain.plug (&sigOut); - sigIn.plug(sigMainSource); - } - catch (const ExceptionFactory& exc) - { - switch (exc.getCode ()) - { - case ExceptionFactory::UNREFERED_SIGNAL: - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "Sqeeze: unknown signal. ", - "(error while searching signal: %s ).", - exc.getMessage ()); - break; - default: - throw; - } - } -} - - -void -ShellFunctions::cmdEnableTrace (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - debugtrace [{true|false}] [<filename>=" - << DebugTrace::DEBUG_FILENAME_DEFAULT <<"]" - << "\t\tOpen/close the file <filename> for debug tracing." - << std::endl; - return; - } - - std::string ws; - cmdArg >> ws; - if (!cmdArg.good ()) - { - if (dgDEBUGFLOW.outputbuffer.good ()) - os << "true" << std::endl; - else - os << "false" << std::endl; - return; - } - - std::string opt; - std::string filename; - - cmdArg >> opt >> ws; - if (opt == "true") - if (cmdArg.good ()) - { - cmdArg >> filename; - DebugTrace::openFile (filename.c_str ()); - } - else - DebugTrace::openFile (); - else - DebugTrace::closeFile (); -} - -void -ShellFunctions::cmdSetPrompt (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - prompt [<string>] " - << "\t\tSet/get the default prompt." << std::endl; - return; - } - - std::string opt; - std::string ws; - cmdArg >> ws; - - if (!cmdArg. good ()) - { - os << "Current prompt is <" << g_shell. prompt << ">." << std::endl; - return; - } - - char buffer [80]; - cmdArg.getline (buffer, 80); - g_shell.prompt = buffer; -} - -void -ShellFunctions::cmdSleep (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - sleep [<float> secs] " - << "\t\tSleep (time in secs)." << std::endl; - return; - } - - std::string opt; - std::string ws; - cmdArg >> ws; - if (!cmdArg. good ()) - { - //FIXME: handle error here. - return; - } - - double secs = 0.; - cmdArg >> secs; - - typedef boost::numeric::converter<unsigned int, double> Double2Int; - unsigned int secs_ = Double2Int::convert (secs); - - if (secs_ > 0) - sleep_ (secs_); -} - -void -ShellFunctions::cmdBeep (const std::string cmdLine, - std::istringstream&, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - beep [<float> secs] " - << "\t\tSend a bip to the std::cout." << std::endl; - return; - } - - os << char (7) << "Beep!" << std::endl; -} - -void -ShellFunctions::cmdCompletionList (const std::string cmdLine, - std::istringstream& cmdArg, - std::ostream& os) -{ - if (cmdLine == "help") - { - os << " - completion <filename>" - << "\t\tGenerate the completion list for current graph." << std::endl; - return; - } - - try - { - std::string aFileName; - cmdArg >> aFileName; - - std::ofstream completionFile (aFileName.c_str ()); - g_pool.writeCompletionList (completionFile); - } - catch (const ExceptionAbstract &) - { - throw; - } - catch (...) - { - DG_THROW ExceptionFactory - (ExceptionFactory::SYNTAX_ERROR, - "setflag: sig should be of flag type. ", - "(while calling setflag)."); - } -} diff --git a/src/traces/tracer.cpp b/src/traces/tracer.cpp index c755759def9e1acdc4ffe3e1dcc24208daebd828..59e30494e27a9ba4a175cb5716f4da50a4184cdf 100644 --- a/src/traces/tracer.cpp +++ b/src/traces/tracer.cpp @@ -263,10 +263,6 @@ commandLine( const std::string& cmdLine } else if( cmdLine=="add" ) { - SignalBase<int> &sig = g_pool.getSignal(cmdArgs); - string r; cmdArgs>>ws>>r; - addSignalToTrace(sig,r); - dgDEBUG(14)<<"Add <" <<sig.getName ()<<"> with nick \""<<r<<"\""<<endl; } else if( cmdLine=="clear" ) { closeFiles (); toTraceSignals.clear (); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d6dc7a1f35a116d884b09dbb11dbc1a7ea7f5866..9268e2030cd98554cd509bed1b9665b60e279a4f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -66,6 +66,3 @@ DYNAMIC_GRAPH_TEST(factory) DYNAMIC_GRAPH_TEST(pool) DYNAMIC_GRAPH_TEST(signal-time-dependent) DYNAMIC_GRAPH_TEST(value) - -DYNAMIC_GRAPH_TEST(interpreter) -DYNAMIC_GRAPH_TEST(interpreter-tracer) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt deleted file mode 100644 index 5c7f9898adef870fea47dec674857e6e989946fb..0000000000000000000000000000000000000000 --- a/tools/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2010, Olivier Stasse, JRL, CNRS/AIST -# -# This file is part of dynamic-graph. -# dynamic-graph is free software: you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# dynamic-graph is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Lesser Public License for more details. You should have -# received a copy of the GNU Lesser General Public License along with -# dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -SET(tools dg-shell) - -include_directories(${Boost_INCLUDE_DIRS}) - -# Configure shell launch script. -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/dg-shell-plugin.cmake - ${${PROJECT_NAME}_BINARY_DIR}/tools/dg-shell-plugin) -INSTALL( - FILES - ${${PROJECT_NAME}_BINARY_DIR}/tools/dg-shell-plugin - DESTINATION - bin - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ - GROUP_EXECUTE GROUP_READ) - -FOREACH(tool_name ${tools}) - SET(EXECUTABLE_NAME ${tool_name}) - - ADD_DEFINITIONS(-DDEBUG=2) - - ADD_EXECUTABLE(${EXECUTABLE_NAME} - ${tool_name}.cpp) - - INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ) - - LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/lib) - - TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} - ${PROJECT_NAME}) - - IF(UNIX) - TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dl) - ENDIF(UNIX) - - INSTALL(TARGETS ${tool_name} DESTINATION bin) -ENDFOREACH(tool_name) diff --git a/tools/dg-shell-plugin.cmake b/tools/dg-shell-plugin.cmake deleted file mode 100644 index ae800e35515686e62d531465644a0a8321e6ccf5..0000000000000000000000000000000000000000 --- a/tools/dg-shell-plugin.cmake +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/sh -tmp=`mktemp` -echo "-- Launching dynamic-graph C shell with default plugins" -echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-functions.so" > $tmp -echo "loadPlugin ${CMAKE_INSTALL_PREFIX}/lib/plugin/shell-procedure.so" >> $tmp -${CMAKE_INSTALL_PREFIX}/bin/dg-shell -i $tmp $@ diff --git a/tools/dg-shell.cpp b/tools/dg-shell.cpp deleted file mode 100644 index d93fe0d4688e71880349385b94061c2206023032..0000000000000000000000000000000000000000 --- a/tools/dg-shell.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, -// JRL, CNRS/AIST. -// -// This file is part of dynamic-graph. -// dynamic-graph is free software: you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// dynamic-graph is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Lesser Public License for more details. You should have -// received a copy of the GNU Lesser General Public License along with -// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - -#include <sstream> -#include <string> -#include <vector> - -#include <boost/filesystem.hpp> -#include <boost/foreach.hpp> -#include <boost/format.hpp> -#include <boost/program_options.hpp> - -#include <dynamic-graph/entity.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/debug.h> - -extern std::ofstream debugfile; - -// Factorize exception catching code. -#define CATCH_EXCEPTIONS() \ - catch (std::exception& e) \ - { \ - std::cout \ - << errorPrefix \ - << e.what () << std::endl; \ - if (options.noninteractive) \ - return 1; \ - } \ - catch (const char* str) \ - { \ - std::cout << errorPrefix \ - << "Unknown exception " << str << std::endl; \ - if (options.noninteractive) \ - return 1; \ - } \ - catch (...) \ - { \ - dgDEBUG(5) << errorPrefix << " Unknown exception " << std::endl; \ - if (options.noninteractive) \ - return 1; \ - } \ - struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n - -struct Options -{ - /// \brief Should we provide a shell to the user or end the program - /// directly? - bool noninteractive; - /// \brief Prologue path (a prologue is a script implicitly - /// evaluated at start-up). - std::string prologue; - /// \brief Files to be evaluated at start-up (left to right order). - std::vector<std::string> inputs; -}; - -std::string defaultPrologue () -{ - char* home = getenv ("HOME"); - boost::filesystem::path path (home); - path/= ".dg-shellrc"; - return path.file_string (); -} - -int main (int argc, char** argv) -{ - dgDEBUGIN(15); - - dgDEBUG(5) << " Loading..." << std::endl; - dynamicgraph::PluginLoader pl; - dynamicgraph::g_shell.referencePluginLoader (&pl); - - Options options; - - // Parse options. - namespace po = boost::program_options; - po::options_description desc ("Allowed options"); - desc.add_options () - ("input,i", - po::value<std::vector<std::string> >(&options.inputs), - "file(s) evaluated at start-up") - ("noninteractive,n", - "enable non-interactive behavior") - ("prologue,p", - po::value<std::string>(&options.prologue)->default_value (defaultPrologue ()), - "override default prologue") - ("help,h", "produce help message") - ; - - po::variables_map vm; - try - { - po::store (po::parse_command_line (argc, argv, desc), vm); - po::notify (vm); - - if (vm.count ("help")) - { - std::cout << "Usage: " << argv[0] << " [options]" << std::endl - << desc << std::endl - << "Report bugs to <hpp@laas.fr>" << std::endl; - return 1; - } - options.noninteractive = vm.count ("noninteractive"); - } - catch (po::error& error) - { - std::cerr << "Error while parsing argument: " - << error.what () << std::endl; - return 1; - } - - std::list<std::string> inputs (options.inputs.begin (), - options.inputs.end ()); - - // First, evaluate the prologue. - boost::filesystem::path prologuePath (options.prologue); - if (!prologuePath.empty ()) - { - if (boost::filesystem::exists (prologuePath) - && !boost::filesystem::is_directory (prologuePath)) - inputs.push_front (prologuePath.file_string ()); - else - { - boost::format fmt ("Failed to load prologue: \"%s\"."); - fmt % prologuePath.file_string (); - std::cerr << fmt.str () << std::endl; - } - } - - // Load all input files. - BOOST_FOREACH (const std::string& pathStr, inputs) - { - boost::filesystem::path path (pathStr); - - std::stringstream ss; - ss << "!! In file <" << path.file_string () << "> : "; - std::string errorPrefix = ss.str (); - - try - { - std::istringstream script (path.file_string ()); - std::cout << "Run " << path.file_string () << std::endl; - dynamicgraph::g_shell.cmd ("run", script, std::cout); - } - CATCH_EXCEPTIONS (); - } - - // Interactive loop. - if (options.noninteractive) - return 0; - std::string errorPrefix = ""; - while (1) - { - try - { - dgDEBUG(5) << "Run shell." << std::endl; - dynamicgraph::g_shell.shell (std::cin, std::cout); - dgDEBUG(5) << "Shell over." << std::endl; - if (std::cin.eof ()) - break; - } - CATCH_EXCEPTIONS (); - } - - dgDEBUGOUT(15); - return 0; -}