43 #include "../TaskContext.hpp" 45 #include "../internal/GlobalService.hpp" 47 #include <boost/bind.hpp> 48 #include <boost/iterator/iterator_traits.hpp> 53 using namespace detail;
55 using namespace boost;
57 error_status<> PeerParser::handle_no_peer(
scanner_t const& scan, parser_error<PeerErrors, iter_t>&e )
59 int length = advance_on_error;
61 while (advance_on_error != 0) {
67 return error_status<>( error_status<>::accept, length );
70 void PeerParser::done()
77 while ( callqueue.size() > 0 && _peer->hasPeer( callqueue.front() ) ) {
79 _peer = _peer->getPeer( callqueue.front() );
81 if ( _peer->ready() == false ) {
82 throw parse_exception_semantic_error
83 (
"Attempt to use TaskContext "+ callqueue.front() +
" which is not ready to use." );
90 if ( !callqueue.empty() ) {
91 std::string name = callqueue.front();
92 if ( (name ==
"states" || name ==
"programs") && _peer->provides()->hasService(name) == 0) {
93 log(
Warning) <<
"'"<<name<<
"' peer not found. The use of '"<<name<<
"' has been deprecated."<<endlog();
94 log(
Warning) <<
"Modify your script to use the program's or state machine's name directly."<<endlog();
99 mcurobject = _peer->provides();
102 while ( callqueue.size() > 0 && mcurobject->hasService( callqueue.front() ) ) {
104 mcurobject = mcurobject->provides( callqueue.front() );
105 mlastobject = callqueue.front();
110 if (mcurobject == context->provides() && callqueue.size() != 0 ) {
112 while ( callqueue.size() && mcurobject->hasService( callqueue.front() ) ) {
113 mcurobject = mcurobject->provides( callqueue.front() );
114 mlastobject = callqueue.front();
120 if ( mfullpath && callqueue.size() != 0 ) {
122 string object = callqueue.front();
123 while ( !callqueue.empty() )
126 if ( _peer->provides() == mcurobject )
127 throw_(begin,
"From TaskContext '"+context->getName()+
"': Task '"+ _peer->getName()+
"' has no child Service '"+
object+
"'." );
129 throw_(begin,
"From TaskContext '"+context->getName()+
"': Service '"+ mcurobject->getName()+
"' has no child Service '"+
object+
"'." );
135 : commonparser(cp), mcurobject(c->provides()), mlastobject(
"this"), context(c), _peer(context), mfullpath(fullpath), mfoundpath(false), advance_on_error(0)
137 BOOST_SPIRIT_DEBUG_RULE( my_guard );
138 BOOST_SPIRIT_DEBUG_RULE( peerpath );
139 BOOST_SPIRIT_DEBUG_RULE( peerlocator );
141 ( +(commonparser.
notassertingidentifier >>
".")[boost::bind( &PeerParser::seenobjectname,
this, _1, _2 ) ] )[boost::bind(&PeerParser::done,
this)];
146 my_guard( *((commonparser.
notassertingidentifier >>
".")[boost::bind( &PeerParser::locatepeer,
this, _1, _2 ) ]))
147 [ boost::bind(&PeerParser::handle_no_peer,
this, _1, _2) ]
155 mlastobject =
"this";
156 advance_on_error = 0;
158 while( !callqueue.empty() )
162 void PeerParser::seenobjectname(
iter_t begin,
iter_t end )
164 std::string name( begin, end );
165 name.erase( name.length() -1 );
166 callqueue.push( name );
172 std::string name( begin, end );
173 name.erase( name.length() -1 );
176 _peer = _peer->
getPeer( name );
177 if ( _peer->
ready() == false ) {
179 (
"Attempt to use TaskContext "+name+
" which is not ready to use." );
182 advance_on_error += end.base() - begin.base();
186 else if ( mcurobject->hasService(name) ) {
187 mcurobject = mcurobject->provides(name);
188 advance_on_error += end.base() - begin.base();
193 advance_on_error += end.base() - begin.base();
196 if ( name ==
"states" || name ==
"programs") {
197 log(
Warning) <<
"'"<<name<<
"' peer not found. The use of '"<<name<<
"' has been deprecated."<<endlog();
198 log(
Warning) <<
"Modify your script to use the program's or state machine's name directly."<<endlog();
199 advance_on_error += end.base() - begin.base();
211 throw_(begin, peer_not_found );
PeerParser(TaskContext *c, CommonParser &cp, bool fullpath=false)
Create a PeerParser which starts looking for peers from a task.
std::string object()
Returns the last matching object name.
Service::shared_ptr provides()
Returns this Service.
void reset()
After reset, peer() == current context and object() == "this".
parse_exception class that is used for various semantic errors for which it was not worth defining a ...
This class contains some very common parser definitions.
TaskContext * peer()
Returns the last matching peer.
virtual TaskContext * getPeer(const std::string &peer_name) const
Get a pointer to a peer of this task.
rule_t & locator()
The locator tries to go as far as possible in the peer-to-object path and will never throw...
boost::shared_ptr< Service > shared_ptr
virtual bool hasPeer(const std::string &peer_name) const
Return true if it knows a peer by that name.
scanner< iter_t, scanner_pol_t > scanner_t
ServicePtr taskObject()
Returns the last matching Service or zero if not found.
The TaskContext is the C++ representation of an Orocos component.
rule_t & parser()
The parser tries to traverse a full peer-to-object path and throws if it got stuck in the middle...
bool foundPath()
Returns true if the PeerParser found a valid path.
rule_t notassertingidentifier
identifier with <template> marks in it
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
static RTT_API Service::shared_ptr Instance()
virtual bool ready()
Checks the validity of this TaskContext.