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