YARP
Yet Another Robot Platform
HumanStream.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include "HumanStream.h"
11 #include <yarp/os/Bytes.h>
12 #include <cstring>
13 
15  if (interrupting) { return -1; }
16  while (inputCache.size() < (unsigned int)b.length()) {
17  std::cout << "*** CHECK OTHER TERMINAL FOR SOMETHING TO TYPE:"
18  << std::endl;
19  char buf[1000];
20  needInterrupt = true; // should be mutexed, in real implementation
21  std::cin.getline(buf,1000);
22  needInterrupt = false;
23  if (interrupting) { return -1; }
24  inputCache += buf;
25  inputCache += "\r\n";
26  std::cout << "Thank you" << std::endl;
27  }
28  memcpy(b.get(),inputCache.c_str(),b.length());
29  inputCache = inputCache.substr(b.length());
30  return b.length();
31 }
32 
33 void HumanStream::write(const Bytes& b) {
34  outputCache.append(b.get(),b.length());
35  while (outputCache.find('\n')!=std::string::npos) {
36  size_t idx = outputCache.find('\n');
37  std::string show;
38  show.append(outputCache.c_str(),idx);
39  std::cout << "*** TYPE THIS ON THE OTHER TERMINAL: " << show << std::endl;
40  outputCache = outputCache.substr(idx+1);
41  SystemClock::delaySystem(1);
42  }
43 }
HumanStream.h
yarp::os::Bytes::get
const char * get() const
Definition: Bytes.cpp:30
yarp::os::Bytes::length
size_t length() const
Definition: Bytes.cpp:25
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::InputStream::read
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
Bytes.h
HumanStream::write
void write(const Bytes &b) override
Write a block of bytes to the stream.
Definition: HumanStream.cpp:33