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