39 #ifndef ORO_FUSEDFUNCTORDATASOURCE_HPP_ 40 #define ORO_FUSEDFUNCTORDATASOURCE_HPP_ 44 #include "../SendStatus.hpp" 46 #include "../ExecutionEngine.hpp" 47 #include "../os/oro_allocator.hpp" 49 #include <boost/bind.hpp> 50 #include <boost/type_traits.hpp> 51 #include <boost/function.hpp> 52 #include <boost/function_types/function_type.hpp> 53 #include <boost/fusion/include/invoke.hpp> 54 #include <boost/fusion/include/invoke_procedure.hpp> 55 #include <boost/mpl/bool.hpp> 56 #include <boost/make_shared.hpp> 65 namespace bf = boost::fusion;
72 template<
typename Signature,
class Enable=
void>
75 typename remove_cr<typename boost::function_traits<Signature>::result_type>::type >
78 typedef typename boost::function_traits<Signature>::result_type
83 typename boost::function_types::parameter_types<Signature>::type>
SequenceFactory;
87 boost::function<Signature>
ff;
91 typedef boost::intrusive_ptr<FusedFunctorDataSource<Signature> >
96 const DataSourceSequence& s = DataSourceSequence() ) :
120 typedef typename bf::result_of::invoke<call_type,arg_type>::type iret;
121 typedef iret(*IType)(call_type, arg_type
const&);
122 IType foo = &bf::invoke<call_type,arg_type>;
123 ret.
exec( boost::bind(foo, boost::ref(ff), SequenceFactory::data(args)));
124 SequenceFactory::update(args);
147 template<
typename Signature>
148 struct FusedFunctorDataSource<Signature, typename
boost::enable_if< is_pure_reference<typename boost::function_traits<Signature>::result_type> >::type >
150 typename remove_cr<typename boost::function_traits<Signature>::result_type>::type >
153 typedef typename boost::function_traits<Signature>::result_type
163 boost::function<Signature>
ff;
167 typedef boost::intrusive_ptr<FusedFunctorDataSource<Signature> >
172 const DataSourceSequence& s = DataSourceSequence() ) :
196 typedef typename bf::result_of::invoke<call_type,arg_type>::type iret;
197 typedef iret(*IType)(call_type, arg_type
const&);
198 IType foo = &bf::invoke<call_type,arg_type>;
199 ret.
exec( boost::bind(foo, boost::ref(ff), SequenceFactory::data(args)));
200 SequenceFactory::update(args);
211 get(); ret.
result() = arg;
215 get();
return ret.
result();
240 template<
class Function>
243 typedef typename boost::function_types::function_type<Function>::type Signature;
245 if ( args.size() != boost::function_traits<Signature>::arity )
255 template<
typename Signature>
258 typename remove_cr<typename boost::function_traits<Signature>::result_type>::type >
260 typedef typename boost::function_traits<Signature>::result_type
271 typedef boost::intrusive_ptr<FusedMCallDataSource<Signature> >
275 const DataSourceSequence& s = DataSourceSequence() ) :
301 typedef typename bf::result_of::invoke<call_type,arg_type>::type iret;
302 typedef iret(*IType)(call_type, arg_type
const&);
303 IType foo = &bf::invoke<call_type,arg_type>;
310 SequenceFactory::update(args);
337 template<
typename Signature>
354 typedef boost::intrusive_ptr<FusedMSendDataSource<Signature> >
358 const DataSourceSequence& s = DataSourceSequence() ) :
359 ff(g), args(s), sh(), isqueued(false)
368 virtual void set( param_t t ) {
412 if ( alreadyCloned[
this] != 0 ) {
429 template<
typename Signature>
438 typedef typename boost::function_types::parameter_types<CollectSignature>::type
arg_types;
447 typedef boost::intrusive_ptr<FusedMCollectDataSource<Signature> >
474 if (isblocking->
get())
478 SequenceFactory::update(args);
494 if ( alreadyCloned[
this] != 0 ) {
513 template<
typename Signature>
516 typedef typename boost::function_traits<Signature>::result_type
522 boost::shared_ptr<base::ActionInterface>
mact;
533 boost::shared_ptr<FusedMSignal<Signature> >
self;
535 typedef boost::shared_ptr<FusedMSignal<Signature> >
shared_ptr;
545 const DataSourceSequence& s,
547 mact(act), args(s), subscriber(subscr), self()
562 shared_ptr sg = this->cloneRT();
563 sg->arg_cache = SequenceFactory::store(seq);
565 if ( subscriber->
process( sg.get() ) ) {
572 SequenceFactory::set( seq, args );
580 SequenceFactory::load( this->arg_cache, this->args );
boost::function_traits< Signature >::result_type result_type
DataSource is a base class representing a generic way to read data of type T.
bf::cons< arg_store_type, arg_store_tail_type > data_store_type
The joint T data storage type of head and tail.
boost::intrusive_ptr< FusedFunctorDataSource< Signature > > shared_ptr
value_t value() const
Return the result of the last evaluate() function.
boost::function_traits< Signature >::result_type result_type
virtual result_t get() const =0
Return the data as type T.
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
SequenceFactory::type DataSourceSequence
FusedMSignal< Signature >::shared_ptr cloneRT() const
bool evaluate() const
Force an evaluation of the DataSourceBase.
SequenceFactory::type DataSourceSequence
SequenceFactory::type DataSourceSequence
void executeAndDispose()
Execute functionality and free this object.
const_reference_t rvalue() const
Get a const reference to the value of this DataSource.
boost::function< Signature > call_type
ExecutionEngine * subscriber
virtual FusedMCallDataSource< Signature > * clone() const
Return a shallow clone of this DataSource.
DataSource< bool >::shared_ptr isblocking
The base class for all internal data representations.
This class can create three kinds of Boost Fusion Sequences.
remove_cr< result_type >::type value_t
SequenceFactory::atype DataSourceSequence
value_t value() const
Return the result of the last evaluate() function.
SequenceFactory::data_store_type arg_cache
void exec(F f)
Stores the result of a function.
remove_cr< result_type >::type value_t
void setArguments(const DataSourceSequence &a1)
void reset()
Reset the data to initial values.
base::DataSourceBase * newFunctorDataSource(Function f, const std::vector< base::DataSourceBase::shared_ptr > &args)
Creates a data source that returns the result of a given function.
FusedMSendDataSource(typename base::OperationCallerBase< Signature >::shared_ptr g, const DataSourceSequence &s=DataSourceSequence())
value_t value() const
Return the result of the last evaluate() function.
A real-time malloc allocator which allocates every block with oro_rt_malloc() and deallocates with or...
virtual FusedMSendDataSource< Signature > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
Create a deep copy of this internal::DataSource, unless it is already cloned.
A DataSource that collects the result of an asynchronous method which store its results in other data...
remove_cr< result_type >::type value_t
value_t value() const
Return the result of the last evaluate() function.
boost::intrusive_ptr< FusedMSendDataSource< Signature > > shared_ptr
SequenceFactory::data_type arg_type
bool evaluate() const
Force an evaluation of the DataSourceBase.
DataSource< value_t >::const_reference_t const_reference_t
boost::function_traits< Signature >::result_type result_type
void reportError()
Executed when the operation execution resulted in a C++ exception.
The base class for all method implementations.
SendHandle< Signature > sh
virtual FusedFunctorDataSource< Signature > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
Create a deep copy of this internal::DataSource, unless it is already cloned.
FusedFunctorDataSource(Func g, const DataSourceSequence &s=DataSourceSequence())
void setArguments(const DataSourceSequence &a1)
CollectType< Signature >::type CollectSignature
An execution engine serialises (executes one after the other) the execution of all commands...
SendStatus
Returns the status of a send() or collect() invocation.
AssignableDataSource< value_t >::reference_t reference_t
DataSource< value_t >::const_reference_t const_reference_t
RStore< result_type > ret
DataSource< value_t >::const_reference_t const_reference_t
A DataSource that calls a method which gets its arguments from other data sources.
RStore< result_type > ret
boost::intrusive_ptr< FusedFunctorDataSource< Signature > > shared_ptr
boost::function< Signature > call_type
SequenceFactory::type DataSourceSequence
boost::shared_ptr< OperationCallerBase< F > > shared_ptr
boost::intrusive_ptr< FusedMCollectDataSource< Signature > > shared_ptr
value_t value() const
Return the result of the last evaluate() function.
void setArguments(const DataSourceSequence &a1)
The SendHandle is used to collect the result values of an asynchronous invocation.
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
virtual FusedFunctorDataSource< Signature > * clone() const
Return a shallow clone of this DataSource.
RStore< result_type > ret
FusedMCallDataSource(typename base::OperationCallerBase< Signature >::shared_ptr g, const DataSourceSequence &s=DataSourceSequence())
Returned when the result of the send() could not be collected.
SequenceFactory::data_type arg_type
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
FusedMCollectDataSource(const DataSourceSequence &s, DataSource< bool >::shared_ptr blocking)
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
Based on the software pattern 'command', this interface allows execution of action objects...
base::OperationCallerBase< Signature >::shared_ptr ff
boost::intrusive_ptr< FusedMCallDataSource< Signature > > shared_ptr
SequenceFactory::type DataSourceSequence
result_type invoke(const typename SequenceFactory::data_type &seq) const
A Fused function that takes the arguments of the signal, puts them into the assignable data sources a...
const_reference_t rvalue() const
Get a const reference to the value of this DataSource.
virtual FusedMCollectDataSource< Signature > * clone() const
Return a shallow clone of this DataSource.
const_reference_t rvalue() const
Get a const reference to the value of this DataSource.
boost::function< Signature > ff
This class is used to return a 'default' value when no value is available ('Not Available').
bf::cons< arg_type, arg_tail_type > data_type
The joint T data type of head and tail.
An object that is executable and is freed after execution.
base::OperationCallerBase< Signature >::shared_ptr ff
AssignableDataSource< value_t >::const_reference_t const_reference_t
virtual FusedMSendDataSource< Signature > * clone() const
Return a shallow clone of this DataSource.
DataSource< SendStatus >::const_reference_t const_reference_t
AssignableDataSource< value_t >::param_t param_t
const_reference_t rvalue() const
Get a const reference to the value of this DataSource.
FusedMSignal(base::ActionInterface *act, const DataSourceSequence &s, ExecutionEngine *subscr)
Create a new object which takes ownership of the action to be executed upon signal.
boost::function_types::parameter_types< CollectSignature >::type arg_types
const_reference_t rvalue() const
Get a const reference to the value of this DataSource.
bf::cons< ds_type, tail_type > type
The joint DataSource<T>::shared_ptr type of head and tail, again a fusion cons.
A DataSource which has set() methods.
void setArguments(const DataSourceSequence &a1)
void setArguments(const DataSourceSequence &a1)
void dispose()
As long as dispose (or executeAndDispose() ) is not called, this object will not be destroyed...
boost::function_traits< Signature >::result_type result_type
void setArguments(const DataSourceSequence &a1)
boost::remove_const< typename boost::remove_reference< T >::type >::type type
Exception thrown when a factory is requested to create an object but the wrong number of arguments wa...
virtual FusedMCollectDataSource< Signature > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
Create a deep copy of this internal::DataSource, unless it is already cloned.
boost::function< Signature > ff
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
SendHandle< Signature > result_type
virtual bool process(base::DisposableInterface *c)
Queue and execute (process) a given message.
bool evaluate() const
Force an evaluation of the DataSourceBase.
mpl::push_front< arg_types, SendHandle< Signature > & >::type handle_and_arg_types
virtual FusedFunctorDataSource< Signature > * clone() const
Return a shallow clone of this DataSource.
virtual FusedFunctorDataSource< Signature > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
Create a deep copy of this internal::DataSource, unless it is already cloned.
details::GetConstRef< T >::type const_reference_t
create_sequence< typename boost::function_types::parameter_types< Signature >::type > SequenceFactory
A Function object that reacts to a Signal by writing the arguments in data sources and calling an act...
FusedFunctorDataSource(Func g, const DataSourceSequence &s=DataSourceSequence())
bool ready() const
Inspect if this SendHandle is pointing to valid (existing) invocation.
create_sequence< handle_and_arg_types > SequenceFactory
bf::cons< ads_type, atail_type > atype
boost::shared_ptr< base::ActionInterface > mact
A DataSource that sends a method which gets its arguments from other data sources.
AssignableDataSource< value_t >::reference_t reference_t
virtual FusedMCallDataSource< Signature > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
Create a deep copy of this internal::DataSource, unless it is already cloned.
boost::shared_ptr< FusedMSignal< Signature > > shared_ptr
A DataSource that calls a functor of signature Signature which gets its arguments from other data sou...