Commit 6d3b7943 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr

Clean up: remove interpreter.

      Remove pool::getSignal().
parent 9c3b1f1a
......@@ -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)
......
......@@ -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
......
// -*- 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
// -*- 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
// -*- 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
// -*- 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
// -*- 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
......@@ -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
......
// -*- 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
......@@ -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