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