YARP
Yet Another Robot Platform
Network.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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 
111  static bool connect(const std::string& src,
112  const std::string& dest,
113  const std::string& carrier = "",
114  bool quiet = true);
115 
116  // Catch old uses of nullptr for carrier
117  static bool connect(const char* src,
118  const char* dest,
119  const char* carrier,
120  bool quiet = true)
121  {
122  return connect(std::string(src),
123  std::string(dest),
124  std::string((carrier == nullptr) ? "" : carrier),
125  quiet);
126  }
127 
135  static bool connect(const std::string& src,
136  const std::string& dest,
137  const ContactStyle& style);
138 
146  static bool disconnect(const std::string& src,
147  const std::string& dest,
148  bool quiet = true);
149 
157  static bool disconnect(const std::string& src,
158  const std::string& dest,
159  const ContactStyle& style);
160 
168  static bool isConnected(const std::string& src,
169  const std::string& dest,
170  bool quiet = true);
171 
179  static bool isConnected(const std::string& src,
180  const std::string& dest,
181  const ContactStyle& style);
182 
189  static bool exists(const std::string& port,
190  bool quiet = true,
191  bool checkVer = true);
192 
199  static bool exists(const std::string& port,
200  const ContactStyle& style,
201  bool checkVer = true);
202 
209  static bool sync(const std::string& port,
210  bool quiet = true);
211 
218  static void assertion(bool shouldBeTrue);
219 
230  static Contact queryName(const std::string& name);
231 
240  static Contact registerName(const std::string& name);
241 
250  static Contact registerContact(const Contact& contact);
251 
259  static Contact unregisterName(const std::string& name);
260 
268  static Contact unregisterContact(const Contact& contact);
269 
270 
281  static bool setProperty(const char* name,
282  const char* key,
283  const Value& value);
284 
285 
293  static Value* getProperty(const char* name,
294  const char* key);
295 
296 
303  static std::string getNameServerName();
304 
311  static Contact getNameServerContact();
312 
313 
322  static bool setNameServerName(const std::string& name);
323 
324 
332  static bool setLocalMode(bool flag);
333 
338  static bool getLocalMode();
339 
340 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
341 
356  static std::string readString(bool* eof = nullptr);
357 #endif // YARP_NO_DEPRECATED
358 
359 
376  static bool write(const Contact& contact,
377  PortWriter& cmd,
378  PortReader& reply,
379  bool admin = false,
380  bool quiet = false,
381  double timeout = -1);
382 
395  static bool write(const Contact& contact,
396  PortWriter& cmd,
397  PortReader& reply,
398  const ContactStyle& style);
399 
409  static bool writeToNameServer(PortWriter& cmd,
410  PortReader& reply,
411  const ContactStyle& style);
412 
423  static bool write(const std::string& port_name,
424  PortWriter& cmd,
425  PortReader& reply);
426 
427 
436  static bool checkNetwork();
437 
438 
449  static bool checkNetwork(double timeout);
450 
459  static bool initialized();
460 
468  static void setVerbosity(int verbosity);
469 
475  static void queryBypass(NameStore* store);
476 
477  static NameStore* getQueryBypass();
478 
488  static std::string getEnvironment(const char* key,
489  bool* found = nullptr);
490 
499  static void setEnvironment(const std::string& key,
500  const std::string& val);
501 
509  static void unsetEnvironment(const std::string& key);
510 
511 
517  static std::string getDirectorySeparator();
518 
524  static std::string getPathSeparator();
525 
534  static bool registerCarrier(const char* name,
535  const char* dll);
536 
540  static void lock();
541 
545  static void unlock();
546 
555  static bool localNetworkAllocation();
556 
568  static Contact detectNameServer(bool useDetectedServer,
569  bool& scanNeeded,
570  bool& serverUsed);
571 
578  static bool setNameServerContact(Contact& nameServerContact);
579 
589  static std::string getConfigFile(const char* fname);
590 
601  static int getDefaultPortRange();
602 
611  static bool setConnectionQos(const std::string& src,
612  const std::string& dest,
613  const QosStyle& srcStyle,
614  const QosStyle& destStyle,
615  bool quiet = true);
616 
624  static bool setConnectionQos(const std::string& src,
625  const std::string& dest,
626  const QosStyle& style,
627  bool quiet = true);
628 
637  static bool getConnectionQos(const std::string& src,
638  const std::string& dest,
639  QosStyle& srcStyle,
640  QosStyle& destStyle,
641  bool quiet = true);
642 
648  static bool isValidPortName(const std::string& portName);
649 
657  static bool waitConnection(const std::string& source,
658  const std::string& destination,
659  bool quiet = false);
660 
667  static bool waitPort(const std::string& target, bool quiet = false);
668 
673  static int sendMessage(const std::string& port,
674  yarp::os::PortWriter& writable,
675  bool silent = false);
676 
685  static int sendMessage(const std::string& port,
686  yarp::os::PortWriter& writable,
687  std::string& output,
688  bool quiet);
689 
697  static int disconnectInput(const std::string& src,
698  const std::string& dest,
699  bool silent = false);
700 
708  static int poll(const std::string& target, bool silent = false);
709 };
710 
718 {
719 public:
726  Network();
727 
741  yarp::os::Clock* custom = nullptr);
742 
746  virtual ~Network();
747 
754  static void init();
755 
760  static void init(yarp::os::yarpClockType clockType,
761  Clock* custom = nullptr);
762 
769  static void fini();
770 };
771 
772 } // namespace os
773 } // namespace yarp
774 
775 #endif // YARP_OS_NETWORK_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:430
static bool connect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:117
Preferences for the port&#39;s Quality of Service.
Definition: QosStyle.h:25
#define YARP_OS_API
Definition: api.h:19
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:26
The main, catch-all namespace for YARP.
Definition: numeric.h:47
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2837
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:26
#define YARP_init_API
Definition: api.h:31
Utilities for manipulating the YARP network, excluding initialization and shutdown.
Definition: Network.h:43
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:717
yarpClockType
Definition: Time.h:28
std::string readString(bool *eof)
Definition: Terminal.cpp:78
A single value (typically within a Bottle).
Definition: Value.h:46
Represents how to reach a part of a YARP network.
Definition: Contact.h:38
Abstract interface for a database of port names.
Definition: NameStore.h:22