YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
HumanStream.h
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
11#include <yarp/os/SystemClock.h>
12
13#include <iostream>
14#include <string>
15#include <cstdio>
16
17using namespace yarp::os;
18
19
21 public InputStream,
22 public OutputStream
23{
24private:
25 bool interrupting;
26 bool needInterrupt;
27 std::string inputCache;
28 std::string outputCache;
29public:
31 interrupting = false;
32 needInterrupt = false;
33 inputCache = outputCache = "";
34 }
35
36 void close() override {
37 std::cout << "Bye bye" << std::endl;
38 }
39
40 bool isOk() const override {
41 return true;
42 }
43
44 void interrupt() override {
45 interrupting = true;
46 while (needInterrupt) {
47 std::cout << "*** INTERRUPT: Please hit enter ***" << std::endl;
48 for (int i=0; i<10 && needInterrupt; i++) {
50 }
51 }
52 }
53
54 // InputStream
56 yarp::conf::ssize_t read(Bytes& b) override;
57
58 // OutputStream
60 void write(const Bytes& b) override;
61
62 // TwoWayStream
63
65 return *this;
66 }
67
69 return *this;
70 }
71
72 const yarp::os::Contact& getLocalAddress() const override {
73 // left undefined
74 return local;
75 }
76
77 const yarp::os::Contact& getRemoteAddress() const override {
78 // left undefined
79 return remote;
80 }
81
82 void reset() override {
83 inputCache = outputCache = "";
84 std::cout << "Stream reset" << std::endl;
85 }
86
87 void beginPacket() override {
88 std::cout << "Packet begins" << std::endl;
89 inputCache = "";
90 outputCache = "";
91 }
92
93 void endPacket() override {
94 std::cout << "Packet ends" << std::endl;
95 }
96
97private:
98 yarp::os::Contact local, remote;
99};
void write(const Bytes &b) override
Write a block of bytes to the stream.
InputStream & getInputStream() override
Get an InputStream to read from.
Definition HumanStream.h:64
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition HumanStream.h:93
void beginPacket() override
Mark the beginning of a logical packet.
Definition HumanStream.h:87
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition HumanStream.h:72
void reset() override
Reset the stream.
Definition HumanStream.h:82
OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition HumanStream.h:68
void close() override
Terminate the stream.
Definition HumanStream.h:36
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition HumanStream.h:77
void interrupt() override
Interrupt the stream.
Definition HumanStream.h:44
bool isOk() const override
Check if the stream is ok or in an error state.
Definition HumanStream.h:40
A simple abstraction for a block of bytes.
Definition Bytes.h:24
Represents how to reach a part of a YARP network.
Definition Contact.h:33
Simple specification of the minimum functions needed from input streams.
Definition InputStream.h:25
virtual int read()
Read and return a single byte.
Simple specification of the minimum functions needed from output streams.
virtual void write(char ch)
Write a single byte to the stream.
static void delaySystem(double seconds)
A stream which can be asked to perform bidirectional communication.
::ssize_t ssize_t
Definition numeric.h:86
An interface to the operating system, including Port based communication.