30 #include <boost/format.hpp> 32 #include <rsc/misc/UUID.h> 34 #include "../EventId.h" 35 #include "../MetaData.h" 36 #include "../Factory.h" 38 #include "../filter/MethodFilter.h" 42 using namespace boost;
53 RemoteServer::RemoteMethod::RemoteMethod(
const Scope& scope,
54 const std::string& name,
57 :
Method(scope, name, listenerConfig, informerConfig),
58 logger(Logger::getLogger(
boost::str(
boost::format(
"rsb.patterns.RemoteMethod[%1%]")
66 return "remote-method";
72 listener->addHandler(shared_from_this());
84 request->setMethod(
"REQUEST");
87 this->
inprogress.insert(std::make_pair(request->getId(), result));
94 if (!event || event->getCauses().empty()) {
95 RSCTRACE(
logger,
"Received uninteresting event " << event);
99 EventId requestId = *
event->getCauses().begin();
103 map<EventId, FuturePtr>::const_iterator it
112 RSCTRACE(this->
logger,
"Received uninteresting event " << event);
115 RSCDEBUG(this->
logger,
"Received reply event " << event);
117 if (event->mutableMetaData().hasUserInfo(
"rsb:error?")) {
118 assert(event->getType() == typeName<std::string>());
119 result->setError(boost::str(boost::format(
"Error calling remote method '%1%': %2%")
120 %
"TODO: obtain method name" 121 % *(boost::static_pointer_cast<string>(event->getData()))));
133 logger(Logger::getLogger(str(format(
"rsb.patterns.RemoteServer[%1%]")
134 % scope.toString()))),
135 listenerConfig(listenerConfig), informerConfig(informerConfig) {
142 for (std::map<std::string, RemoteMethodPtr>::iterator it
144 it->second->deactivate();
149 return "remote-server";
153 return std::set<std::string>();
178 RSCDEBUG(this->
logger,
"Calling method " << methodName <<
" with request " << request);
181 return getMethod(methodName)->call(methodName, request);
186 unsigned int maxReplyWaitTime) {
187 return callAsync(methodName, request)->get(maxReplyWaitTime);
virtual const std::set< std::string > getTransportURLs() const
TODO.
ParticipantConfig listenerConfig
std::map< std::string, RemoteMethodPtr > methods
boost::shared_ptr< RemoteMethod > RemoteMethodPtr
FuturePtr call(const std::string &methodName, EventPtr request)
std::map< EventId, FuturePtr > inprogress
RemoteMethodPtr getMethod(const std::string &name)
Objects of this class participate in the exchange of notifications on one channel of the bus...
RemoteServer(const Scope &scope, const ParticipantConfig &listenerConfig, const ParticipantConfig &informerConfig)
Construct a new RemoteServer object which can be used to call methods of the server at scope...
rsc::logging::LoggerPtr logger
boost::shared_ptr< Filter > FilterPtr
ParticipantConfig listenerConfig
Factory & getFactory()
Returns a factory for client-level RSB objects.
This filter matches events based on the value of their method field.
void handle(EventPtr event)
Handle event.
boost::shared_ptr< Listener > ListenerPtr
virtual std::string getKind() const
Return the kind of the participant.
InformerBasePtr getInformer()
Returns the Informer participant, creating it if necessary.
virtual ListenerPtr makeListener()
Creates and returns the Listener participant.
MutexType inprogressMutex
Base class for method classes.
patterns::RemoteServer::RemoteMethodPtr createRemoteMethod(const Scope &scope, const ParticipantConfig &listenerConfig=getFactory().getDefaultParticipantConfig(), const ParticipantConfig &informerConfig=getFactory().getDefaultParticipantConfig(), ParticipantPtr parent=ParticipantPtr())
Creates a patterns::RemoteServer::RemoteMethod.
virtual std::string getKind() const
Return the kind of the participant.
boost::mutex methodsMutex
ParticipantConfig informerConfig
ParticipantConfig informerConfig
A class describing the configuration of Participant instances.
EventPtr call(const std::string &methodName, EventPtr data, unsigned int maxReplyWaitTime=25)
Call the method named methodName on the remote server, passing it the event data as argument and retu...
A unique ID for events in RSB.
ScopePtr getScope() const
Returns the scope of this participant.
rsc::logging::LoggerPtr logger
boost::shared_ptr< Event > EventPtr
boost::shared_ptr< FutureType > FuturePtr
ListenerPtr makeListener()
Creates and returns the Listener participant.
Scope is a descriptor for a hierarchical channel of the unified bus.
FuturePtr callAsync(const std::string &methodName, EventPtr data)
Call the method named methodName on the remote server, passing it the event data as argument and retu...