YARP
Yet Another Robot Platform
NameSpace.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include <yarp/os/NameSpace.h>
7 
8 #include <yarp/os/Carriers.h>
10 
11 using namespace yarp::os;
12 using namespace yarp::os::impl;
13 
14 
15 NameSpace::~NameSpace() = default;
16 
18 {
19  if (localOnly()) {
20  return true;
21  }
22 
23  Contact c = queryName(getNameServerName());
24  if (!c.isValid()) {
25  return false;
26  }
27 
29  if (out == nullptr) {
30  return false;
31  }
32 
33  out->close();
34  delete out;
35  out = nullptr;
36 
37  return true;
38 }
39 
40 bool NameSpace::checkNetwork(double timeout)
41 {
42  if (localOnly()) {
43  return true;
44  }
45 
46  Contact c = queryName(getNameServerName());
47  if (!c.isValid()) {
48  return false;
49  }
50 
51  c.setTimeout((float)timeout);
53  if (out == nullptr) {
54  return false;
55  }
56 
57  out->close();
58  delete out;
59  out = nullptr;
60 
61  return true;
62 }
63 
64 std::string NameSpace::getNameServerName() const
65 {
66  return getNameServerContact().getName();
67 }
static OutputProtocol * connect(const Contact &address)
Initiate a connection to an address.
Definition: Carriers.cpp:282
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
bool isValid() const
Checks if a Contact is tagged as valid.
Definition: Contact.cpp:298
void setTimeout(float timeout)
Set timeout for this Contact.
Definition: Contact.cpp:282
virtual bool checkNetwork()
Check if a name space is available.
Definition: NameSpace.cpp:17
virtual ~NameSpace()
Destructor.
virtual std::string getNameServerName() const
Get the port name of a name server that manages the name space, if available.
Definition: NameSpace.cpp:64
The output side of an active connection between two ports.
virtual void close()=0
Negotiate an end to operations.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.