|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
43 name(owner.getName()),
47 yCAssert(PORTCOREINPUTUNIT, ip !=
nullptr);
50 if (creator !=
nullptr) {
51 localReader = creator->
create();
58 if (localReader !=
nullptr) {
60 localReader =
nullptr;
91 bool wasNoticed =
false;
96 yCAssert(PORTCOREINPUTUNIT, ip !=
nullptr);
113 yCDebug(PORTCOREINPUTUNIT,
"Port %s starting up, flushing routes %s->*->%s",
122 officialRoute = route;
128 yCInfo(PORTCOREINPUTUNIT,
"%s", msg.c_str());
131 yCDebug(PORTCOREINPUTUNIT,
"%s", msg.c_str());
170 auto*
id =
reinterpret_cast<void*
>(
this);
185 if (localReader !=
nullptr) {
186 bool ok = localReader->
read(br);
195 bool ok = man.
readBlock(br,
id,
nullptr);
211 bool ok = cmd.
read(br);
241 "Port command (%s): %s should add connection: %s",
249 "Port command (%s): %s should remove output: %s",
257 "Port command (%s): %s should remove input: %s",
272 std::string env = cmd.
getText();
273 if (env.length() > 2) {
274 yCTrace(PORTCOREINPUTUNIT,
"***** received an envelope! [%s]", env.c_str());
275 std::string env2 = env.substr(2, env.length());
279 if (localReader !=
nullptr) {
280 localReader->
read(br);
297 skipIncomingData(*cr);
304 skipIncomingData(br);
341 printf(
"Interrupt requested\n");
351 bw.
appendLine(
"This is a YARP port. Here are the commands it responds to:");
352 bw.
appendLine(
"* Gives a description of this port");
353 bw.
appendLine(
"d Signals the beginning of input for the port's owner");
354 bw.
appendLine(R
"(do The same as "d" except replies should be suppressed ("data-only"))");
357 bw.
appendLine(
"i Interrupt parent process (unix only)");
359 bw.
appendLine(
"r Reverse connection type to be a reader");
360 bw.
appendLine(
"/port Requests to send output to /port");
361 bw.
appendLine(
"!/port Requests to stop sending output to /port");
362 bw.
appendLine(
"~/port Requests to stop receiving input from /port");
363 bw.
appendLine(
"a Signals the beginning of an administrative message");
371 bw.
appendLine(
"Port command not understood.");
372 bw.
appendLine(
"Type d to send data to the port's owner.");
391 yCDebug(PORTCOREINPUTUNIT,
"Closing ip");
397 yCDebug(PORTCOREINPUTUNIT,
"Closed ip");
399 std::string msg = std::string(
"Removing input from ") + route.
getFromName() +
" to " + route.
getToName();
403 yCInfo(PORTCOREINPUTUNIT,
"%s", msg.c_str());
406 yCDebug(PORTCOREINPUTUNIT,
"(unrooted) shutting down");
428 if (localReader !=
nullptr) {
430 localReader =
nullptr;
495 void PortCoreInputUnit::closeMain()
522 return officialRoute;
528 size_t pending = reader.
getSize();
530 while (pending > 0) {
532 size_t next = (pending <
sizeof(buf)) ? pending :
sizeof(buf);
554 void PortCoreInputUnit::envelopeReadCallback(
void* data,
const Bytes& envelope)
561 p->ip->setEnvelope(envelope.
get());
std::string toString() const
Render a text form of the route, "source->carrier->dest".
void setDoomed()
Request that this connection be shut down as soon as possible.
virtual void appendLine(const std::string &data)
Send a string along with a carriage-return-line-feed sequence.
void swapNames()
Swap from and to names.
virtual bool acceptIncomingData(yarp::os::ConnectionReader &reader)=0
Determine whether incoming data should be accepted.
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
const std::string & getCarrierName() const
Get the carrier type of the route.
virtual PortReader * create() const =0
Factory for PortReader objects.
@ PORTINFO_CONNECTION
Information about an incoming or outgoing connection.
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
This manages a single threaded resource related to a single input or output connection.
The output side of an active connection between two ports.
This is the heart of a yarp port.
Simple specification of the minimum functions needed from output streams.
virtual const Route & getRoute() const =0
Simple Readable and Writable object representing a command to a YARP port.
A helper for creating cached object descriptions.
virtual size_t getSize() const =0
Checks how much data is available.
bool created
True if a connection is created, false if destroyed.
int getpid()
Portable wrapper for the getppid() function.
Information about a connection between two ports.
void wait()
Decrement the counter, even if we must wait to do that.
bool removeIO(const Route &route, bool synch=false)
Remove any connection matching the supplied route.
virtual bool canEscape() const =0
Check if carrier can encode administrative messages, as opposed to just user data.
Information about a port connection or event.
std::string carrierName
Name of protocol type, if releveant.
void describe(void *id, yarp::os::OutputStream *os)
Produce a text description of the port and its connections.
void post()
Increment the counter.
std::string targetName
Name of connection target, if any.
virtual yarp::os::ConnectionReader & modifyIncomingData(yarp::os::ConnectionReader &reader)=0
Modify incoming payload data, if appropriate.
int tag
Type of information.
bool readBlock(ConnectionReader &reader, void *id, yarp::os::OutputStream *os)
Read a block of regular payload data.
void reportUnit(PortCoreUnit *unit, bool active)
Called by a connection handler with active=true just after it is fully configured,...
virtual bool isPush() const =0
Check if carrier is "push" or "pull" style.
int join(double seconds=-1)
bool incoming
True if a connection is incoming, false if outgoing.
void removeOutput(const std::string &dest, void *id, yarp::os::OutputStream *os)
Remove an output connection.
yarp::os::impl::PortDataModifier & getPortModifier()
virtual void rename(const Route &route)=0
Relabel the route after the fact (e.g.
std::string portName
Name of port.
yarp::os::Carrier * inputModifier
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
yarp::os::PortReaderCreator * getReadCreator()
Get the creator of callbacks.
ConnectionReader & modifyIncomingData(ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
Simple abstraction for a YARP port name.
std::string message
A human-readable description of contents.
A simple abstraction for a block of bytes.
bool acceptIncomingData(ConnectionReader &reader) override
Determine whether incoming data should be accepted.
virtual void getCarrierParams(yarp::os::Property ¶ms) const =0
Get carrier configuration and deliver it by port administrative commands.
#define yCAssert(component, x)
virtual bool isActive() const =0
An interface for reading from a network connection.
bool addOutput(const std::string &dest, void *id, yarp::os::OutputStream *os, bool onlyIfNeeded=false)
Add an output connection to this port.
virtual void setCarrierParams(const yarp::os::Property ¶ms)=0
Configure carrier from port administrative commands.
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
#define yCInfo(component,...)
void removeInput(const std::string &src, void *id, yarp::os::OutputStream *os)
Remove an input connection.
void setEnvelope(const std::string &envelope)
Set some envelope information to pass along with a message without actually being part of the message...
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
void report(const yarp::os::PortInfo &info)
Handle a port event (connection, disconnection, etc) Generate a description of the connections associ...
virtual bool isTextMode() const =0
Check if the connection is text mode.
const std::string & getToName() const
Get the destination of the route.
#define yCTrace(component,...)
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
const std::string & getFromName() const
Get the source of the route.
#define YARP_OS_LOG_COMPONENT(name, name_string)
void setMode()
Check the carrier used for the connection, and see if it has a "log" modifier.
The components from which ports and connections are built.
bool adminBlock(ConnectionReader &reader, void *id)
Read a block of administrative data.
A class for storing options and configuration information.
bool isRooted() const
Check if port name begins with "/".
std::string sourceName
Name of connection source, if any.