aqhome: more work on transformation to event2/ipc2.
This commit is contained in:
@@ -21,6 +21,12 @@
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/endpoint_ipcclient.h"
|
||||
|
||||
#include "aqhome/msg/ipc/m_ipc.h"
|
||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||
#include "aqhome/ipc2/tcp_object.h"
|
||||
#include "aqhome/ipc2/ipc_client.h"
|
||||
|
||||
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
#include <gwenhywfar/endpoint_multilayer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
@@ -35,6 +41,46 @@
|
||||
|
||||
|
||||
|
||||
AQH_OBJECT *Utils2_SetupBrokerClientEndpoint(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbArgs, uint32_t flags)
|
||||
{
|
||||
const char *brokerAddress;
|
||||
int brokerPort;
|
||||
const char *brokerClientId;
|
||||
|
||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "brokerAddress", 0, NULL);
|
||||
if (!(brokerAddress && *brokerAddress))
|
||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/brokerAddress", 0, "127.0.0.1");
|
||||
|
||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "brokerPort", 0, -1);
|
||||
if (brokerPort<0)
|
||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/brokerPort", 0, 45456);
|
||||
|
||||
brokerClientId=GWEN_DB_GetCharValue(dbArgs, "brokerClientId", 0, "aqhome-tool");
|
||||
|
||||
if (brokerAddress && *brokerAddress && brokerPort) {
|
||||
AQH_OBJECT *ep;
|
||||
int fd;
|
||||
|
||||
fd=AQH_TcpObject_CreateConnectedSocket(brokerAddress, brokerPort);
|
||||
if (fd<0) {
|
||||
DBG_ERROR(NULL, "Error connecting to broker server %s:%d", brokerAddress, brokerPort);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ep=AQH_IpcClientObject_new(eventLoop, fd);
|
||||
assert(ep);
|
||||
AQH_Endpoint_AddFlags(ep, flags);
|
||||
return ep;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No server settings");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs, uint32_t flags)
|
||||
{
|
||||
const char *brokerAddress;
|
||||
@@ -172,6 +218,42 @@ 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==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_ERROR(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
|
||||
int msgCode,
|
||||
int timeoutInSeconds)
|
||||
@@ -559,4 +641,24 @@ AQH_DEVICE *Utils_DeviceFromArgs(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
|
||||
|
||||
void Utils_PrintValue(const AQH_VALUE *value, int printHeader)
|
||||
{
|
||||
uint64_t valueId;
|
||||
const char *valueName;
|
||||
const char *valueUnits;
|
||||
|
||||
valueId=AQH_Value_GetId(value);
|
||||
valueName=AQH_Value_GetNameForSystem(value);
|
||||
valueUnits=AQH_Value_GetValueUnits(value);
|
||||
|
||||
if (printHeader)
|
||||
fprintf(stdout, "ID\tName\tUnits\n");
|
||||
fprintf(stdout, "%lu\t%s\t%s\n",
|
||||
(unsigned long int) valueId,
|
||||
valueName?valueName:"",
|
||||
valueUnits?valueUnits:"");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user