aqhome-tool: add Utils_WaitForResponse()
This commit is contained in:
@@ -215,6 +215,45 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds)
|
||||
{
|
||||
time_t startTime;
|
||||
|
||||
startTime=time(NULL);
|
||||
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
time_t now;
|
||||
|
||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
if (GWEN_IpcMsg_GetRefMsgId(msg)==msgId) {
|
||||
DBG_INFO(NULL, "Received expected IPC message");
|
||||
return msg;
|
||||
}
|
||||
else {
|
||||
uint16_t code;
|
||||
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
DBG_ERROR(NULL,
|
||||
"Received unexpected message %d (%x) [msgId=%d, refMsgId=%d]",
|
||||
code, code, GWEN_IpcMsg_GetMsgId(msg), GWEN_IpcMsg_GetRefMsgId(msg));
|
||||
}
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
now=time(NULL);
|
||||
if (now-startTime>timeoutInSeconds) {
|
||||
DBG_ERROR(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
time_t startTime;
|
||||
|
||||
@@ -31,6 +31,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds);
|
||||
|
||||
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
|
||||
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);
|
||||
|
||||
Reference in New Issue
Block a user