BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
StreamConsole.h
1 #pragma once
2 
3 #include <iosfwd>
4 
5 #include <Poco/AtomicCounter.h>
6 #include <Poco/Semaphore.h>
7 #include <Poco/SharedPtr.h>
8 
9 #include "io/Console.h"
10 
11 namespace BeeeOn {
12 
14 public:
15  typedef Poco::SharedPtr<StreamConsoleSessionImpl> Ptr;
16 
18  Poco::Semaphore &semaphore,
19  std::istream &in,
20  std::ostream &out);
22 
23  std::string readUntil(const char c) override;
24  std::string readBytes(const unsigned int length) override;
25  void print(const std::string &text, bool newline = true) override;
26  bool eof() override;
27 
28 private:
29  Poco::Semaphore &m_semaphore;
30  std::istream &m_in;
31  std::ostream &m_out;
32 };
33 
34 class StreamConsole : public Console {
35 public:
36  typedef Poco::SharedPtr<StreamConsole> Ptr;
37 
38  StreamConsole(std::istream &in, std::ostream &out);
39 
40  void close() override;
41 
42 protected:
49  ConsoleSessionImpl::Ptr openSession() override;
50 
51 private:
56  Poco::Semaphore m_semaphore;
60  Poco::AtomicCounter m_close;
61 
62  std::istream &m_in;
63  std::ostream &m_out;
64 };
65 
66 }
std::string readBytes(const unsigned int length) override
Definition: StreamConsole.cpp:29
void print(const std::string &text, bool newline=true) override
Definition: StreamConsole.cpp:34
Definition: Console.h:16
bool eof() override
Definition: StreamConsole.cpp:39
Definition: StreamConsole.h:13
Definition: StreamConsole.h:34
ConsoleSessionImpl::Ptr openSession() override
Definition: StreamConsole.cpp:57
std::string readUntil(const char c) override
Definition: StreamConsole.cpp:24
Definition: Console.h:109