YARP
Yet Another Robot Platform
NameServerManager.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARPDB_NAMESERVERMANAGER_INC
8 #define YARPDB_NAMESERVERMANAGER_INC
9 
11 
13 #include <mutex>
14 #include <yarp/os/Port.h>
15 
16 
17 namespace yarp {
18  namespace name {
19  class NameServerManager;
20  }
21 }
22 
30 private:
31  NameService& ns;
32  yarp::os::Port *port;
33  std::mutex mutex;
34 public:
36  yarp::os::Port *port = NULL) : ns(ns),
37  port(port), mutex() {
38  }
39 
40  void setPort(yarp::os::Port& port) {
41  this->port = &port;
42  }
43 
44  void onEvent(yarp::os::Bottle& event) override {
45  ns.onEvent(event);
46  if (port!=NULL) {
47  port->write(event);
48  }
49  }
50 
51  yarp::os::PortReader *create() const override {
52  return new NameServerConnectionHandler(const_cast<NameServerManager*>(this));
53  }
54 
55  void lock() override {
56  mutex.lock();
57  }
58 
59  void unlock() override {
60  mutex.unlock();
61  }
62 
63  virtual bool apply(yarp::os::Bottle& cmd,
64  yarp::os::Bottle& reply,
65  yarp::os::Bottle& event,
66  const yarp::os::Contact& remote) override {
67  bool ok = ns.apply(cmd,reply,event,remote);
68  return ok;
69  }
70 };
71 
72 #endif
Manage a single connection to the name server.
Manage the name server.
void setPort(yarp::os::Port &port)
void onEvent(yarp::os::Bottle &event) override
virtual bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote) override
yarp::os::PortReader * create() const override
Factory for PortReader objects.
NameServerManager(NameService &ns, yarp::os::Port *port=NULL)
Abstract interface for a name server operator.
Definition: NameService.h:36
virtual void onEvent(yarp::os::Bottle &event)
Definition: NameService.h:45
virtual bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote)=0
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
A creator for readers.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
A mini-server for network communication.
Definition: Port.h:47
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:427
The main, catch-all namespace for YARP.
Definition: dirs.h:16