YARP
Yet Another Robot Platform
Network.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 YARP_OS_NETWORK_H
11 #define YARP_OS_NETWORK_H
12 
13 #include <yarp/os/Contact.h>
14 #include <yarp/os/ContactStyle.h>
15 #include <yarp/os/NameStore.h>
16 #include <yarp/os/Portable.h>
17 #include <yarp/os/Property.h>
18 #include <yarp/os/QosStyle.h>
19 #include <yarp/os/Time.h>
20 #include <yarp/os/Value.h>
21 
22 
23 namespace yarp {
24 namespace os {
25 class ContactStyle;
26 class QosStyle;
27 } // namespace os
28 } // namespace yarp
29 
30 // Make plugins in a library available for use
31 #define YARP_DECLARE_PLUGINS(name) extern "C" void add_ ## name ## _plugins();
32 #define YARP_REGISTER_PLUGINS(name) add_ ## name ## _plugins();
33 
34 namespace yarp {
35 namespace os {
36 
44 {
45 public:
50  static void initMinimum();
51 
57  static void initMinimum(yarp::os::yarpClockType clockType,
58  yarp::os::Clock* custom = nullptr);
59 
65  static void autoInitMinimum();
66 
73  static void autoInitMinimum(yarp::os::yarpClockType clockType,
74  yarp::os::Clock* custom = nullptr);
75 
95  static void yarpClockInit(yarp::os::yarpClockType clockType,
96  Clock* custom = nullptr);
97 
101  static void finiMinimum();
102 
103  /*
104  * Return true if network is initialized.
105  * Expect problem if you use things that require a network before
106  * initializing it.
107  */
108  static bool isNetworkInitialized();
109 
118  static bool connect(const std::string& src,
119  const std::string& dest,
120  const std::string& carrier = "",
121  bool quiet = true);
122 
123  // Catch old uses of nullptr for carrier
124  static bool connect(const char* src,
125  const char* dest,
126  const char* carrier,
127  bool quiet = true)
128  {
129  return connect(std::string(src),
130  std::string(dest),
131  std::string((carrier == nullptr) ? "" : carrier),
132  quiet);
133  }
134 
142  static bool connect(const std::string& src,
143  const std::string& dest,
144  const ContactStyle& style);
145 
153  static bool disconnect(const std::string& src,
154  const std::string& dest,
155  bool quiet);
156 
164  static bool disconnect(const std::string& src,
165  const std::string& dest,
166  const ContactStyle& style);
167 
176  static bool disconnect(const std::string& src,
177  const std::string& dest,
178  const std::string& carrier = "",
179  bool quiet = true);
180 
181  // Catch old uses of nullptr for carrier
182  static bool disconnect(const char* src,
183  const char* dest,
184  const char* carrier,
185  bool quiet = true)
186  {
187  return disconnect(std::string(src),
188  std::string(dest),
189  std::string((carrier == nullptr) ? "" : carrier),
190  quiet);
191  }
192 
200  static bool isConnected(const std::string& src,
201  const std::string& dest,
202  bool quiet);
203 
211  static bool isConnected(const std::string& src,
212  const std::string& dest,
213  const ContactStyle& style);
214 
223  static bool isConnected(const std::string& src,
224  const std::string& dest,
225  const std::string& carrier = "",
226  bool quiet = true);
227 
228  // Catch old uses of nullptr for carrier
229  static bool isConnected(const char* src,
230  const char* dest,
231  const char* carrier,
232  bool quiet = true)
233  {
234  return isConnected(std::string(src),
235  std::string(dest),
236  std::string((carrier == nullptr) ? "" : carrier),
237  quiet);
238  }
239 
246  static bool exists(const std::string& port,
247  bool quiet = true,
248  bool checkVer = true);
249 
256  static bool exists(const std::string& port,
257  const ContactStyle& style,
258  bool checkVer = true);
259 
266  static bool sync(const std::string& port,
267  bool quiet = true);
268 
275  static void assertion(bool shouldBeTrue);
276 
287  static Contact queryName(const std::string& name);
288 
297  static Contact registerName(const std::string& name);
298 
307  static Contact registerContact(const Contact& contact);
308 
316  static Contact unregisterName(const std::string& name);
317 
325  static Contact unregisterContact(const Contact& contact);
326 
327 
338  static bool setProperty(const char* name,
339  const char* key,
340  const Value& value);
341 
342 
350  static Value* getProperty(const char* name,
351  const char* key);
352 
353 
360  static std::string getNameServerName();
361 
368  static Contact getNameServerContact();
369 
370 
379  static bool setNameServerName(const std::string& name);
380 
381 
389  static bool setLocalMode(bool flag);
390 
395  static bool getLocalMode();
396 
397 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
398 
413  static std::string readString(bool* eof = nullptr);
414 #endif // YARP_NO_DEPRECATED
415 
416 
433  static bool write(const Contact& contact,
434  PortWriter& cmd,
435  PortReader& reply,
436  bool admin = false,
437  bool quiet = false,
438  double timeout = -1);
439 
452  static bool write(const Contact& contact,
453  PortWriter& cmd,
454  PortReader& reply,
455  const ContactStyle& style);
456 
466  static bool writeToNameServer(PortWriter& cmd,
467  PortReader& reply,
468  const ContactStyle& style);
469 
480  static bool write(const std::string& port_name,
481  PortWriter& cmd,
482  PortReader& reply);
483 
484 
493  static bool checkNetwork();
494 
495 
506  static bool checkNetwork(double timeout);
507 
516  static bool initialized();
517 
518 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
519 
525  YARP_DEPRECATED_MSG("Use LogComponents instead")
526  static void setVerbosity(int verbosity);
527 #endif // YARP_NO_DEPRECATED
528 
534  static void queryBypass(NameStore* store);
535 
536  static NameStore* getQueryBypass();
537 
538 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
539 
548  YARP_DEPRECATED_MSG("Use yarp::conf::environment::getEnvironment instead")
549  static std::string getEnvironment(const char* key,
550  bool* found = nullptr);
551 
560  YARP_DEPRECATED_MSG("Use yarp::conf::environment::setEnvironment instead")
561  static void setEnvironment(const std::string& key,
562  const std::string& val);
563 
571  YARP_DEPRECATED_MSG("Use yarp::conf::environment::unsetEnvironment instead")
572  static void unsetEnvironment(const std::string& key);
573 #endif // YARP_NO_DEPRECATED
574 
575 
576 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3.0
577 
582  YARP_DEPRECATED_MSG("Use yarp::conf::filesystem::preferred_separator instead")
583  static std::string getDirectorySeparator();
584 
590  YARP_DEPRECATED_MSG("Use yarp::conf::filesystem::path_separator instead")
591  static std::string getPathSeparator();
592 #endif // YARP_NO_DEPRECATED
593 
602  static bool registerCarrier(const char* name,
603  const char* dll);
604 
608  static void lock();
609 
613  static void unlock();
614 
623  static bool localNetworkAllocation();
624 
636  static Contact detectNameServer(bool useDetectedServer,
637  bool& scanNeeded,
638  bool& serverUsed);
639 
646  static bool setNameServerContact(Contact& nameServerContact);
647 
657  static std::string getConfigFile(const char* fname);
658 
669  static int getDefaultPortRange();
670 
679  static bool setConnectionQos(const std::string& src,
680  const std::string& dest,
681  const QosStyle& srcStyle,
682  const QosStyle& destStyle,
683  bool quiet = true);
684 
692  static bool setConnectionQos(const std::string& src,
693  const std::string& dest,
694  const QosStyle& style,
695  bool quiet = true);
696 
705  static bool getConnectionQos(const std::string& src,
706  const std::string& dest,
707  QosStyle& srcStyle,
708  QosStyle& destStyle,
709  bool quiet = true);
710 
716  static bool isValidPortName(const std::string& portName);
717 
725  static bool waitConnection(const std::string& source,
726  const std::string& destination,
727  bool quiet = false);
728 
735  static bool waitPort(const std::string& target, bool quiet = false);
736 
741  static int sendMessage(const std::string& port,
742  yarp::os::PortWriter& writable,
743  bool silent = false);
744 
753  static int sendMessage(const std::string& port,
754  yarp::os::PortWriter& writable,
755  std::string& output,
756  bool quiet);
757 
765  static int disconnectInput(const std::string& src,
766  const std::string& dest,
767  bool silent = false);
768 
776  static int poll(const std::string& target, bool silent = false);
777 };
778 
786 {
787 public:
795 
809  yarp::os::Clock* custom = nullptr);
810 
814  virtual ~Network();
815 
822  static void init();
823 
828  static void init(yarp::os::yarpClockType clockType,
829  Clock* custom = nullptr);
830 
837  static void fini();
838 };
839 
840 } // namespace os
841 } // namespace yarp
842 
843 #endif // YARP_OS_NETWORK_H
yarp::os::ContactStyle
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:27
yarp::os::NetworkBase::isConnected
static bool isConnected(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:229
yarp::os::QosStyle
Preferences for the port's Quality of Service.
Definition: QosStyle.h:26
yarp::os::Network::fini
static void fini()
Deinitialization.
yarp::os::NameStore
Abstract interface for a database of port names.
Definition: NameStore.h:23
yarp::os::Network::~Network
virtual ~Network()
Destructor.
ContactStyle.h
yarp::os::Network::init
static void init(yarp::os::yarpClockType clockType, Clock *custom=nullptr)
Initialization.
yarp::conf::environment::getEnvironment
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
Definition: environment.h:31
yarp::os::Clock
Definition: Clock.h:18
Portable.h
YARP_DEPRECATED
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2882
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::conf::filesystem::path_separator
static constexpr value_type path_separator
Definition: filesystem.h:29
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::conf::environment::unsetEnvironment
void unsetEnvironment(const std::string &key)
Remove an environment variable.
Definition: environment.h:67
yarp::os::Network::Network
Network()
Constructor.
yarp::os::impl::Terminal::readString
std::string readString(bool *eof)
Definition: Terminal.cpp:79
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Property.h
QosStyle.h
YARP_init_API
#define YARP_init_API
Definition: api.h:31
yarp::os::Network::init
static void init()
Initialization.
YARP_DEPRECATED_MSG
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
yarp::os::Network
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:786
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::conf::environment::setEnvironment
void setEnvironment(const std::string &key, const std::string &val)
Set or change an environment variable.
Definition: environment.h:51
Time.h
yarp::os::Network::Network
Network(yarp::os::yarpClockType clockType, yarp::os::Clock *custom=nullptr)
Initialize the YARP network using the specified clock.
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
Contact.h
yarp::os::NetworkBase::disconnect
static bool disconnect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:182
NameStore.h
yarp::os::NetworkBase
Utilities for manipulating the YARP network, excluding initialization and shutdown.
Definition: Network.h:44
yarp::os::NetworkBase::connect
static bool connect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:124
Value.h
yarp::os::yarpClockType
yarpClockType
Definition: Time.h:29