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