Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "PeerParser.hpp"
00041 #include "parser-debug.hpp"
00042 #include "parse_exception.hpp"
00043 #include "../TaskContext.hpp"
00044 #include "parser-types.hpp"
00045 #include "../internal/GlobalService.hpp"
00046
00047 #include <boost/bind.hpp>
00048 #include <boost/iterator/iterator_traits.hpp>
00049
00050 namespace RTT
00051 {
00052 using boost::bind;
00053 using namespace detail;
00054 using namespace std;
00055 using namespace boost;
00056
00057 error_status<> PeerParser::handle_no_peer(scanner_t const& scan, parser_error<PeerErrors, iter_t>&e )
00058 {
00059 int length = advance_on_error;
00060
00061 while (advance_on_error != 0) {
00062 ++scan;
00063 --advance_on_error;
00064 }
00065
00066
00067 return error_status<>( error_status<>::accept, length );
00068 }
00069
00070 void PeerParser::done()
00071 {
00072
00073 mlastobject = "this";
00074
00075
00076
00077 while ( callqueue.size() > 0 && _peer->hasPeer( callqueue.front() ) ) {
00078
00079 _peer = _peer->getPeer( callqueue.front() );
00080
00081 if ( _peer->ready() == false ) {
00082 throw parse_exception_semantic_error
00083 ("Attempt to use TaskContext "+ callqueue.front() +" which is not ready to use." );
00084 }
00085
00086 callqueue.pop();
00087 }
00088
00089
00090 if ( !callqueue.empty() ) {
00091 std::string name = callqueue.front();
00092 if ( (name == "states" || name == "programs") && _peer->provides()->hasService(name) == 0) {
00093 log(Warning) << "'"<<name<<"' peer not found. The use of '"<<name<<"' has been deprecated."<<endlog();
00094 log(Warning) << "Modify your script to use the program's or state machine's name directly."<<endlog();
00095 callqueue.pop();
00096 }
00097 }
00098
00099 mcurobject = _peer->provides();
00100
00101
00102 while ( callqueue.size() > 0 && mcurobject->hasService( callqueue.front() ) ) {
00103
00104 mcurobject = mcurobject->provides( callqueue.front() );
00105 mlastobject = callqueue.front();
00106 callqueue.pop();
00107 }
00108
00109
00110 if (mcurobject == context->provides() && callqueue.size() != 0 ) {
00111 mcurobject = GlobalService::Instance();
00112 while ( callqueue.size() && mcurobject->hasService( callqueue.front() ) ) {
00113 mcurobject = mcurobject->provides( callqueue.front() );
00114 mlastobject = callqueue.front();
00115 callqueue.pop();
00116 }
00117 }
00118
00119
00120 if ( mfullpath && callqueue.size() != 0 ) {
00121
00122 string object = callqueue.front();
00123 while ( !callqueue.empty() )
00124 callqueue.pop();
00125 iter_t begin;
00126 if ( _peer->provides() == mcurobject )
00127 throw_(begin, "From TaskContext '"+context->getName()+"': Task '"+ _peer->getName()+"' has no child Service '"+object+"'." );
00128 else
00129 throw_(begin, "From TaskContext '"+context->getName()+"': Service '"+ mcurobject->getName()+"' has no child Service '"+object+"'." );
00130 }
00131
00132 }
00133
00134 PeerParser::PeerParser(TaskContext* c, CommonParser& cp, bool fullpath)
00135 : commonparser(cp), mcurobject(c->provides()), mlastobject("this"), context(c), _peer(context), mfullpath(fullpath), advance_on_error(0)
00136 {
00137 BOOST_SPIRIT_DEBUG_RULE( my_guard );
00138 BOOST_SPIRIT_DEBUG_RULE( peerpath );
00139 BOOST_SPIRIT_DEBUG_RULE( peerlocator );
00140 peerpath =
00141 ( +(commonparser.notassertingidentifier >> ".")[boost::bind( &PeerParser::seenobjectname, this, _1, _2 ) ] )[boost::bind(&PeerParser::done, this)];
00142
00143
00144
00145 peerlocator =
00146 my_guard( *((commonparser.notassertingidentifier >> ".")[boost::bind( &PeerParser::locatepeer, this, _1, _2 ) ]))
00147 [ boost::bind(&PeerParser::handle_no_peer, this, _1, _2) ]
00148 ;
00149 }
00150
00151 void PeerParser::reset()
00152 {
00153 _peer = context;
00154 mcurobject = context->provides();
00155 mlastobject = "this";
00156 advance_on_error = 0;
00157 while( !callqueue.empty() )
00158 callqueue.pop();
00159 }
00160
00161 void PeerParser::seenobjectname( iter_t begin, iter_t end )
00162 {
00163 std::string name( begin, end );
00164 name.erase( name.length() -1 );
00165 callqueue.push( name );
00166
00167 }
00168
00169 void PeerParser::locatepeer( iter_t begin, iter_t end )
00170 {
00171 std::string name( begin, end );
00172 name.erase( name.length() -1 );
00173
00174 if ( mcurobject == _peer->provides() && _peer->hasPeer( name ) ) {
00175 _peer = _peer->getPeer( name );
00176 if ( _peer->ready() == false ) {
00177 throw parse_exception_semantic_error
00178 ("Attempt to use TaskContext "+name+" which is not ready to use." );
00179 }
00180 mcurobject = _peer->provides();
00181 advance_on_error += end.base() - begin.base();
00182
00183
00184 }
00185 else if ( mcurobject->hasService(name) ) {
00186 mcurobject = mcurobject->provides(name);
00187 advance_on_error += end.base() - begin.base();
00188 }
00189
00190 else if (mcurobject == _peer->provides() && GlobalService::Instance()->hasService(name) ) {
00191 mcurobject = GlobalService::Instance()->provides(name);
00192 advance_on_error += end.base() - begin.base();
00193 } else {
00194 if ( name == "states" || name == "programs") {
00195 log(Warning) << "'"<<name<<"' peer not found. The use of '"<<name<<"' has been deprecated."<<endlog();
00196 log(Warning) << "Modify your script to use the program's or state machine's name directly."<<endlog();
00197 advance_on_error += end.base() - begin.base();
00198 return;
00199 }
00200
00201
00202
00203
00204 mlastobject = name;
00205 if (mfullpath)
00206 mcurobject.reset();
00207 throw_(begin, peer_not_found );
00208 }
00209 }
00210
00211 rule_t& PeerParser::parser()
00212 {
00213 return peerpath;
00214 }
00215
00216 rule_t& PeerParser::locator()
00217 {
00218 return peerlocator;
00219 }
00220
00221 TaskContext* PeerParser::peer()
00222 {
00223 return _peer;
00224 }
00225
00226 Service::shared_ptr PeerParser::taskObject()
00227 {
00228 return mcurobject;
00229 }
00230
00231 std::string PeerParser::object()
00232 {
00233 return mlastobject;
00234 }
00235
00236 }
00237