1 #if !defined(_REQUESTCLIENT_H_) 2 #define _REQUESTCLIENT_H_ 6 #include "NetworkManager.h" 7 #include "MovingAverage.h" 17 typedef void (* RequestCallbackFunction)(RequestReply& reply);
19 enum RequestStatus { NONE = 0, IDLE = 1, QUEUED = 2, PROCESSING = 3, SENT = 4, SUCCESS = 5, FAILED = 6, TIMEOUT = 7, TOOBUSY = 8, LOCALERROR = 9, NETWORKERROR = 10, SERVERERROR = 11};
24 RequestCallbackFunction callback;
32 RequestReply() { requestMsg = replyMsg = NULL; callback = NULL; status = IDLE; systemID = 0; startTime = GetTimeNow(); origin = processor = clientRef = gatewayRef = execRef = finishTime = customRef = 0; isLongReq =
false; isInUse =
true; }
33 virtual ~
RequestReply() {
delete(requestMsg);
delete(replyMsg); callback = NULL; status = IDLE; }
48 bool setStatus(RequestStatus status);
49 RequestStatus getStatus();
50 std::string getStatusText();
51 bool setCallback(RequestCallbackFunction callback);
52 RequestCallbackFunction getCallback();
54 bool replyToRequest(
DataMessage* msg, RequestStatus status);
65 RequestStatus waitForResult(uint32 timeoutMS);
66 DataMessage* waitForMessage(uint32 timeoutMS,
bool takeMessage =
false);
68 uint64 getRequestDuration();
69 uint32 getRequestDurationMS();
79 static bool UnitTest();
86 uint32 getCount() {
return (uint32)requestQ.size(); }
94 std::list<RequestReply*> takeQueue();
100 std::list<RequestReply*> requestQ;
115 uint64 lastStatusTime;
116 uint32 reportedShortReqQSize;
117 uint32 reportedLongReqQSize;
118 uint32 longReqQProcessingSize;
124 void clear() { lastConTime=lastFailTime=conID=location=lastStatusTime=0; reportedShortReqQSize = reportedLongReqQSize = longReqQProcessingSize = count = 0; }
136 void clear() { lastConTime=lastFailTime=conID=0; port=0;
id=0; addr.clear(); conID=location=0; encryption = NOENC; }
141 friend THREAD_RET THREAD_FUNCTION_CALL RequestClientRun(THREAD_ARG arg);
143 static bool TestServerLogin(
const char* address, uint16 port,
const char* username,
const char* password,
const char* reqAfterLogin);
147 static std::string GetJSONReplyParameter(
const char* json,
const char* name);
148 static DataMessage* CreateRequestMessage(uint8 operation,
const char* req,
149 const char* key1 = NULL,
const char* val1 = NULL,
150 const char* key2 = NULL,
const char* val2 = NULL,
151 const char* key3 = NULL,
const char* val3 = NULL,
152 const char* key4 = NULL,
const char* val4 = NULL,
153 const char* key5 = NULL,
const char* val5 = NULL,
154 const char* key6 = NULL,
const char* val6 = NULL,
155 const char* key7 = NULL,
const char* val7 = NULL,
156 const char* key8 = NULL,
const char* val8 = NULL,
157 const char* key9 = NULL,
const char* val9 = NULL,
158 const char* key10 = NULL,
const char* val10 = NULL,
159 const char* key11 = NULL,
const char* val11 = NULL,
160 const char* key12 = NULL,
const char* val12 = NULL,
161 const char* key13 = NULL,
const char* val13 = NULL,
162 const char* key14 = NULL,
const char* val14 = NULL,
163 const char* key15 = NULL,
const char* val15 = NULL,
164 const char* key16 = NULL,
const char* val16 = NULL,
165 const char* key17 = NULL,
const char* val17 = NULL,
166 const char* key18 = NULL,
const char* val18 = NULL,
167 const char* key19 = NULL,
const char* val19 = NULL,
168 const char* key20 = NULL,
const char* val20 = NULL
176 bool addGateway(uint32
id, std::string addr, uint16 port, uint8 encryption = NOENC);
179 bool postRequest(
DataMessage *msg, RequestCallbackFunction callback, uint32 timeoutMS);
189 std::list<RequestGatewayConnection> connections;
193 std::map<uint64,RequestReply*> requestMap;
197 uint64 receivedCount;
205 THREAD_RET THREAD_FUNCTION_CALL RequestClientRun(THREAD_ARG arg);
209 friend THREAD_RET THREAD_FUNCTION_CALL TestRequestClientRun(THREAD_ARG arg);
215 THREAD_RET THREAD_FUNCTION_CALL TestRequestClientRun(THREAD_ARG arg);
219 #endif // _REQUESTCLIENT_H_ Definition: RequestClient.h:110
Definition: NetworkProtocols.h:194
Definition: NetworkManager.h:47
Definition: NetworkManager.h:136
Definition: RequestClient.h:77
Definition: ThreadManager.h:33
Definition: RequestClient.h:127
Definition: RequestClient.h:207
Definition: MovingAverage.h:14
Definition: NetworkManager.h:25
Definition: NetworkProtocols.h:81
Definition: RequestClient.h:139
Definition: NetworkManager.h:12
Definition: RequestClient.h:21
Definition: DataMessage.h:95