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