40 name(owner.getName()),
44 yCAssert(PORTCOREINPUTUNIT, ip !=
nullptr);
47 if (creator !=
nullptr) {
48 localReader = creator->
create();
55 if (localReader !=
nullptr) {
57 localReader =
nullptr;
88 bool wasNoticed =
false;
93 yCAssert(PORTCOREINPUTUNIT, ip !=
nullptr);
110 yCDebug(PORTCOREINPUTUNIT,
"Port %s starting up, flushing routes %s->*->%s",
119 officialRoute = route;
125 yCInfo(PORTCOREINPUTUNIT,
"%s", msg.c_str());
128 yCDebug(PORTCOREINPUTUNIT,
"%s", msg.c_str());
167 auto*
id =
reinterpret_cast<void*
>(
this);
182 if (localReader !=
nullptr) {
183 bool ok = localReader->
read(br);
192 bool ok = man.
readBlock(br,
id,
nullptr);
208 bool ok = cmd.
read(br);
238 "Port command (%s): %s should add connection: %s",
246 "Port command (%s): %s should remove output: %s",
254 "Port command (%s): %s should remove input: %s",
269 std::string env = cmd.
getText();
270 if (env.length() > 2) {
271 yCTrace(PORTCOREINPUTUNIT,
"***** received an envelope! [%s]", env.c_str());
272 std::string env2 = env.substr(2, env.length());
276 if (localReader !=
nullptr) {
277 localReader->
read(br);
294 skipIncomingData(*cr);
301 skipIncomingData(br);
338 printf(
"Interrupt requested\n");
348 bw.
appendLine(
"This is a YARP port. Here are the commands it responds to:");
349 bw.
appendLine(
"* Gives a description of this port");
350 bw.
appendLine(
"d Signals the beginning of input for the port's owner");
351 bw.
appendLine(R
"(do The same as "d" except replies should be suppressed ("data-only"))");
354 bw.
appendLine(
"i Interrupt parent process (unix only)");
356 bw.
appendLine(
"r Reverse connection type to be a reader");
357 bw.
appendLine(
"/port Requests to send output to /port");
358 bw.
appendLine(
"!/port Requests to stop sending output to /port");
359 bw.
appendLine(
"~/port Requests to stop receiving input from /port");
360 bw.
appendLine(
"a Signals the beginning of an administrative message");
368 bw.
appendLine(
"Port command not understood.");
369 bw.
appendLine(
"Type d to send data to the port's owner.");
388 yCDebug(PORTCOREINPUTUNIT,
"Closing ip");
394 yCDebug(PORTCOREINPUTUNIT,
"Closed ip");
396 std::string msg = std::string(
"Removing input from ") + route.
getFromName() +
" to " + route.
getToName();
400 yCInfo(PORTCOREINPUTUNIT,
"%s", msg.c_str());
403 yCDebug(PORTCOREINPUTUNIT,
"(unrooted) shutting down");
425 if (localReader !=
nullptr) {
427 localReader =
nullptr;
492 void PortCoreInputUnit::closeMain()
519 return officialRoute;
525 size_t pending = reader.
getSize();
527 while (pending > 0) {
529 size_t next = (pending <
sizeof(buf)) ? pending :
sizeof(buf);
551 void PortCoreInputUnit::envelopeReadCallback(
void* data,
const Bytes& envelope)
558 p->ip->setEnvelope(envelope.
get());
A simple abstraction for a block of bytes.
ConnectionReader & modifyIncomingData(ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
bool acceptIncomingData(ConnectionReader &reader) override
Determine whether incoming data should be accepted.
An interface for reading from a network connection.
virtual bool isTextMode() const =0
Check if the connection is text mode.
virtual size_t getSize() const =0
Checks how much data is available.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
virtual bool isActive() const =0
virtual bool acceptIncomingData(yarp::os::ConnectionReader &reader)=0
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.
virtual yarp::os::ConnectionReader & modifyIncomingData(yarp::os::ConnectionReader &reader)=0
Modify incoming payload data, if appropriate.
virtual bool canEscape() const =0
Check if carrier can encode administrative messages, as opposed to just user data.
virtual bool isPush() const =0
Check if carrier is "push" or "pull" style.
virtual void setCarrierParams(const yarp::os::Property ¶ms)=0
Configure carrier from port administrative commands.
Simple abstraction for a YARP port name.
bool isRooted() const
Check if port name begins with "/".
The output side of an active connection between two ports.
virtual const Route & getRoute() const =0
virtual void rename(const Route &route)=0
Relabel the route after the fact (e.g.
Simple specification of the minimum functions needed from output streams.
Information about a port connection or event.
std::string targetName
Name of connection target, if any.
std::string carrierName
Name of protocol type, if releveant.
bool incoming
True if a connection is incoming, false if outgoing.
std::string message
A human-readable description of contents.
bool created
True if a connection is created, false if destroyed.
std::string portName
Name of port.
int tag
Type of information.
std::string sourceName
Name of connection source, if any.
@ PORTINFO_CONNECTION
Information about an incoming or outgoing connection.
virtual PortReader * create() const =0
Factory for PortReader objects.
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
A class for storing options and configuration information.
Information about a connection between two ports.
const std::string & getToName() const
Get the destination of the route.
const std::string & getCarrierName() const
Get the carrier type of the route.
std::string toString() const
Render a text form of the route, "source->carrier->dest".
const std::string & getFromName() const
Get the source of the route.
void swapNames()
Swap from and to names.
void wait()
Decrement the counter, even if we must wait to do that.
void post()
Increment the counter.
A helper for creating cached object descriptions.
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
virtual void appendLine(const std::string &data)
Send a string along with a carriage-return-line-feed sequence.
Simple Readable and Writable object representing a command to a YARP port.
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
This manages a single threaded resource related to a single input or output connection.
void setMode()
Check the carrier used for the connection, and see if it has a "log" modifier.
void setDoomed()
Request that this connection be shut down as soon as possible.
bool readBlock(ConnectionReader &reader, void *id, yarp::os::OutputStream *os)
Read a block of regular payload data.
yarp::os::PortReaderCreator * getReadCreator()
Get the creator of callbacks.
void setEnvelope(const std::string &envelope)
Set some envelope information to pass along with a message without actually being part of the message...
bool removeIO(const Route &route, bool synch=false)
Remove any connection matching the supplied route.
void report(const yarp::os::PortInfo &info)
Handle a port event (connection, disconnection, etc) Generate a description of the connections associ...
void removeOutput(const std::string &dest, void *id, yarp::os::OutputStream *os)
Remove an output connection.
void reportUnit(PortCoreUnit *unit, bool active)
Called by a connection handler with active=true just after it is fully configured,...
void describe(void *id, yarp::os::OutputStream *os)
Produce a text description of the port and its connections.
bool adminBlock(ConnectionReader &reader, void *id)
Read a block of administrative data.
void removeInput(const std::string &src, void *id, yarp::os::OutputStream *os)
Remove an input connection.
yarp::os::impl::PortDataModifier & getPortModifier()
bool addOutput(const std::string &dest, void *id, yarp::os::OutputStream *os, bool onlyIfNeeded=false)
Add an output connection to this port.
This is the heart of a yarp port.
yarp::os::Carrier * inputModifier
int join(double seconds=-1)
#define yCInfo(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
int getpid()
Portable wrapper for the getppid() function.