From 106f47d465912eda61e62ce3ffddc72b639d3764 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 1 Mar 2025 15:22:00 +0100 Subject: [PATCH] aqhome-tool: more work on transformation to events2. --- apps/aqhome-tool/client.c | 64 +++++++++------------------------------ apps/aqhome-tool/utils.c | 36 ---------------------- 2 files changed, 15 insertions(+), 85 deletions(-) diff --git a/apps/aqhome-tool/client.c b/apps/aqhome-tool/client.c index 6a89c01..929baf8 100644 --- a/apps/aqhome-tool/client.c +++ b/apps/aqhome-tool/client.c @@ -19,7 +19,7 @@ #include "aqhome/msg/ipc/m_ipc_result.h" #include "aqhome/msg/ipc/data/m_ipcd.h" #include "aqhome/msg/ipc/data/m_ipcd_connect.h" -#include "aqhome/ipc2/endpoint.h" +#include "aqhome/ipc2/ipc_endpoint.h" #include #include @@ -37,7 +37,7 @@ static void GWENHYWFAR_CB _freeData(void *bp, void *p); static int _sendWaitHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo); static int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId); -static int _exchangeConnect(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t flags); +static int _exchangeConnect(AQH_TOOL_CLIENT *xo, uint32_t flags); static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId); static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first); @@ -216,7 +216,7 @@ int AQH_ToolClient_Run(AQH_OBJECT *o) return 2; } - rv=_exchangeConnect(o, xo, xo->flags); + rv=_exchangeConnect(xo, xo->flags); if (rv!=AQH_MSGDATA_RESULT_SUCCESS) { DBG_ERROR(NULL, "Connect response: %d", rv); return 2; @@ -242,7 +242,7 @@ int AQH_ToolClient_Watch(AQH_OBJECT *o) return 2; } - rv=_exchangeConnect(o, xo, xo->flags); + rv=_exchangeConnect(xo, xo->flags); if (rv!=AQH_MSGDATA_RESULT_SUCCESS) { DBG_ERROR(NULL, "Connect response: %d", rv); return 2; @@ -291,15 +291,12 @@ int _sendWaitHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo) int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId) { - AQH_EVENT_LOOP *eventLoop; int first=1; - eventLoop=AQH_Object_GetEventLoop(o); - for (;;) { AQH_MESSAGE *msgIn; - msgIn=Utils2_WaitForResponseMsg(eventLoop, xo->ipcEndpoint, msgId, xo->timeoutInSeconds); + msgIn=AQH_IpcEndpoint_WaitForResponseMsg(xo->ipcEndpoint, msgId, xo->timeoutInSeconds); if (msgIn) { GWEN_TAG16_LIST *tagList; @@ -327,11 +324,8 @@ int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId) -int _exchangeConnect(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t flags) +int _exchangeConnect(AQH_TOOL_CLIENT *xo, uint32_t flags) { - AQH_EVENT_LOOP *eventLoop; - AQH_MESSAGE *msgOut; - uint32_t msgId; const char *clientId; const char *userId; const char *passw; @@ -340,43 +334,14 @@ int _exchangeConnect(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t flags) userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL); passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL); - eventLoop=AQH_Object_GetEventLoop(o); - msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint); - msgOut=AQH_IpcdMessageConnect_new(AQH_MSGTYPE_IPC_DATA_CONNECT_REQ, msgId, 0, clientId, userId, passw, flags); - AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut); - - for (;;) { - AQH_MESSAGE *msgIn; - - msgIn=Utils2_WaitForResponseMsg(eventLoop, xo->ipcEndpoint, msgId, xo->timeoutInSeconds); - if (msgIn) { - GWEN_TAG16_LIST *tagList; - - tagList=AQH_IpcMessageTag16_ParsePayload(msgIn, 0); - if (tagList) { - int code; - - code=AQH_IpcMessage_GetCode(msgIn); - if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - int result; - - result=AQH_IpcMessageResult_GetResult(tagList); - GWEN_Tag16_List_free(tagList); - AQH_Message_free(msgIn); - return result; - } - else { - DBG_ERROR(NULL, "Unexpected message received (%x)", code); - GWEN_Tag16_List_free(tagList); - AQH_Message_free(msgIn); - return AQH_MSGDATA_RESULT_ERROR_GENERIC; - } - GWEN_Tag16_List_free(tagList); - } - AQH_Message_free(msgIn); - } - } /* for */ - return AQH_MSGDATA_RESULT_ERROR_GENERIC; + return AQH_IpcEndpoint_ExchangeConnectMsg(xo->ipcEndpoint, + AQH_MSGTYPE_IPC_DATA_CONNECT_REQ, + AQH_MSGTYPE_IPC_DATA_RESULT, + clientId, + userId, + passw, + flags, + xo->timeoutInSeconds); } @@ -419,3 +384,4 @@ int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG } + diff --git a/apps/aqhome-tool/utils.c b/apps/aqhome-tool/utils.c index 872091f..6ffdbe7 100644 --- a/apps/aqhome-tool/utils.c +++ b/apps/aqhome-tool/utils.c @@ -215,42 +215,6 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, -AQH_MESSAGE *Utils2_WaitForResponseMsg(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *epTcp, uint32_t refMsgId, int timeoutInSeconds) -{ - time_t startTime; - - startTime=time(NULL); - - for (;;) { - AQH_MESSAGE *msg; - time_t now; - - AQH_EventLoop_Run(eventLoop, 500); - msg=AQH_Endpoint_GetNextMsgIn(epTcp); - if (msg) { - if (refMsgId==0 || refMsgId==AQH_IpcMessage_GetRefMsgId(msg)) - return msg; - else { - uint16_t code; - - code=AQH_IpcMessage_GetCode(msg); - DBG_ERROR(NULL, "Received unexpected message %d (%x), ignoring", code, code); - AQH_Message_free(msg); - } - } - - now=time(NULL); - if (now-startTime>timeoutInSeconds) { - DBG_INFO(NULL, "Timeout"); - break; - } - } - - return NULL; -} - - - GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds)