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 mfoundpath = true;
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), mfoundpath(false), 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 mfoundpath = false;
00158 while( !callqueue.empty() )
00159 callqueue.pop();
00160 }
00161
00162 void PeerParser::seenobjectname( iter_t begin, iter_t end )
00163 {
00164 std::string name( begin, end );
00165 name.erase( name.length() -1 );
00166 callqueue.push( name );
00167
00168 }
00169
00170 void PeerParser::locatepeer( iter_t begin, iter_t end )
00171 {
00172 std::string name( begin, end );
00173 name.erase( name.length() -1 );
00174
00175 if ( mcurobject == _peer->provides() && _peer->hasPeer( name ) ) {
00176 _peer = _peer->getPeer( name );
00177 if ( _peer->ready() == false ) {
00178 throw parse_exception_semantic_error
00179 ("Attempt to use TaskContext "+name+" which is not ready to use." );
00180 }
00181 mcurobject = _peer->provides();
00182 advance_on_error += end.base() - begin.base();
00183
00184
00185 }
00186 else if ( mcurobject->hasService(name) ) {
00187 mcurobject = mcurobject->provides(name);
00188 advance_on_error += end.base() - begin.base();
00189 }
00190
00191 else if (mcurobject == _peer->provides() && GlobalService::Instance()->hasService(name) ) {
00192 mcurobject = GlobalService::Instance()->provides(name);
00193 advance_on_error += end.base() - begin.base();
00194 mfoundpath = true;
00195 } else {
00196 if ( name == "states" || name == "programs") {
00197 log(Warning) << "'"<<name<<"' peer not found. The use of '"<<name<<"' has been deprecated."<<endlog();
00198 log(Warning) << "Modify your script to use the program's or state machine's name directly."<<endlog();
00199 advance_on_error += end.base() - begin.base();
00200 return;
00201 }
00202
00203
00204
00205
00206 mlastobject = name;
00207 if (mfullpath) {
00208 mcurobject.reset();
00209 mfoundpath = false;
00210 }
00211 throw_(begin, peer_not_found );
00212 }
00213 }
00214
00215 rule_t& PeerParser::parser()
00216 {
00217 return peerpath;
00218 }
00219
00220 rule_t& PeerParser::locator()
00221 {
00222 return peerlocator;
00223 }
00224
00225 TaskContext* PeerParser::peer()
00226 {
00227 return _peer;
00228 }
00229
00230 Service::shared_ptr PeerParser::taskObject()
00231 {
00232 return mcurobject;
00233 }
00234
00235 std::string PeerParser::object()
00236 {
00237 return mlastobject;
00238 }
00239
00240 bool PeerParser::foundPath()
00241 {
00242 return mfoundpath;
00243 }
00244 }
00245