aqhome: more work on transformation to event2/ipc2.
This commit is contained in:
@@ -19,6 +19,12 @@
|
||||
#include "aqhome/ipc/data/msg_data_devices.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_devices.h"
|
||||
#include "aqhome/ipc2/endpoint.h"
|
||||
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/i18n.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
@@ -33,7 +39,6 @@
|
||||
|
||||
|
||||
static int _doGetDevices(GWEN_DB_NODE *dbArgs);
|
||||
static void _sendCommand(GWEN_MSG_ENDPOINT *epTcp);
|
||||
|
||||
|
||||
|
||||
@@ -164,88 +169,91 @@ int AQH_Tool_GetDevices(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
|
||||
int _doGetDevices(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
AQH_OBJECT *epTcp;
|
||||
int timeoutInSeconds;
|
||||
GWEN_MSG *msg;
|
||||
int printHeader;
|
||||
AQH_MESSAGE *msgOut;
|
||||
uint32_t msgId;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*fprintf(stdout, "Sending GetDevices request\n");*/
|
||||
|
||||
_sendCommand(epTcp);
|
||||
msgId=AQH_Endpoint_GetNextMessageId(epTcp);
|
||||
msgOut=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ,
|
||||
msgId, 0,
|
||||
0, NULL);
|
||||
AQH_Endpoint_AddMsgOut(epTcp, msgOut);
|
||||
|
||||
for (;;) {
|
||||
AQH_MESSAGE *msgIn;
|
||||
uint16_t code;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP) {
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
msgIn=Utils2_WaitForResponseMsg(eventLoop, epTcp, msgId, timeoutInSeconds);
|
||||
if (msgIn) {
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
AQH_DevicesDataIpcMsg_Parse(msg, 0);
|
||||
deviceList=AQH_DevicesDataIpcMsg_ReadDeviceList(msg);
|
||||
if (deviceList) {
|
||||
AQH_DEVICE *device;
|
||||
code=AQH_IpcMessage_GetCode(msgIn);
|
||||
tagList=AQH_IpcMessageTag16_ParsePayload(msgIn, 0);
|
||||
if (tagList) {
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP) {
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
Utils_PrintDevice(device, printHeader);
|
||||
printHeader=0;
|
||||
device=AQH_Device_List_Next(device);
|
||||
deviceList=AQH_IpcdMessageDevices_ReadDeviceList(tagList);
|
||||
if (deviceList) {
|
||||
AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
Utils_PrintDevice(device, printHeader);
|
||||
printHeader=0;
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
AQH_Device_List_free(deviceList);
|
||||
}
|
||||
|
||||
DBG_ERROR(NULL, "Flags: %08x", AQH_IpcdMessageDevices_GetFlags(tagList));
|
||||
if (AQH_IpcdMessageDevices_GetFlags(tagList) & AQH_MSGDATA_DEVICES_FLAGS_LASTMSG) {
|
||||
DBG_ERROR(NULL, "Last message received");
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
AQH_Device_List_free(deviceList);
|
||||
}
|
||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||
uint32_t resultCode;
|
||||
|
||||
if (AQH_DevicesDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_DEVICES_FLAGS_LASTMSG) {
|
||||
DBG_INFO(NULL, "Last message received");
|
||||
break;
|
||||
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 if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||
uint32_t resultCode;
|
||||
|
||||
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
||||
fprintf(stderr, "ERROR: %d\n", resultCode);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return 3;
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return 3;
|
||||
}
|
||||
} /* for */
|
||||
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
AQH_Object_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _sendCommand(GWEN_MSG_ENDPOINT *epTcp)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
msgOut=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
||||
0, NULL);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user