/
PhysicalLayerSyncProxy.h
executable file
·73 lines (51 loc) · 1.24 KB
/
PhysicalLayerSyncProxy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef __PHYSICAL_LAYER_SYNC_PROXY_H_
#define __PHYSICAL_LAYER_SYNC_PROXY_H_
#include <APL/Lock.h>
#include <APL/Thread.h>
#include <APL/Threadable.h>
#include <APL/PhysicalLayerAsyncBase.h>
#include <iostream>
#include <queue>
#include <boost/system/error_code.hpp>
namespace boost
{
namespace asio
{
class io_service;
}
}
namespace apl
{
class Logger;
/** Simple thread object that allows for non-blocking read of std input.
*/
class PhysicalLayerSyncProxy : public PhysicalLayerAsyncBase, private Threadable
{
public:
PhysicalLayerSyncProxy(Logger*, boost::asio::io_service*);
void DoOpen();
void DoClose();
void DoAsyncRead(boost::uint8_t*, size_t);
void DoAsyncWrite(const boost::uint8_t*, size_t);
static const boost::system::error_code mSuccessCode;
static const boost::system::error_code mErrorCode;
protected:
// Blocking read defined in base class
virtual std::string Read() = 0;
// Blocking write defined in base class
virtual void Write(const std::string&) = 0;
private:
void SignalStop();
void Run();
void Reset();
void CheckForRead();
boost::asio::io_service* mpService;
bool mReading;
size_t mNumToRead;
boost::uint8_t* mpBuffer;
SigLock mWaitLock;
std::deque<std::string> mLineQueue;
Thread mThread;
};
}
#endif