YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
HumanStream.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 "HumanStream.h"
8#include <yarp/os/Bytes.h>
9#include <cstring>
10
12 if (interrupting) { return -1; }
13 while (inputCache.size() < (unsigned int)b.length()) {
14 std::cout << "*** CHECK OTHER TERMINAL FOR SOMETHING TO TYPE:"
15 << std::endl;
16 char buf[1000];
17 needInterrupt = true; // should be mutexed, in real implementation
18 std::cin.getline(buf,1000);
19 needInterrupt = false;
20 if (interrupting) { return -1; }
21 inputCache += buf;
22 inputCache += "\r\n";
23 std::cout << "Thank you" << std::endl;
24 }
25 memcpy(b.get(),inputCache.c_str(),b.length());
26 inputCache = inputCache.substr(b.length());
27 return b.length();
28}
29
30void HumanStream::write(const Bytes& b) {
31 outputCache.append(b.get(),b.length());
32 while (outputCache.find('\n')!=std::string::npos) {
33 size_t idx = outputCache.find('\n');
34 std::string show;
35 show.append(outputCache.c_str(),idx);
36 std::cout << "*** TYPE THIS ON THE OTHER TERMINAL: " << show << std::endl;
37 outputCache = outputCache.substr(idx+1);
39 }
40}
void write(const Bytes &b) override
Write a block of bytes to the stream.
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
size_t length() const
Definition Bytes.cpp:22
const char * get() const
Definition Bytes.cpp:27
virtual int read()
Read and return a single byte.
static void delaySystem(double seconds)
::ssize_t ssize_t
Definition numeric.h:86