BlueZero (BØ)
Middleware for distributed applications
service_server.h
1 #ifndef B0__SERVICE_SERVER_H__INCLUDED
2 #define B0__SERVICE_SERVER_H__INCLUDED
3 
4 #include <string>
5 
6 #include <boost/function.hpp>
7 #include <boost/bind.hpp>
8 
9 #include <b0/socket.h>
10 
11 namespace b0
12 {
13 
14 class Node;
15 
24 class ServiceServer : public Socket
25 {
26 public:
28 
32  ServiceServer(Node *node, std::string service_name, boost::function<void(const std::string&, std::string&)> callback = 0, bool managed = true, bool notify_graph = true);
33 
37  template<class TNode>
38  ServiceServer(TNode *node, std::string service_name, void (TNode::*callbackMethod)(const std::string&, std::string&), bool managed = true, bool notify_graph = true)
39  : ServiceServer(node, service_name, boost::bind(callbackMethod, node, _1, _2), managed, notify_graph)
40  {
41  // delegate constructor. leave empty
42  }
43 
47  template<class T>
48  ServiceServer(Node *node, std::string service_name, void (T::*callbackMethod)(const std::string&, std::string&), T *callbackObject, bool managed = true, bool notify_graph = true)
49  : ServiceServer(node, service_name, boost::bind(callbackMethod, callbackObject, _1, _2), managed, notify_graph)
50  {
51  // delegate constructor. leave empty
52  }
53 
57  virtual ~ServiceServer();
58 
62  void log(LogLevel level, std::string message) const override;
63 
67  virtual void init() override;
68 
72  virtual void cleanup() override;
73 
77  virtual void spinOnce() override;
78 
82  std::string getServiceName();
83 
87  virtual void bind(std::string address);
88 
89 protected:
93  virtual void bind();
94 
98  virtual void unbind();
99 
103  virtual void announce();
104 
106  std::string bind_addr_;
107 
109  const bool notify_graph_;
110 
114  boost::function<void(const std::string&, std::string&)> callback_;
115 };
116 
117 } // namespace b0
118 
119 #endif // B0__SERVICE_SERVER_H__INCLUDED
LogLevel
Definition: interface.h:23
std::string getServiceName()
Return the name of this server&#39;s service.
virtual void bind()
Bind socket to the address.
ServiceServer(TNode *node, std::string service_name, void(TNode::*callbackMethod)(const std::string &, std::string &), bool managed=true, bool notify_graph=true)
Construct a ServiceServer child of a specific Node, using a method (of the Node subclass) as callback...
Definition: service_server.h:38
virtual void unbind()
Unbind socket from the address.
virtual void spinOnce() override
Poll and read incoming messages, and dispatch them (called by b0::Node::spinOnce()) ...
ServiceServer(Node *node, std::string service_name, boost::function< void(const std::string &, std::string &)> callback=0, bool managed=true, bool notify_graph=true)
Construct an ServiceServer child of the specified Node, optionally using a boost::function as a callb...
void log(LogLevel level, std::string message) const override
Log a message using node&#39;s logger, prepending this service server informations.
boost::function< void(const std::string &, std::string &)> callback_
Callback which will be called when a new message is read from the socket.
Definition: service_server.h:114
virtual void cleanup() override
Perform cleanup and optionally send graph notify.
The abstraction for a node in the network.
Definition: node.h:40
The service server class.
Definition: service_server.h:24
The Socket class.
Definition: socket.h:31
std::string bind_addr_
The ZeroMQ address to bind the service socket on.
Definition: service_server.h:106
virtual void log(LogLevel level, std::string message) const =0
Log a message to the remote logger, with a specified level.
virtual ~ServiceServer()
ServiceServer destructor.
virtual void init() override
Perform initialization and optionally send graph notify.
ServiceServer(Node *node, std::string service_name, void(T::*callbackMethod)(const std::string &, std::string &), T *callbackObject, bool managed=true, bool notify_graph=true)
Construct a ServiceServer child of a specific Node, using a method as callback.
Definition: service_server.h:48
const bool notify_graph_
If false this socket will not send announcement to resolv (i.e. it will be "invisible") ...
Definition: service_server.h:109
Definition: node.h:17
virtual void announce()
Announce service to resolver.