32 #include <rsc/runtime/TypeStringTools.h>
33 #include <rsc/logging/Logger.h>
35 #include "../EventId.h"
36 #include "../Factory.h"
37 #include "../MetaData.h"
38 #include "../Handler.h"
43 using namespace rsc::runtime;
48 Server::IntlCallback::~IntlCallback() {
51 Server::CallbackBase::CallbackBase(
const string& requestType,
52 const string& replyType)
53 : requestType(requestType), replyType(replyType) {
57 return this->requestType;
61 return this->replyType;
77 logger(rsc::logging::Logger::getLogger(
"rsb.patterns.RequestHandler."
78 + methodName)), methodName(methodName), callback(callback),
83 return "RequestHandler";
87 stream <<
"methodName = " << methodName;
91 if (event->getMethod() !=
"REQUEST") {
94 if (event->getType() != callback->getRequestType()) {
95 RSCERROR(logger,
"Request type '" << event->getType()
96 <<
"' does not match expected request type '"
97 << callback->getRequestType() <<
"' of method '"
98 << methodName <<
"'");
103 reply->setScopePtr(informer->getScope());
104 reply->setMethod(
"REPLY");
105 reply->addCause(event->getEventId());
108 = callback->intlCall(methodName, event->getData());
109 reply->setType(returnData.first);
110 reply->setData(returnData.second);
111 }
catch (
const exception& e) {
112 reply->setType(typeName<string>());
113 reply->setData(boost::shared_ptr<string>(
new string(typeName(e) +
": " + e.what())));
114 reply->mutableMetaData().setUserInfo(
"rsb:error?",
"");
116 informer->publish(reply);
123 scope(scope), listenerConfig(listenerConfig), informerConfig(
133 if (
methods.count(methodName)) {
149 methods[methodName] = informer;
boost::shared_ptr< IntlCallback > CallbackPtr
std::map< std::string, Informer< AnyType >::Ptr > methods
std::pair< std::string, boost::shared_ptr< void > > AnnotatedData
A combination of data type and the actual data.
ParticipantConfig informerConfig
virtual const std::string & getRequestType() const
Indicates that a method of a Server already exists.
RequestHandler(const string &methodName, Server::CallbackPtr callback, Informer< AnyType >::Ptr informer)
void handle(EventPtr event)
Handle event.
Basic message that is exchanged between informers and listeners.
ParticipantConfig listenerConfig
Asynchronously called handler interface on the client level.
A tag type for constructing Informer instances that can publish data of arbitrary types...
const std::string & toString() const
Reconstructs a fully formal string representation of the scope with leading an trailing slashes...
void registerMethod(const std::string &methodName, CallbackPtr callback)
Register a new method with the given name.
virtual const std::string & getReplyType() const
Factory & getFactory()
Returns a factory for client-level RSB objects.
Informer< DataType >::Ptr createInformer(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig(), const std::string &dataType=detail::TypeName< DataType >()())
Creates and returns a new Informer that publishes Event s under the Scope scope.
boost::shared_ptr< Listener > ListenerPtr
Informer< AnyType >::Ptr informer
Server(const Scope &scope, const ParticipantConfig &listenerConfig, const ParticipantConfig &informerConfig)
void printContents(ostream &stream) const
boost::shared_ptr< Handler > HandlerPtr
ListenerPtr createListener(const Scope &scope, const ParticipantConfig &config=getFactory().getDefaultParticipantConfig())
Creates a new listener for the specified scope.
rsc::logging::LoggerPtr logger
Scope concat(const Scope &childScope) const
Creates a new scope that is a sub-scope of this one with the subordinated scope described by the give...
A class describing the configuration of Participant instances.
string getClassName() const
std::set< ListenerPtr > requestListeners
Server::CallbackPtr callback
boost::shared_ptr< Event > EventPtr
Scope is a descriptor for a hierarchical channel of the unified bus.