YARP  2.3.68+228-20170410.2+git7d0b2e0
Yet Another Robot Platform
Network.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 RobotCub Consortium
3  * Authors: Paul Fitzpatrick
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  */
6 
7 #ifndef YARP_OS_NETWORK_H
8 #define YARP_OS_NETWORK_H
9 
10 #include <yarp/os/ContactStyle.h>
11 #include <yarp/os/Contact.h>
12 #include <yarp/os/Portable.h>
13 #include <yarp/os/Value.h>
14 #include <yarp/os/Property.h>
15 #include <yarp/os/NameStore.h>
16 #include <yarp/os/QosStyle.h>
17 
18 //protects against some dangerous ACE macros
19 #ifdef main
20 #undef main
21 #endif
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 
43 class YARP_OS_API yarp::os::NetworkBase {
44 public:
49  static void initMinimum();
50 
56  static void autoInitMinimum();
57 
58 
62  static void finiMinimum();
63 
72  static bool connect(const ConstString& src, const ConstString& dest,
73  const ConstString& carrier = "",
74  bool quiet = true);
75 
76  // Catch old uses of YARP_NULLPTR for carrier
77  static bool connect(const char *src, const char *dest,
78  const char *carrier,
79  bool quiet = true) {
80  return connect(ConstString(src),ConstString(dest),ConstString((carrier==YARP_NULLPTR)?"":carrier),quiet);
81  }
82 
90  static bool connect(const ConstString& src, const ConstString& dest,
91  const ContactStyle& style);
92 
100  static bool disconnect(const ConstString& src, const ConstString& dest,
101  bool quiet = true);
102 
110  static bool disconnect(const ConstString& src, const ConstString& dest,
111  const ContactStyle& style);
112 
120  static bool isConnected(const ConstString& src, const ConstString& dest,
121  bool quiet = true);
122 
130  static bool isConnected(const ConstString& src, const ConstString& dest,
131  const ContactStyle& style);
132 
139  static bool exists(const ConstString& port, bool quiet = true);
140 
147  static bool exists(const ConstString& port, const ContactStyle& style);
148 
155  static bool sync(const ConstString& port, bool quiet = true);
156 
167  static int main(int argc, char *argv[]);
168 
177  static int runNameServer(int argc, char *argv[]);
178 
185  static void assertion(bool shouldBeTrue);
186 
197  static Contact queryName(const ConstString& name);
198 
207  static Contact registerName(const ConstString& name);
208 
217  static Contact registerContact(const Contact& contact);
218 
226  static Contact unregisterName(const ConstString& name);
227 
235  static Contact unregisterContact(const Contact& contact);
236 
237 
248  static bool setProperty(const char *name,
249  const char *key,
250  const Value& value);
251 
252 
260  static Value *getProperty(const char *name,
261  const char *key);
262 
263 
270  static ConstString getNameServerName();
271 
278  static Contact getNameServerContact();
279 
280 
289  static bool setNameServerName(const ConstString& name);
290 
291 
299  static bool setLocalMode(bool flag);
300 
305  static bool getLocalMode();
306 
319  static ConstString readString(bool *eof = YARP_NULLPTR);
320 
321 
338  static bool write(const Contact& contact,
339  PortWriter& cmd,
340  PortReader& reply,
341  bool admin = false,
342  bool quiet = false,
343  double timeout = -1);
344 
357  static bool write(const Contact& contact,
358  PortWriter& cmd,
359  PortReader& reply,
360  const ContactStyle& style);
361 
371  static bool writeToNameServer(PortWriter& cmd,
372  PortReader& reply,
373  const ContactStyle& style);
374 
385  static bool write(const ConstString& port_name,
386  PortWriter& cmd,
387  PortReader& reply);
388 
389 
398  static bool checkNetwork();
399 
400 
411  static bool checkNetwork(double timeout);
412 
421  static bool initialized();
422 
430  static void setVerbosity(int verbosity);
431 
437  static void queryBypass(NameStore *store);
438 
439  static NameStore *getQueryBypass();
440 
450  static ConstString getEnvironment(const char *key,
451  bool *found = YARP_NULLPTR);
452 
461  static void setEnvironment(const ConstString& key,const ConstString& val);
462 
470  static void unsetEnvironment(const ConstString& key);
471 
472 
478  static ConstString getDirectorySeparator();
479 
485  static ConstString getPathSeparator();
486 
495  static bool registerCarrier(const char *name,const char *dll);
496 
500  static void lock();
501 
505  static void unlock();
506 
515  static bool localNetworkAllocation();
516 
528  static Contact detectNameServer(bool useDetectedServer,
529  bool& scanNeeded,
530  bool& serverUsed);
531 
538  static bool setNameServerContact(Contact &nameServerContact);
539 
549  static ConstString getConfigFile(const char *fname);
550 
561  static int getDefaultPortRange();
562 
571  static bool setConnectionQos(const ConstString& src, const ConstString& dest,
572  const QosStyle& srcStyle, const QosStyle& destStyle,
573  bool quiet=true);
574 
582  static bool setConnectionQos(const ConstString& src, const ConstString& dest,
583  const QosStyle& style, bool quiet=true);
584 
593  static bool getConnectionQos(const ConstString& src, const ConstString& dest,
594  QosStyle& srcStyle, QosStyle& destStyle, bool quiet=true);
595 };
596 
603 class YARP_init_API yarp::os::Network : public NetworkBase {
604 public:
611  Network();
612 
616  virtual ~Network();
617 
624  static void init();
625 
626 
633  static void fini();
634 
635 };
636 
637 #endif // YARP_OS_NETWORK_H
static void unlock()
Definition: Time.cpp:32
static bool connect(const char *src, const char *dest, const char *carrier, bool quiet=true)
Definition: Network.h:77
Preferences for the port&#39;s Quality of Service.
Definition: QosStyle.h:26
* dest
Definition: ImageCopy.cpp:72
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
The main, catch-all namespace for YARP.
A string with almost the same api as std::string.
Definition: ConstString.h:44
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:25
static void lock()
Definition: Time.cpp:28
virtual void write(const Bytes &b)
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:603
ConstString name
Definition: Module.h:221
int main()
A single value (typically within a Bottle).
Definition: Value.h:36
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Abstract interface for a database of port names.
Definition: NameStore.h:23
#define YARP_NULLPTR
Expands to either the standard nullptr or to 0 elsewhere.
Definition: compiler.h:2513