Files
aqhomecontrol/aqhome/ipc/data/cmd_data.c
Martin Preuss 03f9178dd2 Revert "Revert "aqhome: convenience code.""
This reverts commit bb77c6acd1.
2024-09-30 18:28:38 +02:00

45 lines
912 B
C

GWEN_MSG *AQH_CmdDataIpc_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds)
{
time_t startTime;
startTime=time(NULL);
for (;;) {
GWEN_MSG *msg;
time_t now;
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) {
uint16_t code;
code=GWEN_IpcMsg_GetCode(msg);
if (code==msgCode) {
DBG_INFO(NULL, "Received expected IPC message");
return msg;
}
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
DBG_INFO(NULL, "Received IPC result message");
return msg;
}
else {
DBG_INFO(NULL, "Received unexpected message %d (%x)", code, code);
}
GWEN_Msg_free(msg);
}
now=time(NULL);
if (now-startTime>timeoutInSeconds) {
DBG_INFO(NULL, "Timeout");
break;
}
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
}
return NULL;
}