YARP
Yet Another Robot Platform
Network.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 YARP_OS_NETWORK_H
8 #define YARP_OS_NETWORK_H
9 
10 #include <yarp/os/Contact.h>
11 #include <yarp/os/ContactStyle.h>
12 #include <yarp/os/NameStore.h>
13 #include <yarp/os/Portable.h>
14 #include <yarp/os/Property.h>
15 #include <yarp/os/QosStyle.h>
16 #include <yarp/os/Time.h>
17 #include <yarp/os/Value.h>
18 
19 
20 namespace yarp {
21 namespace os {
22 class ContactStyle;
23 class QosStyle;
24 } // namespace os
25 } // namespace yarp
26 
27 // Make plugins in a library available for use
28 #define YARP_DECLARE_PLUGINS(name) extern "C" void add_ ## name ## _plugins();
29 #define YARP_REGISTER_PLUGINS(name) add_ ## name ## _plugins();
30 
31 namespace yarp {
32 namespace os {
33 
41 {
42 public:
47  static void initMinimum();
48 
54  static void initMinimum(yarp::os::yarpClockType clockType,
55  yarp::os::Clock* custom = nullptr);
56 
62  static void autoInitMinimum();
63 
70  static void autoInitMinimum(yarp::os::yarpClockType clockType,
71  yarp::os::Clock* custom = nullptr);
72 
92  static void yarpClockInit(yarp::os::yarpClockType clockType,
93  Clock* custom = nullptr);
94 
98  static void finiMinimum();
99 
100  /*
101  * Return true if network is initialized.
102  * Expect problem if you use things that require a network before
103  * initializing it.
104  */
105  static bool isNetworkInitialized();
106 
115  static bool connect(const std::string& src,
116  const std::string& dest,
117  const std::string& carrier = "",
118  bool quiet = true);
119 
120  // Catch old uses of nullptr for carrier
121  static bool connect(const char* src,
122  const char* dest,
123  const char* carrier,
124  bool quiet = true)
125  {
126  return connect(std::string(src),
127  std::string(dest),
128  std::string((carrier == nullptr) ? "" : carrier),
129  quiet);
130  }
131 
139  static bool connect(const std::string& src,
140  const std::string& dest,
141  const ContactStyle& style);
142 
150  static bool disconnect(const std::string& src,
151  const std::string& dest,
152  bool quiet);
153 
161  static bool disconnect(const std::string& src,
162  const std::string& dest,
163  const ContactStyle& style);
164 
173  static bool disconnect(const std::string& src,
174  const std::string& dest,
175  const std::string& carrier = "",
176  bool quiet = true);
177 
178  // Catch old uses of nullptr for carrier
179  static bool disconnect(const char* src,
180  const char* dest,
181  const char* carrier,
182  bool quiet = true)
183  {
184  return disconnect(std::string(src),
185  std::string(dest),
186  std::string((carrier == nullptr) ? "" : carrier),
187  quiet);
188  }
189 
197  static bool isConnected(const std::string& src,
198  const std::string& dest,
199  bool quiet);
200 
208  static bool isConnected(const std::string& src,
209  const std::string& dest,
210  const ContactStyle& style);
211 
220  static bool isConnected(const std::string& src,
221  const std::string& dest,
222  const std::string& carrier = "",
223  bool quiet = true);
224 
225  // Catch old uses of nullptr for carrier
226  static bool isConnected(const char* src,
227  const char* dest,
228  const char* carrier,
229  bool quiet = true)
230  {
231  return isConnected(std::string(src),
232  std::string(dest),
233  std::string((carrier == nullptr) ? "" : carrier),
234  quiet);
235  }
236 
243  static bool exists(const std::string& port,
244  bool quiet = true,
245  bool checkVer = true);
246 
253  static bool exists(const std::string& port,
254  const ContactStyle& style,
255  bool checkVer = true);
256 
263  static bool sync(const std::string& port,
264  bool quiet = true);
265 
272  static void assertion(bool shouldBeTrue);
273 
284  static Contact queryName(const std::string& name);
285 
294  static Contact registerName(const std::string& name);
295 
304  static Contact registerContact(const Contact& contact);
305 
313  static Contact unregisterName(const std::string& name);
314 
322  static Contact unregisterContact(const Contact& contact);
323 
324 
335  static bool setProperty(const char* name,
336  const char* key,
337  const Value& value);
338 
339 
347  static Value* getProperty(const char* name,
348  const char* key);
349 
350 
357  static std::string getNameServerName();
358 
365  static Contact getNameServerContact();
366 
367 
376  static bool setNameServerName(const std::string& name);
377 
378 
386  static bool setLocalMode(bool flag);
387 
392  static bool getLocalMode();
393 
394 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
409  YARP_DEPRECATED
410  static std::string readString(bool* eof = nullptr);
411 #endif // YARP_NO_DEPRECATED
412 
413 
430  static bool write(const Contact& contact,
431  PortWriter& cmd,
432  PortReader& reply,
433  bool admin = false,
434  bool quiet = false,
435  double timeout = -1);
436 
449  static bool write(const Contact& contact,
450  PortWriter& cmd,
451  PortReader& reply,
452  const ContactStyle& style);
453 
463  static bool writeToNameServer(PortWriter& cmd,
464  PortReader& reply,
465  const ContactStyle& style);
466 
477  static bool write(const std::string& port_name,
478  PortWriter& cmd,
479  PortReader& reply);
480 
481 
490  static bool checkNetwork();
491 
492 
503  static bool checkNetwork(double timeout);
504 
513  static bool initialized();
514 
515 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
522  YARP_DEPRECATED_MSG("Use LogComponents instead")
523  static void setVerbosity(int verbosity);
524 #endif // YARP_NO_DEPRECATED
525 
531  static void queryBypass(NameStore* store);
532 
533  static NameStore* getQueryBypass();
534 
535 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
545  YARP_DEPRECATED_MSG("Use yarp::conf::environment::get_string instead")
546  static std::string getEnvironment(const char* key,
547  bool* found = nullptr);
548 
557  YARP_DEPRECATED_MSG("Use yarp::conf::environment::set_string instead")
558  static void setEnvironment(const std::string& key,
559  const std::string& val);
560 
568  YARP_DEPRECATED_MSG("Use yarp::conf::environment::unset instead")
569  static void unsetEnvironment(const std::string& key);
570 #endif // YARP_NO_DEPRECATED
571 
572 
573 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3.0
579  YARP_DEPRECATED_MSG("Use yarp::conf::filesystem::preferred_separator instead")
580  static std::string getDirectorySeparator();
581 
587  YARP_DEPRECATED_MSG("Use yarp::conf::environment::path_separator instead")
588  static std::string getPathSeparator();
589 #endif // YARP_NO_DEPRECATED
590 
599  static bool registerCarrier(const char* name,
600  const char* dll);
601 
605  static void lock();
606 
610  static void unlock();
611 
620  static bool localNetworkAllocation();
621 
633  static Contact detectNameServer(bool useDetectedServer,
634  bool& scanNeeded,
635  bool& serverUsed);
636 
643  static bool setNameServerContact(Contact& nameServerContact);
644 
654  static std::string getConfigFile(const char* fname);
655 
666  static int getDefaultPortRange();
667 
676  static bool setConnectionQos(const std::string& src,
677  const std::string& dest,
678  const QosStyle& srcStyle,
679  const QosStyle& destStyle,
680  bool quiet = true);
681 
689  static bool setConnectionQos(const std::string& src,
690  const std::string& dest,
691  const QosStyle& style,
692  bool quiet = true);
693 
702  static bool getConnectionQos(const std::string& src,
703  const std::string& dest,
704  QosStyle& srcStyle,
705  QosStyle& destStyle,
706  bool quiet = true);
707 
713  static bool isValidPortName(const std::string& portName);
714 
722  static bool waitConnection(const std::string& source,
723  const std::string& destination,
724  bool quiet = false);
725 
732  static bool waitPort(const std::string& target, bool quiet = false);
733 
738  static int sendMessage(const std::string& port,
739  yarp::os::PortWriter& writable,
740  bool silent = false);
741 
750  static int sendMessage(const std::string& port,
751  yarp::os::PortWriter& writable,
752  std::string& output,
753  bool quiet);
754 
762  static int disconnectInput(const std::string& src,
763  const std::string& dest,
764  bool silent = false);
765 
773  static int poll(const std::string& target, bool silent = false);
774 };
775 
783 {
784 public:
792 
806  yarp::os::Clock* custom = nullptr);
807 
811  virtual ~Network();
812 
819  static void init();
820 
825  static void init(yarp::os::yarpClockType clockType,
826  Clock* custom = nullptr);
827 
834  static void fini();
835 };
836 
837 } // namespace os
838 } // namespace yarp
839 
840 #endif // YARP_OS_NETWORK_H
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:24
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
Abstract interface for a database of port names.
Definition: NameStore.h:20
Utilities for manipulating the YARP network, excluding initialization and shutdown.
Definition: Network.h:41
static bool isConnected(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:226
static bool connect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:121
static bool disconnect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:179
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:783
Network(yarp::os::yarpClockType clockType, yarp::os::Clock *custom=nullptr)
Initialize the YARP network using the specified clock.
static void fini()
Deinitialization.
virtual ~Network()
Destructor.
static void init()
Initialization.
Network()
Constructor.
static void init(yarp::os::yarpClockType clockType, Clock *custom=nullptr)
Initialization.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
Preferences for the port's Quality of Service.
Definition: QosStyle.h:24
A single value (typically within a Bottle).
Definition: Value.h:45
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
void setEnvironment(const std::string &key, const std::string &value)
Set or change an environment variable.
Definition: environment.h:324
bool unset(const std::string &key)
Remove an environment variable.
Definition: environment.h:274
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a string from an environment variable.
Definition: environment.h:309
void unsetEnvironment(const std::string &key)
Remove an environment variable.
Definition: environment.h:338
std::string readString(bool *eof)
Definition: Terminal.cpp:76
yarpClockType
Definition: Time.h:26
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1099
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_init_API
Definition: api.h:32
#define YARP_os_API
Definition: api.h:18