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;
44 using namespace rsc::runtime;
45 using namespace rsc::logging;
46 using namespace rsc::threading;
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());
81 MutexType::scoped_lock lock(this->inprogressMutex);
83 request->setScopePtr(getInformer()->
getScope());
84 request->setMethod(
"REQUEST");
85 getInformer()->publish(request);
87 this->inprogress.insert(std::make_pair(request->getEventId(), result));
94 if (!event || event->getCauses().empty()) {
95 RSCTRACE(
logger,
"Received uninteresting event " << event);
99 EventId requestId = *
event->getCauses().begin();
102 MutexType::scoped_lock lock(this->inprogressMutex);
103 map<EventId, FuturePtr>::const_iterator it
104 = this->inprogress.find(requestId);
105 if (it != this->inprogress.end()) {
107 this->inprogress.erase(requestId);
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";
156 if (!this->
methods.count(name)) {
174 RSCDEBUG(this->
logger,
"Calling method " << methodName <<
" with request " << request);
177 return getMethod(methodName)->call(methodName, request);
182 unsigned int maxReplyWaitTime) {
183 return callAsync(methodName, request)->get(maxReplyWaitTime);
ParticipantConfig listenerConfig
std::map< std::string, RemoteMethodPtr > methods
boost::shared_ptr< RemoteMethod > RemoteMethodPtr
FuturePtr call(const std::string &methodName, EventPtr request)
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...
boost::shared_ptr< Filter > FilterPtr
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.
virtual ListenerPtr makeListener()
Creates and returns the Listener participant.
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
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...