Skip to content

Commit

Permalink
Patch for Project #104: Commands and Methods : Away with the Template…
Browse files Browse the repository at this point in the history
…* classes

The TaskContext interface has been changed to the 'CommandRepository' and 'MethodRepository'
for commands and methods. Use the commands.pl script to convert your app.

git-svn-id: https://svn.mech.kuleuven.be/repos/orocos/orocos-trunk@5146 ce417995-dfc9-0310-95a0-acdaff106893
  • Loading branch information
psoetens committed Jul 20, 2006
1 parent 2dc70a9 commit 469e4c7
Show file tree
Hide file tree
Showing 71 changed files with 2,942 additions and 2,507 deletions.
10 changes: 9 additions & 1 deletion packages/corelib/common/current/include/TemplateTypeInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ namespace ORO_CoreLib
// A variable starts its life as unbounded.
Logger::log() << Logger::Debug << "Building Variable of type " << tname <<Logger::endl;
return new Attribute<T>( new detail::UnboundDataSource<ValueDataSource<T> >() );
//return new ScriptAttribute<T>();
}

DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& args) const
{
// It must start its life as unbounded.
Logger::log() << Logger::Debug << "Constructor of " << tname <<Logger::endl;
if ( args.empty() )
return new detail::UnboundDataSource<ValueDataSource<T> >();
return DataSourceBase::shared_ptr();
}

AttributeBase* buildAttribute( DataSourceBase::shared_ptr in) const
Expand Down
7 changes: 7 additions & 0 deletions packages/corelib/common/current/include/TypeInfoName.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ namespace ORO_CoreLib
return 0;
}

DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& ) const {
Logger::In loc("TypeInfoName");
Logger::log() << Logger::Error << "Can not construct value of "<<tname<<"."<<Logger::endl;
return DataSourceBase::shared_ptr();
}


virtual std::ostream& write( std::ostream& os, DataSourceBase::shared_ptr in ) const {
Logger::In loc("TypeInfoName");
#if HAVE_STREAMS
Expand Down
5 changes: 5 additions & 0 deletions packages/corelib/common/current/include/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ namespace ORO_CoreLib
*/
virtual AttributeBase* buildVariable(int sizehint) const;
virtual AttributeBase* buildVariable() const = 0;
/**
* Constructor syntax: construct a DataSource which returns an instance of data
* depending on the given arguments.
*/
virtual DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& args) const = 0;
/**
* build an alias with b as the value. If b is of the wrong type,
* 0 will be returned..
Expand Down
1 change: 0 additions & 1 deletion packages/corelib/events/current/include/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ namespace ORO_CoreLib
Event()
: signal_base_type()
{
Logger::log() << Logger::Debug << "Nameless Event Created." << Logger::endl;
}

const std::string& getName() const { return mname; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ is very powerful."
compile PeerParser.cxx
compile PropertyParser.cxx
compile FunctionFactory.cxx
compile TaskBrowser.cxx
compile ProgramLoader.cxx
compile GenericTaskContext.cxx
compile StatementProcessor.cxx
compile ParserScriptingAccess.cxx
compile TaskBrowser.cxx

requires OROPKG_SUPPORT_BOOST
requires OROPKG_SUPPORT_BOOST_GRAPH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
#ifndef FUNCTIONFACTORY_HPP
#define FUNCTIONFACTORY_HPP

#include "CommandFactoryInterface.hpp"
#include "OperationFactory.hpp"
#include "corelib/Property.hpp"
#include <map>
#include <string>
#include "ProgramInterface.hpp"
#include "DispatchInterface.hpp"

namespace ORO_Execution
{
Expand All @@ -47,41 +48,25 @@ namespace ORO_Execution
* a FunctionGraph in a Processor.
*/
class FunctionFactory
: public CommandFactoryInterface
: public detail::OperationFactoryPart<DispatchInterface*>
{
typedef std::map<std::string, ProgramInterfacePtr > map_t;
map_t funcmap;
ProgramInterfacePtr func;
ExecutionEngine* proc;
public:
FunctionFactory(ExecutionEngine* procs);
~FunctionFactory();
FunctionFactory(ProgramInterfacePtr func, ExecutionEngine* procs);

void addFunction(const std::string& name, ProgramInterfacePtr f ) ;

bool hasCommand(const std::string& com) const ;

std::vector<std::string> getCommandList() const;

std::string getResultType( const std::string& com ) const;
std::string getDescription( const std::string& com ) const;
std::string resultType() const;
std::string description() const;

ORO_CoreLib::PropertyBag
getArgumentSpec( const std::string& command ) const;

std::vector< ArgumentDescription > getArgumentList( const std::string& command ) const;
getArgumentSpec() const;

int getArity( const std::string& foo ) const;
ComCon create( const std::string& command,
const ORO_CoreLib::PropertyBag& args,
bool nodispatch ) const;
std::vector< ArgumentDescription > getArgumentList() const;

ComCon create(const std::string& command,
const std::vector<ORO_CoreLib::DataSourceBase*>& args,
bool nodispatch ) const;
int arity() const;

ComCon create(const std::string& command,
const std::vector<ORO_CoreLib::DataSourceBase::shared_ptr>& args,
bool nodispatch ) const;
DispatchInterface* produce(const std::vector<ORO_CoreLib::DataSourceBase::shared_ptr>& args
) const;
};
}

Expand Down
15 changes: 4 additions & 11 deletions packages/execution/program_parser/current/include/TaskBrowser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#define ORO_TASKBROWSER_HPP


#include "MethodFactoryInterface.hpp"
#include "DataSourceFactoryInterface.hpp"
#include "CommandFactoryInterface.hpp"
#include "OperationInterface.hpp"
#include "DispatchInterface.hpp"
#include <deque>
#include <string>
Expand Down Expand Up @@ -71,9 +69,6 @@ namespace ORO_Execution
ORO_CoreLib::ConditionInterface* condition;
DispatchInterface* command;
ORO_CoreLib::DataSource<bool>::shared_ptr accepted;
const CommandFactoryInterface* command_fact;
const DataSourceFactoryInterface* datasource_fact;
const MethodFactoryInterface* method_fact;

int debug;
/* A static variable for holding the line. */
Expand Down Expand Up @@ -109,11 +104,9 @@ namespace ORO_Execution

static void find_completes();

static void find_command(std::string::size_type startpos);
static void find_ops(std::string::size_type startpos);
static void find_peers(std::string::size_type startpos);

static void find_datasource(std::string::size_type startpos);

static void find_method(std::string::size_type startpos);

static void find_attribute(std::string::size_type startpos);
Expand Down Expand Up @@ -182,7 +175,7 @@ namespace ORO_Execution
/**
* Print the synopsis of a command.
*/
void printCommand( const std::string c );
void printCommand( const std::string c, OperationInterface* ops );

/**
* Print the synopsis of a DataSource.
Expand All @@ -192,7 +185,7 @@ namespace ORO_Execution
/**
* Print the synopsis of a Method.
*/
void printMethod( const std::string m );
void printMethod( const std::string m, OperationInterface* ops );

/**
* Print a program listing of a loaded program centered at line \a line.
Expand Down
115 changes: 38 additions & 77 deletions packages/execution/program_parser/current/src/CommandParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include "corelib/CommandDataSource.hpp"
#include "corelib/ConditionTrue.hpp"
#include "corelib/ConditionOnce.hpp"
#include "execution/GlobalCommandFactory.hpp"
#include "execution/CommandFactoryInterface.hpp"

#include "execution/AsynchCommandDecorator.hpp"

Expand Down Expand Up @@ -124,33 +122,23 @@ namespace ORO_Execution
peer = peerparser.peer();
peerparser.reset();

const GlobalCommandFactory* gcf =
peer->commands();
const GlobalMethodFactory* gmf =
peer->methods();
const GlobalDataSourceFactory* gdf =
peer->datasources();
const CommandFactoryInterface* cfi = gcf->getObjectFactory( mcurobject );
const MethodFactoryInterface* mfi = gmf->getObjectFactory( mcurobject );
const DataSourceFactoryInterface* dfi = gdf->getObjectFactory( mcurobject );

// In case the object is not found :
if ( ! cfi && ! mfi && ! dfi) {
if ( mcurobject == "this" )
mcurobject = mcurmethod;
else
mcurobject = mcurobject + "." + mcurmethod;
throw parse_exception_no_such_component( peer->getName(), mcurobject );
}

// In case the method/command is not found :
if ( !( ( cfi && cfi->hasCommand(mcurmethod)) || ( mfi && mfi->hasMember(mcurmethod)) || ( dfi && dfi->hasMember(mcurmethod)) ) )
throw parse_exception_no_such_method_on_component( mcurobject, mcurmethod );
OperationInterface* obj = 0;
if (mcurobject != "this")
if ( (obj = peer->getObject(mcurobject)) == 0 )
throw parse_exception_no_such_component( peer->getName(), mcurobject+"."+mcurmethod );
else {
if ( obj->methods()->hasMember(mcurmethod) == false && obj->commands()->hasMember(mcurmethod) == false)
throw parse_exception_no_such_method_on_component( mcurobject, mcurmethod );
}
else {
if ( peer->methods()->hasMember(mcurmethod) == false && peer->commands()->hasMember(mcurmethod) == false)
throw parse_exception_no_such_method_on_component( peer->getName(), mcurmethod );
}

// we found it !
argsparser = new ArgumentsParser( expressionparser, peer,
// ok object and method are found.
argsparser = new ArgumentsParser( expressionparser, peer,
mcurobject, mcurmethod );
arguments = argsparser->parser();
arguments = argsparser->parser();
}

void CommandParser::seencallcommand()
Expand All @@ -161,62 +149,37 @@ namespace ORO_Execution
mcurobject = argsparser->objectname();
mcurmethod = argsparser->methodname();

const GlobalCommandFactory* gcf =
peer->commands();
const GlobalMethodFactory* gmf =
peer->methods();
const GlobalDataSourceFactory* gdf =
peer->datasources();
const CommandFactoryInterface* cfi = gcf->getObjectFactory( mcurobject );
const MethodFactoryInterface* mfi = gmf->getObjectFactory( mcurobject );
const DataSourceFactoryInterface* dfi = gdf->getObjectFactory( mcurobject );

// cfi should exist, because otherwise we would have noticed in
// seenstartofcall()...
assert( cfi || mfi || dfi);
OperationInterface* obj = 0;
CommandRepository::Factory* cfi = 0;
MethodRepository::Factory* mfi = 0;
if ( mcurobject != "this" ) {
obj = peer->getObject(mcurobject);
assert(obj);
mfi = obj->methods();
cfi = obj->commands();
} else {
mfi = peer->methods();
cfi = peer->commands();
}
assert(mfi);
assert(cfi);

ComCon comcon;
if ( cfi && cfi->hasCommand( mcurmethod ) )
if ( cfi->hasMember( mcurmethod ) )
try
{
// check if dispatching is required:
// This check is done, here but we always dispatch anyway,
// to allow CommandProcessor policies to be in effect.
if ( peer->engine()->commands() != context->engine()->commands() || mdispatch ) {
// different, dispatch:
comcon = cfi->create( mcurmethod, argsparser->result(), false );
dcom = dynamic_cast<DispatchInterface*>( comcon.first );
assert( dcom );
dcom = cfi->produce( mcurmethod, argsparser->result() );// ,false );
} else {
// within same execution engine, no dispatch:
comcon = cfi->create( mcurmethod, argsparser->result(), true );
dcom = cfi->produce( mcurmethod, argsparser->result() );//, true );
}

}
catch( const wrong_number_of_args_exception& e )
{
throw parse_exception_wrong_number_of_arguments
(mcurobject, mcurmethod, e.wanted, e.received );
}
catch( const wrong_types_of_args_exception& e )
{
throw parse_exception_wrong_type_of_argument
( mcurobject, mcurmethod, e.whicharg, e.expected_, e.received_ );
}
catch( ... )
{
assert( false );
}
else if ( mfi && mfi->hasMember( mcurmethod ) )
try
{
// if the method returns a boolean, construct it as a command
// which accepts/rejects the result.
DataSourceBase* dsb = mfi->create( mcurmethod, argsparser->result() );
DataSource<bool>* dsb_res = DataSource<bool>::narrow( dsb );
if ( dsb_res == 0 )
comcon.first = new CommandDataSource( dsb );
else
comcon.first = new CommandDataSourceBool( dsb_res );
comcon.second = new ConditionTrue();
comcon.first = dcom;
comcon.second = dcom->createCondition();
}
catch( const wrong_number_of_args_exception& e )
{
Expand All @@ -232,12 +195,12 @@ namespace ORO_Execution
{
assert( false );
}
else if ( dfi && dfi->hasMember( mcurmethod ) )
else if ( mfi->hasMember( mcurmethod ) )
try
{
// if the method returns a boolean, construct it as a command
// which accepts/rejects the result.
DataSourceBase* dsb = dfi->create( mcurmethod, argsparser->result() );
DataSourceBase* dsb = mfi->produce( mcurmethod, argsparser->result() );
DataSource<bool>* dsb_res = DataSource<bool>::narrow( dsb );
if ( dsb_res == 0 )
comcon.first = new CommandDataSource( dsb );
Expand All @@ -259,8 +222,6 @@ namespace ORO_Execution
{
assert( false );
}
else
assert(false);

mcurobject.clear();
mcurmethod.clear();
Expand Down
Loading

0 comments on commit 469e4c7

Please sign in to comment.