aqhome: completed adapting to msgio2 interface.

This commit is contained in:
Martin Preuss
2023-07-12 13:33:04 +02:00
parent 39987b31c7
commit 08c3875a26
66 changed files with 1765 additions and 3914 deletions

View File

@@ -13,10 +13,11 @@
#include "./utils.h"
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
#include "aqhome/ipc/endpoint2_ipc.h"
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include <gwenhywfar/endpoint2_tcpc.h>
#include <gwenhywfar/debug.h>
#include <time.h>
@@ -25,28 +26,35 @@
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_DB_NODE *dbArgs)
GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT *epTcp;
GWEN_MSG_ENDPOINT2 *epTcp;
const char *tcpAddress;
int tcpPort;
int rv;
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "tcpAddress", 0, "127.0.0.1");
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, 45454);
DBG_INFO(NULL, "Setup tcp client endpoint to %s:%d", tcpAddress, tcpPort);
epTcp=AQH_IpcTcpClientEndpoint_new(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
epTcp=AQH_IpcEndpoint2_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
if (epTcp==NULL) {
DBG_ERROR(NULL, "Error creating endpoint TCPc");
return NULL;
}
rv=GWEN_TcpcEndpoint2_StartConnect(epTcp);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_ERROR(NULL, "Error connecting (%d)", rv);
GWEN_MsgEndpoint2_free(epTcp);
return NULL;
}
return epTcp;
}
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
int msgCode,
int nodeAddr,
int timeoutInSeconds)
@@ -59,9 +67,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
if (msg) {
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_FORWARD) {
GWEN_MSG *nodeMsg;
@@ -79,6 +86,9 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
}
}
}
else {
DBG_INFO(NULL, "Received IPC message %d, ignoring", GWEN_IpcMsg_GetCode(msg));
}
GWEN_Msg_free(msg);
}
now=time(NULL);
@@ -93,7 +103,7 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
int msgCode,
int timeoutInSeconds)
{
@@ -105,9 +115,8 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
if (msg) {
uint16_t code;
@@ -134,17 +143,16 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
{
time_t startTime;
startTime=time(NULL);
while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) {
while(GWEN_MsgEndpoint2_HaveMessageToSend(epTcp)) {
time_t now;
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
now=time(NULL);
if (now-startTime>timeoutInSeconds) {
DBG_INFO(NULL, "Timeout");
@@ -157,7 +165,7 @@ int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *e
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups)
{
GWEN_MSG *msgOut;
@@ -166,7 +174,7 @@ int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
return 0;
}