YARP
Yet Another Robot Platform
Port.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 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 #include <yarp/os/Port.h>
11 
12 #include <yarp/conf/system.h>
13 
14 #include <yarp/os/Bottle.h>
15 #include <yarp/os/Contact.h>
16 #include <yarp/os/Network.h>
17 #include <yarp/os/Portable.h>
18 #include <yarp/os/Time.h>
19 #include <yarp/os/impl/Logger.h>
22 #include <yarp/os/impl/PortCore.h>
24 
25 using namespace yarp::os::impl;
26 using namespace yarp::os;
27 
28 
29 void* Port::needImplementation() const
30 {
31  if (implementation != nullptr) {
32  return implementation;
33  }
34  Port* self = const_cast<Port*>(this);
35  self->implementation = new yarp::os::impl::PortCoreAdapter(*self);
36  yAssert(self->implementation != nullptr);
37  self->owned = true;
38  return self->implementation;
39 }
40 
41 // implementation is a PortCoreAdapter
42 #define IMPL() (*((yarp::os::impl::PortCoreAdapter*)(needImplementation())))
43 
45 {
46  implementation = nullptr;
47  owned = false;
48 }
49 
51 {
52  if (implementation != nullptr) {
53  close();
54  if (owned) {
56  }
57  implementation = nullptr;
58  owned = false;
59  }
60 }
61 
63 {
64  close();
65  if (owned) {
67  }
68  implementation = port.implementation;
69  owned = false;
70  return true;
71 }
72 
73 bool Port::openFake(const std::string& name)
74 {
75  return open(Contact(name), false, name.c_str());
76 }
77 
78 bool Port::open(const std::string& name)
79 {
80  return open(Contact(name));
81 }
82 
83 bool Port::open(const Contact& contact, bool registerName)
84 {
85  return open(contact, registerName, nullptr);
86 }
87 
88 bool Port::open(const Contact& contact, bool registerName, const char* fakeName)
89 {
90  Contact contact2 = contact;
91 
92  if (!NetworkBase::initialized()) {
93  YARP_ERROR(Logger::get(), "YARP not initialized; create a yarp::os::Network object before using ports");
94  return false;
95  }
96 
97  std::string n = contact2.getName();
98 
99  NameConfig conf;
100  std::string nenv = std::string("YARP_RENAME") + conf.getSafeString(n);
101  std::string rename = NetworkBase::getEnvironment(nenv.c_str());
102  if (!rename.empty()) {
103  n = rename;
104  contact2.setName(n);
105  }
106 
107  bool local = false;
108  if (n.empty() && contact2.getPort() <= 0) {
109  local = true;
110  registerName = false;
111  n = "...";
112  }
113 
114  NestedContact nc(n);
115  if (!nc.getNestedName().empty()) {
116  if (nc.getNodeName().empty()) {
118  nodes.requireActiveName();
119  std::string node_name = nodes.getActiveName();
120  if (!node_name.empty()) {
121  n = n + node_name;
122  }
123  }
124  }
125 
126  PortCoreAdapter* currentCore = &(IMPL());
127  if (currentCore != nullptr) {
128  currentCore->active = false;
129  if (!n.empty() && (n[0] != '/' || currentCore->includeNode) && n[0] != '=' && n != "..." && n.substr(0, 3) != "...") {
130  if (fakeName == nullptr) {
132  std::string node_name = nodes.getActiveName();
133  if (!node_name.empty()) {
134  n = (n[0] == '/' ? "" : "/") + n + "@" + node_name;
135  }
136  }
137  }
138  }
139  if (!n.empty() && n[0] != '/' && n[0] != '=' && n != "..." && n.substr(0, 3) != "...") {
140  if (fakeName == nullptr) {
141  YARP_SPRINTF1(Logger::get(), error, "Port name '%s' needs to start with a '/' character", n.c_str());
142  return false;
143  }
144  }
145  if (!n.empty() && n != "..." && n[0] != '=' && n.substr(0, 3) != "...") {
146  if (fakeName == nullptr) {
147  std::string prefix = NetworkBase::getEnvironment("YARP_PORT_PREFIX");
148  if (!prefix.empty()) {
149  n = prefix + n;
150  contact2.setName(n);
151  }
152  }
153  }
154  if (currentCore != nullptr) {
155  NestedContact nc;
156  nc.fromString(n);
157  if (!nc.getNestedName().empty()) {
158  if (nc.getCategory().empty()) {
159  // we need to add in a category
160  std::string cat;
161  if (currentCore->commitToRead) {
162  cat = "-";
163  } else if (currentCore->commitToWrite) {
164  cat = "+";
165  }
166  if (!cat.empty()) {
167  if (currentCore->commitToRpc) {
168  cat += "1";
169  }
170  contact2.setName(nc.getNestedName() + cat + "@" + nc.getNodeName());
171  } else {
172  YARP_SPRINTF1(Logger::get(), error, "Error: Port '%s' is not committed to being either an input or output port.", n.c_str());
173  YARP_SPRINTF0(Logger::get(), error, "YARP does not mind, but we are trying to register with a name server that does.");
174  YARP_SPRINTF0(Logger::get(), error, "You can call Port::setWriteOnly() or Port::setReadOnly(), OR rename the port.");
175  NestedContact nc2 = nc;
176  nc2.setCategoryWrite();
177  YARP_SPRINTF1(Logger::get(), error, "For an output port, call it: %s (+ adds data)", nc2.toString().c_str());
178  nc2.setCategoryRead();
179  YARP_SPRINTF1(Logger::get(), error, "For an input port, call it: %s (- takes data)", nc2.toString().c_str());
180  return false;
181  }
182  }
183  }
184  }
185 
186  // Allow for open() to be called safely many times on the same Port
187  if ((currentCore != nullptr) && currentCore->isOpened()) {
188  auto* newCore = new PortCoreAdapter(*this);
189  yAssert(newCore != nullptr);
190  // copy state that should survive in a new open()
191  if (currentCore->checkPortReader() != nullptr) {
192  newCore->configReader(*(currentCore->checkPortReader()));
193  }
194  if (currentCore->checkAdminPortReader() != nullptr) {
195  newCore->configAdminReader(*(currentCore->checkAdminPortReader()));
196  }
197  if (currentCore->checkReadCreator() != nullptr) {
198  newCore->configReadCreator(*(currentCore->checkReadCreator()));
199  }
200  if (currentCore->checkWaitAfterSend() >= 0) {
201  newCore->configWaitAfterSend(currentCore->checkWaitAfterSend() != 0);
202  }
203  if (currentCore->haveCallbackLock) {
204  newCore->configCallbackLock(currentCore->recCallbackLock);
205  }
206  close();
207  if (owned) {
208  delete ((PortCoreAdapter*)implementation);
209  }
210  implementation = newCore;
211  owned = true;
212  currentCore = newCore;
213  currentCore->active = false;
214  }
215 
216  PortCoreAdapter& core = IMPL();
217 
218  core.openable();
219 
220  if (NetworkBase::localNetworkAllocation() && contact2.getPort() <= 0) {
221  YARP_DEBUG(Logger::get(), "local network allocation needed");
222  local = true;
223  }
224 
225  bool success = true;
226  Contact address(contact2.getName(),
227  contact2.getCarrier(),
228  contact2.getHost(),
229  contact2.getPort());
230  address.setNestedContact(contact2.getNested());
231 
232  core.setReadHandler(core);
233  if (contact2.getPort() > 0 && !contact2.getHost().empty()) {
234  registerName = false;
235  }
236 
237  std::string ntyp = getType().getNameOnWire();
238  if (ntyp.empty()) {
239  NestedContact nc;
240  nc.fromString(n);
241  if (!nc.getTypeName().empty()) {
242  ntyp = nc.getTypeName();
243  }
244  }
245  if (ntyp.empty()) {
246  ntyp = getType().getName();
247  }
248  if (!ntyp.empty()) {
249  NestedContact nc;
250  nc.fromString(contact2.getName());
251  nc.setTypeName(ntyp);
252  contact2.setNestedContact(nc);
253  if (getType().getNameOnWire() != ntyp) {
254  core.promiseType(Type::byNameOnWire(ntyp.c_str()));
255  }
256  }
257 
258  if (registerName && !local) {
259  address = NetworkBase::registerContact(contact2);
260  }
261 
262  core.setControlRegistration(registerName);
263  success = (address.isValid() || local) && (fakeName == nullptr);
264 
265  if (success) {
266  // create a node if needed
268  nodes.prepare(address.getRegName());
269  }
270 
271  // If we are a service client, go ahead and connect
272  if (success) {
273  NestedContact nc;
274  nc.fromString(address.getName());
275  if (!nc.getNestedName().empty()) {
276  if (nc.getCategory() == "+1") {
277  addOutput(nc.getNestedName());
278  }
279  }
280  }
281 
282  std::string blame = "invalid address";
283  if (success) {
284  success = core.listen(address, registerName);
285  blame = "address conflict";
286  if (success) {
287  success = core.start();
288  blame = "manager did not start";
289  }
290  }
291  if (success) {
292  address = core.getAddress();
293  if (registerName && local) {
294  contact2.setSocket(address.getCarrier(),
295  address.getHost(),
296  address.getPort());
297  contact2.setName(address.getRegName());
298  Contact newName = NetworkBase::registerContact(contact2);
299  core.resetPortName(newName.getName());
300  address = core.getAddress();
301  } else if (core.getAddress().getRegName().empty() && !registerName) {
302  core.resetPortName(core.getAddress().toURI(false));
303  core.setName(core.getAddress().getRegName());
304  }
305 
306  if (core.getVerbosity() >= 1) {
307  if (address.getRegName().empty()) {
309  std::string("Anonymous port active at ") + address.toURI());
310  } else {
312  std::string("Port ") + address.getRegName() + " active at " + address.toURI());
313  }
314  }
315  }
316 
317  if (fakeName != nullptr) {
318  success = core.manualStart(fakeName);
319  blame = "unmanaged port failed to start";
320  }
321 
322  if (!success) {
324  std::string("Port ") + (address.isValid() ? (address.getRegName().c_str()) : (contact2.getName().c_str())) + " failed to activate" + (address.isValid() ? " at " : "") + (address.isValid() ? address.toURI() : std::string("")) + " (" + blame + ")");
325  }
326 
327  if (success) {
328  // create a node if needed
330  nodes.add(*this);
331  }
332 
333  if (success && currentCore != nullptr) {
334  currentCore->active = true;
335  }
336  return success;
337 }
338 
339 bool Port::addOutput(const std::string& name)
340 {
341  return addOutput(Contact(name));
342 }
343 
344 bool Port::addOutput(const std::string& name, const std::string& carrier)
345 {
346  return addOutput(Contact(name, carrier));
347 }
348 
350 {
351  if (!owned) {
352  return;
353  }
354 
356  nodes.remove(*this);
357 
358  PortCoreAdapter& core = IMPL();
359  core.finishReading();
360  core.finishWriting();
361  core.close();
362  core.join();
363  core.active = false;
364 
365  // In fact, open flag means "ever opened", so don't reset it
366  // core.setOpened(false);
367 }
368 
370 {
372  nodes.remove(*this);
373 
374  PortCoreAdapter& core = IMPL();
375  core.interrupt();
376 }
377 
379 {
380  PortCoreAdapter& core = IMPL();
381  if (!core.isInterrupted()) {
382  // prevent resuming when the port is not interrupted
383  return;
384  }
385  core.resumeFull();
387  nodes.add(*this);
388 }
389 
390 
392 {
393  PortCoreAdapter& core = IMPL();
394  return core.getAddress();
395 }
396 
397 
398 bool Port::addOutput(const Contact& contact)
399 {
400  PortCoreAdapter& core = IMPL();
401  if (core.commitToRead) {
402  return false;
403  }
404  if (core.isInterrupted()) {
405  return false;
406  }
407  core.alertOnWrite();
408  std::string name;
409  if (contact.getPort() <= 0) {
410  name = contact.toString();
411  } else {
412  name = contact.toURI();
413  }
414  if (!core.isListening()) {
415  return core.addOutput(name, nullptr, nullptr, true);
416  }
417  Contact me = where();
418  return NetworkBase::connect(me.getName(), name);
419 }
420 
421 
422 bool Port::write(const PortWriter& writer, const PortWriter* callback) const
423 {
424  PortCoreAdapter& core = IMPL();
425  if (core.isInterrupted()) {
426  return false;
427  }
428  core.alertOnWrite();
429  bool result = false;
430  //WritableAdapter adapter(writer);
431  result = core.send(writer, nullptr, callback);
432  //writer.onCompletion();
433  if (!result) {
434  //YARP_DEBUG(Logger::get(), e.toString() + " <<<< Port::write saw this");
435  if (callback != nullptr) {
436  callback->onCompletion();
437  } else {
438  writer.onCompletion();
439  }
440  // leave result false
441  }
442  return result;
443 }
444 
445 bool Port::write(const PortWriter& writer,
446  PortReader& reader,
447  const PortWriter* callback) const
448 {
449  PortCoreAdapter& core = IMPL();
450  if (core.isInterrupted()) {
451  return false;
452  }
453  core.alertOnRpc();
454  core.alertOnWrite();
455  bool result = false;
456  result = core.send(writer, &reader, callback);
457  if (!result) {
458  //YARP_DEBUG(Logger::get(), e.toString() + " <<<< Port::write saw this");
459  if (callback != nullptr) {
460  callback->onCompletion();
461  } else {
462  writer.onCompletion();
463  }
464  // leave result false
465  }
466  return result;
467 }
468 
469 bool Port::read(PortReader& reader, bool willReply)
470 {
471  if (!isOpen()) {
472  return false;
473  }
474  PortCoreAdapter& core = IMPL();
475  if (willReply) {
476  core.alertOnRpc();
477  }
478  core.alertOnRead();
479  if (core.isInterrupted()) {
480  return false;
481  }
482  return core.read(reader, willReply);
483 }
484 
485 
486 bool Port::reply(PortWriter& writer)
487 {
488  PortCoreAdapter& core = IMPL();
489  return core.reply(writer, false, core.isInterrupted());
490 }
491 
493 {
494  PortCoreAdapter& core = IMPL();
495  return core.reply(writer, true, core.isInterrupted());
496 }
497 
498 
500 {
501  PortCoreAdapter& core = IMPL();
502  core.alertOnRead();
503  core.configReader(reader);
504 }
505 
507 {
508  PortCoreAdapter& core = IMPL();
509  core.configAdminReader(reader);
510 }
511 
512 
514 {
515  PortCoreAdapter& core = IMPL();
516  core.alertOnRead();
517  core.configReadCreator(creator);
518 }
519 
520 
521 void Port::enableBackgroundWrite(bool backgroundFlag)
522 {
523  PortCoreAdapter& core = IMPL();
524  core.configWaitAfterSend(!backgroundFlag);
525 }
526 
527 
529 {
530  PortCoreAdapter& core = IMPL();
531  return core.isWriting();
532 }
533 
534 
536 {
537  PortCoreAdapter& core = IMPL();
538  return core.setEnvelope(envelope);
539 }
540 
541 
543 {
544  PortCoreAdapter& core = IMPL();
545  return core.getEnvelope(envelope);
546 }
547 
549 {
550  PortCoreAdapter& core = IMPL();
551  core.alertOnRead();
552  return core.getInputCount();
553 }
554 
556 {
557  PortCoreAdapter& core = IMPL();
558  core.alertOnWrite();
559  return core.getOutputCount();
560 }
561 
563 {
564  PortCoreAdapter& core = IMPL();
565  core.describe(reporter);
566 }
567 
568 
570 {
571  PortCoreAdapter& core = IMPL();
572  core.setReportCallback(&reporter);
573 }
574 
575 
577 {
578  PortCoreAdapter& core = IMPL();
579  core.resetReportCallback();
580 }
581 
582 
583 void Port::setAdminMode(bool adminMode)
584 {
585  if (adminMode) {
586  Bottle b("__ADMIN");
587  setEnvelope(b);
588  } else {
589  Bottle b;
590  setEnvelope(b);
591  }
592 }
593 
594 
595 #define SET_FLAG(implementation, mask, val) \
596  IMPL().setFlags((IMPL().getFlags() & (~(mask))) + ((val) ? (mask) : 0))
597 
598 void Port::setInputMode(bool expectInput)
599 {
600  if (!expectInput) {
601  IMPL().setWriteOnly();
602  }
604 }
605 
606 void Port::setOutputMode(bool expectOutput)
607 {
608  if (!expectOutput) {
609  IMPL().setReadOnly();
610  }
612 }
613 
614 void Port::setRpcMode(bool expectRpc)
615 {
616  if (expectRpc) {
617  IMPL().setRpc();
618  }
620 }
621 
622 bool Port::setTimeout(float timeout)
623 {
624  IMPL().setTimeout(timeout);
625  return true;
626 }
627 
628 void Port::setVerbosity(int level)
629 {
630  IMPL().setVerbosity(level);
631 }
632 
634 {
635  return IMPL().getVerbosity();
636 }
637 
639 {
640  return IMPL().getType();
641 }
642 
643 void Port::promiseType(const Type& typ)
644 {
645  IMPL().promiseType(typ);
646 }
647 
649 {
650  return IMPL().acquireProperties(readOnly);
651 }
652 
654 {
655  IMPL().releaseProperties(prop);
656 }
657 
658 void Port::includeNodeInName(bool flag)
659 {
660  IMPL().includeNodeInName(flag);
661 }
662 
663 bool Port::isOpen() const
664 {
665  if (implementation == nullptr) {
666  return false;
667  }
668  return IMPL().active;
669 }
670 
672 {
673  return IMPL().configCallbackLock(mutex);
674 }
675 
677 {
678  return IMPL().unconfigCallbackLock();
679 }
680 
682 {
683  if (!IMPL().lockCallback()) {
684  fprintf(stderr, "Cannot do lockCallback() without setCallbackLock() before opening port\n");
685  }
686  return true;
687 }
688 
690 {
691  return IMPL().tryLockCallback();
692 }
693 
695 {
696  IMPL().unlockCallback();
697 }
bool sharedOpen(Port &port)
Open a port wrapping an existing port.
Definition: Port.cpp:62
void interrupt()
Prepare the port to be shut down.
Definition: PortCore.cpp:373
std::string getTypeName() const
virtual ~Port()
Destructor.
Definition: Port.cpp:50
bool getEnvelope(PortReader &envelope) override
Get the envelope information (e.g., a timestamp) from the last message received on the port...
Definition: Port.cpp:542
void close() override
Shut down port.
Definition: PortCore.cpp:307
#define YARP_INFO(log, x)
Definition: Logger.h:89
#define PORTCORE_IS_INPUT
Definition: PortCore.h:44
std::string toURI(bool includeCarrier=true) const
Get a representation of the Contact as a URI.
Definition: Contact.cpp:310
virtual void onCompletion() const
This is called when the port has finished all writing operations.
Definition: PortWriter.cpp:16
void unlockCallback() override
Unlock callbacks.
Definition: Port.cpp:694
static Contact registerContact(const Contact &contact)
Register contact information with the name server.
Definition: Network.cpp:940
void setReaderCreator(PortReaderCreator &creator)
Set a creator for readers for port data.
Definition: Port.cpp:513
void resetReportCallback()
Reset the callback to be notified of changes in port status.
Definition: PortCore.cpp:1224
void setVerbosity(int level)
Set whether the port should issue messages about its operations.
Definition: Port.cpp:628
A placeholder for rich contact information.
Definition: NestedContact.h:26
#define YARP_DEBUG(log, x)
Definition: Logger.h:91
static NameClient & getNameClient()
Get an instance of the name client.
Definition: NameClient.cpp:129
A base class for objects that want information about port status changes.
Definition: PortReport.h:30
const NestedContact & getNested() const
Get the NestedContact containing extra information for this Contact.
Definition: Contact.cpp:258
void promiseType(const Type &typ) override
Commit the port to a particular type of data.
Definition: Port.cpp:643
bool isWriting()
Check if a message is currently being sent.
Definition: PortCore.cpp:1442
A class for storing options and configuration information.
Definition: Property.h:34
void setRpcMode(bool expectRpc) override
Configure the port to be RPC only.
Definition: Port.cpp:614
bool isWriting() override
Report whether the port is currently writing data.
Definition: Port.cpp:528
std::string getCategory() const
#define IMPL()
Definition: Port.cpp:42
int getInputCount() override
Determine how many connections are arriving into this port.
Definition: Port.cpp:548
bool isOpen() const
Check if the port has been opened.
Definition: Port.cpp:663
void resetReporter() override
Remove the callback which is called upon any future connections and disconnections to/from the port...
Definition: Port.cpp:576
void add(Contactable &contactable) override
add a Contactable to the Node specified in the contactable name (see NestedContact.nodeName).
Definition: Nodes.cpp:273
void setReporter(PortReport &reporter) override
Set a callback to be called upon any future connections and disconnections to/from the port...
Definition: Port.cpp:569
std::string toString() const
Get a textual representation of the Contact.
Definition: Contact.cpp:300
int getVerbosity()
Get port verbosity level.
Definition: Port.cpp:633
bool reply(PortWriter &writer, bool drop, bool interrupted)
Contact where() const override
Returns information about how this port can be reached.
Definition: Port.cpp:391
std::string getEnvelope()
Definition: PortCore.cpp:1521
A mini-server for network communication.
Definition: Port.h:49
std::string getNestedName() const
std::string getNodeName() const
void setOutputMode(bool expectOutput) override
Configure the port to allow or forbid outputs.
Definition: Port.cpp:606
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:26
void setSocket(const std::string &carrier, const std::string &hostname, int port)
Set information to a Contact about how to reach it using socket communication.
Definition: Contact.cpp:285
bool requireActiveName()
requireActiveName if there is no active node, creates a temporary one.
Definition: Nodes.cpp:333
std::string getHost() const
Get the host name associated with this Contact for socket communication.
Definition: Contact.cpp:225
int getOutputCount() override
Determine how many output connections this port has.
Definition: Port.cpp:555
int join(double seconds=-1)
Definition: ThreadImpl.cpp:157
bool reply(PortWriter &writer) override
Send an object as a reply to an object read from the port.
Definition: Port.cpp:486
int getOutputCount()
Check how many output connections there are.
Definition: PortCore.cpp:1473
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:78
static bool localNetworkAllocation()
Check where the name server in use expects processes to allocate their own network resources...
Definition: Network.cpp:1882
void interrupt() override
Interrupt any current reads or writes attached to the port.
Definition: Port.cpp:369
void setInputMode(bool expectInput) override
Configure the port to allow or forbid inputs.
Definition: Port.cpp:598
The Nodes class.
Definition: Nodes.h:34
std::string getActiveName()
getActiveName getter for the currently active node&#39;s name
Definition: Nodes.cpp:328
std::string getName() const
Get the name associated with this Contact.
Definition: Contact.cpp:202
#define PORTCORE_IS_OUTPUT
Definition: PortCore.h:45
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:422
bool tryLockCallback() override
Try to lock callbacks until unlockCallback() is called.
Definition: Port.cpp:689
static Type byNameOnWire(const char *name_on_wire)
Definition: Type.cpp:189
void setAdminReader(PortReader &reader) override
Set an external reader for unrecognized administrative port messages.
Definition: Port.cpp:506
bool isInterrupted() const
Definition: PortCore.cpp:2720
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
bool replyAndDrop(PortWriter &writer) override
Same as reply(), but closes connection after reply.
Definition: Port.cpp:492
Property * acquireProperties(bool readOnly) override
Access unstructured port properties.
Definition: Port.cpp:648
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
Definition: Port.cpp:535
bool listen(const Contact &address, bool shouldAnnounce=true)
Begin service at a given address.
Definition: PortCore.cpp:108
bool read(ConnectionReader &reader) override
Callback for data.
void promiseType(const Type &typ)
Definition: PortCore.cpp:2814
bool setCallbackLock(yarp::os::Mutex *mutex=nullptr) override
Add a lock to use when invoking callbacks.
Definition: Port.cpp:671
void configAdminReader(PortReader &reader)
bool send(const yarp::os::PortWriter &writer, yarp::os::PortReader *reader=nullptr, const yarp::os::PortWriter *callback=nullptr)
Send a normal message.
Definition: PortCore.cpp:1294
#define SET_FLAG(implementation, mask, val)
Definition: Port.cpp:595
void getReport(PortReport &reporter) override
Get information on the state of the port - connections etc.
Definition: Port.cpp:562
#define PORTCORE_IS_RPC
Definition: PortCore.h:43
Small helper class to help deal with legacy YARP configuration files.
Definition: NameConfig.h:27
bool removeCallbackLock() override
Remove a lock on callbacks added with setCallbackLock()
Definition: Port.cpp:676
yarp::os::Nodes & getNodes()
Definition: NameClient.cpp:497
static std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
Definition: Network.cpp:1334
void setName(const std::string &name)
Set the name of this port.
Definition: PortCore.cpp:2670
void setReadHandler(yarp::os::PortReader &reader)
Set a callback for incoming data.
Definition: PortCore.cpp:179
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:72
std::string getRegName() const
Get the name associated with this Contact.
Definition: Contact.cpp:214
void remove(Contactable &contactable) override
remove a Contactable from the Node specified in the contactable&#39;s name.
Definition: Nodes.cpp:278
Type getType() override
Get the type of data the port has committed to send/receive.
Definition: Port.cpp:638
void configReadCreator(PortReaderCreator &creator)
void setReportCallback(yarp::os::PortReport *reporter)
Set a callback to be notified of changes in port status.
Definition: PortCore.cpp:1215
#define YARP_ERROR(log, x)
Definition: Logger.h:87
void configReader(PortReader &reader)
#define yAssert(x)
Definition: Log.h:112
A creator for readers.
const Contact & getAddress() const
Get the address associated with the port.
Definition: PortCore.cpp:2690
void enableBackgroundWrite(bool backgroundFlag)
control whether writing from this port is done in the background.
Definition: Port.cpp:521
void includeNodeInName(bool flag) override
Choose whether to prepend a node name (if one is available) to the port&#39;s name.
Definition: Port.cpp:658
void configWaitAfterSend(bool waitAfterSend)
int rename(const char *oldname, const char *newname)
Portable wrapper for the rename() function.
Definition: Os.cpp:81
void resetPortName(const std::string &str)
Definition: PortCore.cpp:2695
void setAdminMode(bool adminMode=true)
Turn on/off "admin" mode.
Definition: Port.cpp:583
bool setTimeout(float timeout)
Set a timeout on network operations.
Definition: Port.cpp:622
int getPort() const
Get the port number associated with this Contact for socket communication.
Definition: Contact.cpp:236
void prepare(const std::string &name)
prepare checks for the existence of the node specified in the name parameter.
Definition: Nodes.cpp:313
Represents how to reach a part of a YARP network.
Definition: Contact.h:38
RandScalar * implementation(void *t)
Definition: RandnScalar.cpp:20
bool lockCallback() override
Lock callbacks until unlockCallback() is called.
Definition: Port.cpp:681
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition: Network.cpp:615
bool start() override
Begin main thread.
Definition: PortCore.cpp:320
std::string getSafeString(const std::string &txt)
Definition: NameConfig.cpp:102
void setControlRegistration(bool flag)
Normally the port will unregister its name with the name server when shutting down.
Definition: PortCore.cpp:2705
bool openFake(const std::string &name)
Start port without making it accessible from the network.
Definition: Port.cpp:73
bool addOutput(const std::string &dest, void *id, yarp::os::OutputStream *os, bool onlyIfNeeded=false)
Add an output connection to this port.
Definition: PortCore.cpp:888
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition: Port.cpp:499
bool addOutput(const std::string &name) override
Add an output connection to the specified port.
Definition: Port.cpp:339
PortReaderCreator * checkReadCreator()
void resume() override
Put the port back in an operative state after interrupt() has been called.
Definition: Port.cpp:378
bool fromString(const std::string &nFullName)
An interface to the operating system, including Port based communication.
void close() override
Stop port activity.
Definition: Port.cpp:349
void setEnvelope(const std::string &envelope)
Set some envelope information to pass along with a message without actually being part of the message...
Definition: PortCore.cpp:1507
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition: Port.cpp:469
void setName(const std::string &name)
Set the name associated with this Contact.
Definition: Contact.cpp:219
static bool initialized()
Returns true if YARP has been fully initialized.
Definition: Network.cpp:1312
Port()
Constructor.
Definition: Port.cpp:44
static Logger & get()
Definition: Logger.cpp:45
The components from which ports and connections are built.
void setTypeName(const std::string &nWireType)
int getInputCount()
Check how many input connections there are.
Definition: PortCore.cpp:1464
void cat(Vector &a, const Vector &b)
std::string getCarrier() const
Get the carrier associated with this Contact for socket communication.
Definition: Contact.cpp:247
void describe(void *id, yarp::os::OutputStream *os)
Produce a text description of the port and its connections.
Definition: PortCore.cpp:1091
bool manualStart(const char *sourceName)
Start up the port, but without a main thread.
Definition: PortCore.cpp:352
#define YARP_SPRINTF1(log, mode, msg, a)
Definition: Logger.h:104
void setNestedContact(const yarp::os::NestedContact &nestedContact)
Sets the NestedContact containing extra information for this Contact.
Definition: Contact.cpp:263
void releaseProperties(Property *prop) override
End access unstructured port properties.
Definition: Port.cpp:653
#define YARP_SPRINTF0(log, mode, msg)
Definition: Logger.h:98
bool isListening() const
Definition: PortCore.cpp:2710
Basic wrapper for mutual exclusion.
Definition: Mutex.h:28
std::string toString() const