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());
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.