29 #ifndef _TRM_CONNECTION_H
30 #define _TRM_CONNECTION_H
48 static const uint32_t kInvalidClientId = (~0);
49 static const uint32_t kRecorderClientId = 0XFFFFFF00;
50 static const uint32_t kTunerAgentId = 0XFFFFFF02;
51 static const uint32_t kSDVAgentId = 0XFFFFFF03;
52 static const uint32_t kTRMMgrClientId = 0XFFFFFF04;
53 static const uint32_t kTrmClientId = 0x00000000;
54 static const uint32_t kTrmMonitorId = 0xFFFFFFF0;
55 static bool isTestClient(uint32_t clientId) {
56 return ((clientId != kRecorderClientId) &&
57 ((clientId >= kTrmMonitorId)));
60 static bool isXREClient(uint32_t clientId) {
61 return (clientId > 0 && clientId < 0xFFFFFF00);
64 static bool isTunerAgentClient(uint32_t clientId) {
65 return ((clientId == kTunerAgentId));
68 static bool isTRMDiagClient(uint32_t clientId) {
69 return ((clientId == kTRMMgrClientId));
72 static bool isSDVAgentClient(uint32_t clientId) {
73 return ((clientId == kSDVAgentId));
79 void send(
const std::vector<uint8_t> &out)
const;
80 void sendMessage(
const QByteArray &outgoingMessage)
const;
82 void recvMessage(QByteArray &recvBuffer)
const;
83 const QByteArray & recvMessage(
void)
const;
85 void sendAsync(
const std::vector<uint8_t> &out)
const;
90 State(
void) : dataLength(0) {}
91 virtual QByteArray & read(QAbstractSocket &socket, QByteArray &readBuffer) = 0;
92 virtual const char * stateName(
void) = 0;
93 void setDataLength(
size_t length) { dataLength = length;};
94 size_t getDataLength(
void) {
return dataLength;};
101 QByteArray & read(QAbstractSocket &socket, QByteArray &readBuffer);
102 const char * stateName(
void) {
return "IdleState";};
107 QByteArray & read(QAbstractSocket &socket, QByteArray &readBuffer);
108 const char * stateName(
void) {
return "WaitHeaderState";};
113 QByteArray & read(QAbstractSocket &socket, QByteArray &readBuffer);
114 const char * stateName(
void) {
return "WaitPayloadState";};
117 QAbstractSocket & getSocket(
void)
126 void readyRead(
void);
127 void hasMessageToSend(
const std::vector<uint8_t> out)
const;
131 void onReadyRead(
void);
132 void onBytesWritten(qint64 bytes);
133 void onDisconnected(
void);
134 void onSocketError(QAbstractSocket::SocketError socketError);
135 void onStateChanged(QAbstractSocket::SocketState socketState);
136 void onHasMessageToSend(
const std::vector<uint8_t> out)
const;
140 WaitHeaderState waitHeaderState;
141 WaitPayloadState waitPayloadState;
143 QAbstractSocket &socket;
144 mutable QQueue<QByteArray *> incomingMessages;
145 QByteArray *messageByteArray;
147 mutable uint32_t clientId;