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/ContactStyle.h>
14 #include <yarp/os/Contact.h>
15 #include <yarp/os/Portable.h>
16 #include <yarp/os/Value.h>
17 #include <yarp/os/Property.h>
18 #include <yarp/os/NameStore.h>
19 #include <yarp/os/QosStyle.h>
20 #include <yarp/os/Time.h>
21 
22 
23 namespace yarp {
24  namespace os {
25  class NetworkBase;
26  class Network;
27  class ContactStyle;
28  class QosStyle;
29  }
30 }
31 
32 // Make plugins in a library available for use
33 #define YARP_DECLARE_PLUGINS(name) extern "C" void add_ ## name ## _plugins();
34 #define YARP_REGISTER_PLUGINS(name) add_ ## name ## _plugins();
35 
36 
44 public:
49  static void initMinimum();
50 
56  static void initMinimum(yarp::os::yarpClockType clockType, yarp::os::Clock *custom=nullptr);
57 
63  static void autoInitMinimum();
64 
71  static void autoInitMinimum(yarp::os::yarpClockType clockType, yarp::os::Clock *custom=nullptr);
72 
92  static void yarpClockInit(yarp::os::yarpClockType clockType, Clock *custom = nullptr);
93 
97  static void finiMinimum();
98 
107  static bool connect(const std::string& src, const std::string& dest,
108  const std::string& carrier = "",
109  bool quiet = true);
110 
111  // Catch old uses of nullptr for carrier
112  static bool connect(const char *src, const char *dest,
113  const char *carrier,
114  bool quiet = true) {
115  return connect(std::string(src), std::string(dest), std::string((carrier==nullptr)?"":carrier), quiet);
116  }
117 
125  static bool connect(const std::string& src, const std::string& dest,
126  const ContactStyle& style);
127 
135  static bool disconnect(const std::string& src, const std::string& dest,
136  bool quiet = true);
137 
145  static bool disconnect(const std::string& src, const std::string& dest,
146  const ContactStyle& style);
147 
155  static bool isConnected(const std::string& src, const std::string& dest,
156  bool quiet = true);
157 
165  static bool isConnected(const std::string& src, const std::string& dest,
166  const ContactStyle& style);
167 
174  static bool exists(const std::string& port, bool quiet = true, bool checkVer = true);
175 
182  static bool exists(const std::string& port, const ContactStyle& style, bool checkVer = true);
183 
190  static bool sync(const std::string& port, bool quiet = true);
191 
198  static void assertion(bool shouldBeTrue);
199 
210  static Contact queryName(const std::string& name);
211 
220  static Contact registerName(const std::string& name);
221 
230  static Contact registerContact(const Contact& contact);
231 
239  static Contact unregisterName(const std::string& name);
240 
248  static Contact unregisterContact(const Contact& contact);
249 
250 
261  static bool setProperty(const char *name,
262  const char *key,
263  const Value& value);
264 
265 
273  static Value *getProperty(const char *name,
274  const char *key);
275 
276 
283  static std::string getNameServerName();
284 
291  static Contact getNameServerContact();
292 
293 
302  static bool setNameServerName(const std::string& name);
303 
304 
312  static bool setLocalMode(bool flag);
313 
318  static bool getLocalMode();
319 
320 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
321 
336  static std::string readString(bool *eof = nullptr);
337 #endif // YARP_NO_DEPRECATED
338 
339 
356  static bool write(const Contact& contact,
357  PortWriter& cmd,
358  PortReader& reply,
359  bool admin = false,
360  bool quiet = false,
361  double timeout = -1);
362 
375  static bool write(const Contact& contact,
376  PortWriter& cmd,
377  PortReader& reply,
378  const ContactStyle& style);
379 
389  static bool writeToNameServer(PortWriter& cmd,
390  PortReader& reply,
391  const ContactStyle& style);
392 
403  static bool write(const std::string& port_name,
404  PortWriter& cmd,
405  PortReader& reply);
406 
407 
416  static bool checkNetwork();
417 
418 
429  static bool checkNetwork(double timeout);
430 
439  static bool initialized();
440 
448  static void setVerbosity(int verbosity);
449 
455  static void queryBypass(NameStore *store);
456 
457  static NameStore *getQueryBypass();
458 
468  static std::string getEnvironment(const char *key,
469  bool *found = nullptr);
470 
479  static void setEnvironment(const std::string& key, const std::string& val);
480 
488  static void unsetEnvironment(const std::string& key);
489 
490 
496  static std::string getDirectorySeparator();
497 
503  static std::string getPathSeparator();
504 
513  static bool registerCarrier(const char *name, const char *dll);
514 
518  static void lock();
519 
523  static void unlock();
524 
533  static bool localNetworkAllocation();
534 
546  static Contact detectNameServer(bool useDetectedServer,
547  bool& scanNeeded,
548  bool& serverUsed);
549 
556  static bool setNameServerContact(Contact &nameServerContact);
557 
567  static std::string getConfigFile(const char *fname);
568 
579  static int getDefaultPortRange();
580 
589  static bool setConnectionQos(const std::string& src, const std::string& dest,
590  const QosStyle& srcStyle, const QosStyle& destStyle,
591  bool quiet=true);
592 
600  static bool setConnectionQos(const std::string& src, const std::string& dest,
601  const QosStyle& style, bool quiet=true);
602 
611  static bool getConnectionQos(const std::string& src, const std::string& dest,
612  QosStyle& srcStyle, QosStyle& destStyle, bool quiet=true);
613 
619  static bool isValidPortName(const std::string& portName);
620 
628  static bool waitConnection(const std::string& source,
629  const std::string& destination,
630  bool quiet = false);
631 
638  static bool waitPort(const std::string& target, bool quiet = false);
639 
644  static int sendMessage(const std::string& port,
645  yarp::os::PortWriter& writable,
646  bool silent = false);
647 
656  static int sendMessage(const std::string& port,
657  yarp::os::PortWriter& writable,
658  std::string& output,
659  bool quiet);
660 
668  static int disconnectInput(const std::string& src,
669  const std::string& dest,
670  bool silent = false);
671 
679  static int poll(const std::string& target, bool silent = false);
680 };
681 
689 public:
696  Network();
697 
710  Network(yarp::os::yarpClockType clockType, yarp::os::Clock *custom=nullptr);
711 
715  virtual ~Network();
716 
723  static void init();
724 
729  static void init(yarp::os::yarpClockType clockType, Clock *custom=nullptr);
730 
737  static void fini();
738 };
739 
740 #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:112
Preferences for the port&#39;s Quality of Service.
Definition: QosStyle.h:28
#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:29
#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:688
yarpClockType
Definition: Time.h:24
std::string readString(bool *eof)
Definition: Terminal.cpp:78
A single value (typically within a Bottle).
Definition: Value.h:40
Represents how to reach a part of a YARP network.
Definition: Contact.h:34
Abstract interface for a database of port names.
Definition: NameStore.h:26