aqhome: more work on transformation to event2/ipc2.

This commit is contained in:
Martin Preuss
2025-02-27 14:08:44 +01:00
parent bebc4c1b0d
commit d887747b3c
45 changed files with 2446 additions and 287 deletions

View File

@@ -19,6 +19,12 @@
#include "aqhome/ipc/data/msg_data_values.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/m_ipc_result.h"
#include "aqhome/msg/ipc/data/m_ipcd_values.h"
#include "aqhome/ipc2/endpoint.h"
#include <gwenhywfar/args.h>
#include <gwenhywfar/i18n.h>
#include <gwenhywfar/debug.h>
@@ -33,8 +39,6 @@
static int _doGetValues(GWEN_DB_NODE *dbArgs);
static uint32_t _sendRequest(GWEN_MSG_ENDPOINT *epTcp);
static int _handleResponses(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
@@ -110,6 +114,17 @@ int AQH_Tool_GetValues(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
I18S("Specify service password"),
I18S("Specify service password")
},
{
0, /* flags */
GWEN_ArgsType_Int, /* type */
"printHeader", /* name */
0, /* minnum */
1, /* maxnum */
"H", /* short option */
"printheader", /* long option */
I18S("Print header if given"),
I18S("Print header if given")
},
{
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
GWEN_ArgsType_Int, /* type */
@@ -154,112 +169,88 @@ int AQH_Tool_GetValues(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
int _doGetValues(GWEN_DB_NODE *dbArgs)
{
GWEN_MSG_ENDPOINT *epTcp;
AQH_EVENT_LOOP *eventLoop;
AQH_OBJECT *epTcp;
int timeoutInSeconds;
int printHeader;
AQH_MESSAGE *msgOut;
uint32_t msgId;
int rv;
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
printHeader=GWEN_DB_GetIntValue(dbArgs, "printHeader", 0, 0);
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs, 0);
eventLoop=AQH_EventLoop_new();
epTcp=Utils2_SetupBrokerClientEndpoint(eventLoop, dbArgs, 0);
if (epTcp==NULL) {
DBG_ERROR(NULL, "ERROR creating TCP connection");
AQH_EventLoop_free(eventLoop);
return 2;
}
msgId=_sendRequest(epTcp);
rv=_handleResponses(epTcp, msgId, timeoutInSeconds);
if (rv!=0) {
DBG_ERROR(NULL, "here (%d)", rv);
}
GWEN_MsgEndpoint_free(epTcp);
return rv;
}
msgId=AQH_Endpoint_GetNextMessageId(epTcp);
msgOut=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ,
msgId, 0,
0, NULL);
AQH_Endpoint_AddMsgOut(epTcp, msgOut);
uint32_t _sendRequest(GWEN_MSG_ENDPOINT *epTcp)
{
GWEN_MSG *msgOut;
uint32_t msgId;
msgId=GWEN_MsgEndpoint_GetNextMessageId(epTcp);
msgOut=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ,
msgId, 0,
0, NULL);
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
return msgId;
}
int _handleResponses(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds)
{
for (;;) {
GWEN_MSG *msg;
AQH_MESSAGE *msgIn;
uint16_t code;
msg=Utils_WaitForResponse(epTcp, msgId, timeoutInSeconds);
if (msg) {
uint16_t code;
msgIn=Utils2_WaitForResponseMsg(eventLoop, epTcp, msgId, timeoutInSeconds);
if (msgIn) {
GWEN_TAG16_LIST *tagList;
code=GWEN_IpcMsg_GetCode(msg);
if (code==AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP) {
AQH_VALUE_LIST *valueList;
code=AQH_IpcMessage_GetCode(msgIn);
tagList=AQH_IpcMessageTag16_ParsePayload(msgIn, 0);
if (tagList) {
if (code==AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP) {
AQH_VALUE_LIST *valueList;
AQH_ValuesDataIpcMsg_Parse(msg, 0);
valueList=AQH_ValuesDataIpcMsg_ReadValueList(msg);
if (valueList) {
AQH_VALUE *v;
valueList=AQH_IpcdMessageValues_ReadValueList(tagList);
if (valueList) {
AQH_VALUE *value;
v=AQH_Value_List_First(valueList);
while(v) {
uint64_t valueId;
const char *valueName;
const char *valueUnits;
valueId=AQH_Value_GetId(v);
valueName=AQH_Value_GetNameForSystem(v);
valueUnits=AQH_Value_GetValueUnits(v);
fprintf(stdout, "%lu\t%s\t%s\n",
(unsigned long int) valueId,
valueName?valueName:"",
valueUnits?valueUnits:"");
v=AQH_Value_List_Next(v);
value=AQH_Value_List_First(valueList);
while(value) {
Utils_PrintValue(value, printHeader);
printHeader=0;
value=AQH_Value_List_Next(value);
}
AQH_Value_List_free(valueList);
}
AQH_Value_List_free(valueList);
}
if (AQH_ValuesDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_VALUES_FLAGS_LASTMSG) {
DBG_INFO(NULL, "Last message received");
GWEN_Msg_free(msg);
break;
if (AQH_IpcdMessageValues_GetFlags(tagList) & AQH_MSGDATA_VALUES_FLAGS_LASTMSG) {
DBG_INFO(NULL, "Last message received");
GWEN_Tag16_List_free(tagList);
break;
}
}
}
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
uint32_t resultCode;
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
uint32_t resultCode;
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
fprintf(stderr, "ERROR: %d\n", resultCode);
GWEN_Msg_free(msg);
return 3;
resultCode=AQH_IpcMessageResult_GetResult(tagList);
fprintf(stderr, "ERROR: %d\n", resultCode);
GWEN_Tag16_List_free(tagList);
AQH_Object_free(epTcp);
AQH_EventLoop_free(eventLoop);
return 3;
}
else {
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
GWEN_Tag16_List_free(tagList);
AQH_Object_free(epTcp);
AQH_EventLoop_free(eventLoop);
return 3;
}
GWEN_Tag16_List_free(tagList);
}
else {
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
GWEN_Msg_free(msg);
return 3;
}
} /* if msg */
else {
DBG_ERROR(NULL, "No response received");
return 2;
}
} /* for */
AQH_Object_free(epTcp);
return 0;
}