more work on new events2-based apps.
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
r_connect.h
|
r_connect.h
|
||||||
r_forward.h
|
r_forward.h
|
||||||
r_setaccmsggrps.h
|
r_setaccmsggrps.h
|
||||||
|
r_getnodes.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
<sources>
|
<sources>
|
||||||
@@ -55,6 +56,7 @@
|
|||||||
r_connect.c
|
r_connect.c
|
||||||
r_forward.c
|
r_forward.c
|
||||||
r_setaccmsggrps.c
|
r_setaccmsggrps.c
|
||||||
|
r_getnodes.c
|
||||||
main.c
|
main.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ void AQH_NodeServer_HandleConnect(GWEN_UNUSED AQH_OBJECT *o, AQH_OBJECT *ep, con
|
|||||||
AQH_IpcMessage_GetMsgId(msg),
|
AQH_IpcMessage_GetMsgId(msg),
|
||||||
resultCode, NULL);
|
resultCode, NULL);
|
||||||
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||||
|
DBG_ERROR(NULL, "Client connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
77
apps/aqhome-nodes/r_getnodes.c
Normal file
77
apps/aqhome-nodes/r_getnodes.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "./r_getnodes.h"
|
||||||
|
#include "./server_p.h"
|
||||||
|
#include "aqhome/ipc2/endpoint.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* code
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
void AQH_NodeServer_HandleGetNodes(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg)
|
||||||
|
{
|
||||||
|
AQH_NODE_SERVER *xo;
|
||||||
|
|
||||||
|
xo=AQH_NodeServer_GetServerData(o);
|
||||||
|
if (xo) {
|
||||||
|
AQH_NODE_INFO_LIST *nodeInfoList;
|
||||||
|
|
||||||
|
nodeInfoList=AQH_NodeDb_GetAllNodeInfos(xo->nodeDb);
|
||||||
|
if (nodeInfoList && AQH_NodeInfo_List_GetCount(nodeInfoList)) {
|
||||||
|
const AQH_NODE_INFO *ni;
|
||||||
|
|
||||||
|
ni=AQH_NodeInfo_List_First(nodeInfoList);
|
||||||
|
while(ni) {
|
||||||
|
const AQH_NODE_INFO *niNext;
|
||||||
|
AQH_MESSAGE *outMsg;
|
||||||
|
|
||||||
|
niNext=AQH_NodeInfo_List_Next(ni);
|
||||||
|
DBG_INFO(AQH_LOGDOMAIN, "Sending response for node %02x (%08x)", AQH_NodeInfo_GetBusAddress(ni), AQH_NodeInfo_GetUid(ni));
|
||||||
|
outMsg=AQH_IpcnMessageGetDevicesRsp_new(AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP,
|
||||||
|
AQH_Endpoint_GetNextMessageId(ep), AQH_IpcMessage_GetMsgId(msg),
|
||||||
|
niNext?0:AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG, ni);
|
||||||
|
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||||
|
DBG_ERROR(NULL, "Messages in clients out queue: %d", AQH_Message_List_GetCount(AQH_Endpoint_GetMsgOutList(ep)));
|
||||||
|
ni=niNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AQH_MESSAGE *outMsg;
|
||||||
|
|
||||||
|
DBG_INFO(AQH_LOGDOMAIN, "No nodes");
|
||||||
|
outMsg=AQH_IpcMessageResult_new(AQH_IPC_PROTOCOL_NODES_ID,
|
||||||
|
AQH_IPC_PROTOCOL_NODES_VERSION,
|
||||||
|
AQH_MSGTYPE_IPC_NODES_RESULT,
|
||||||
|
AQH_Endpoint_GetNextMessageId(ep),
|
||||||
|
AQH_IpcMessage_GetMsgId(msg),
|
||||||
|
AQH_MSGDATA_RESULT_ERROR_NODATA, NULL);
|
||||||
|
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
27
apps/aqhome-nodes/r_getnodes.h
Normal file
27
apps/aqhome-nodes/r_getnodes.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQHOMED_R_GETNODES_H
|
||||||
|
#define AQHOMED_R_GETNODES_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "./server.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/tag16.h>
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_NodeServer_HandleGetNodes(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "./r_connect.h"
|
#include "./r_connect.h"
|
||||||
#include "./r_forward.h"
|
#include "./r_forward.h"
|
||||||
#include "./r_setaccmsggrps.h"
|
#include "./r_setaccmsggrps.h"
|
||||||
|
#include "./r_getnodes.h"
|
||||||
|
|
||||||
#include <aqhome/aqhome.h>
|
#include <aqhome/aqhome.h>
|
||||||
#include <aqhome/ipc2/ipc_endpoint.h>
|
#include <aqhome/ipc2/ipc_endpoint.h>
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
#include <gwenhywfar/args.h>
|
||||||
#include <gwenhywfar/misc.h>
|
#include <gwenhywfar/misc.h>
|
||||||
|
#include <gwenhywfar/gwentime.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -758,16 +760,15 @@ void _handleMsgFromClient(GWEN_UNUSED AQH_OBJECT *o, GWEN_UNUSED AQH_NODE_SERVER
|
|||||||
GWEN_TAG16_LIST *tagList;
|
GWEN_TAG16_LIST *tagList;
|
||||||
|
|
||||||
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
||||||
if (tagList) {
|
DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code);
|
||||||
DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code);
|
switch(code) {
|
||||||
switch(code) {
|
case AQH_MSGTYPE_IPC_NODES_CONNECT_REQ: AQH_NodeServer_HandleConnect(o, ep, msg, tagList); break;
|
||||||
case AQH_MSGTYPE_IPC_NODES_CONNECT_REQ: AQH_NodeServer_HandleConnect(o, ep, msg, tagList); break;
|
case AQH_MSGTYPE_IPC_NODES_FORWARD: AQH_NodeServer_HandleForward(o, ep, msg, tagList); break;
|
||||||
case AQH_MSGTYPE_IPC_NODES_FORWARD: AQH_NodeServer_HandleForward(o, ep, msg, tagList); break;
|
case AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS: AQH_NodeServer_HandleSetAccMsgGrps(o, ep, msg, tagList); break;
|
||||||
case AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS: AQH_NodeServer_HandleSetAccMsgGrps(o, ep, msg, tagList); break;
|
case AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ: AQH_NodeServer_HandleGetNodes(o, ep, msg); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
|
||||||
GWEN_Tag16_List_free(tagList);
|
|
||||||
}
|
}
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_ERROR(NULL, "Invalid IPC protocol %d (%02x)", protoId, protoId);
|
DBG_ERROR(NULL, "Invalid IPC protocol %d (%02x)", protoId, protoId);
|
||||||
@@ -1016,8 +1017,13 @@ void _writeTtyMsgToLogFile(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
|||||||
{
|
{
|
||||||
if (xo->logFile) {
|
if (xo->logFile) {
|
||||||
GWEN_BUFFER *dbuf;
|
GWEN_BUFFER *dbuf;
|
||||||
|
GWEN_TIME *ti;
|
||||||
|
|
||||||
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||||
|
ti=GWEN_CurrentTime();
|
||||||
|
GWEN_Time_toString(ti, "YYYY-MM-DD hh:mm:ss ", dbuf);
|
||||||
|
GWEN_Time_free(ti);
|
||||||
|
ti=NULL;
|
||||||
AQH_NodeMessage_DumpSpecificToBuffer(msg, dbuf, "received");
|
AQH_NodeMessage_DumpSpecificToBuffer(msg, dbuf, "received");
|
||||||
_writeToLogFile(xo->logFile, GWEN_Buffer_GetStart(dbuf));
|
_writeToLogFile(xo->logFile, GWEN_Buffer_GetStart(dbuf));
|
||||||
GWEN_Buffer_free(dbuf);
|
GWEN_Buffer_free(dbuf);
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ int AQH_ToolClient_Run(AQH_OBJECT *o)
|
|||||||
if (xo) {
|
if (xo) {
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
rv=AQH_ToolClient_Connect(o, 0, xo->flags, 0);
|
rv=AQH_ToolClient_Connect(o, xo->flags, 0, 0);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_ERROR(NULL, "Error connecting (%d)", rv);
|
DBG_ERROR(NULL, "Error connecting (%d)", rv);
|
||||||
return 2;
|
return 2;
|
||||||
@@ -397,6 +397,7 @@ int _exchangeConnectMsgs(AQH_TOOL_CLIENT *xo, uint32_t flags)
|
|||||||
userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL);
|
userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL);
|
||||||
passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL);
|
passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL);
|
||||||
|
|
||||||
|
DBG_ERROR(NULL, "Sending connect message for proto=%d.%d", xo->protoId, xo->protoVer);
|
||||||
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||||
msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer,
|
msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer,
|
||||||
AQH_MSGTYPE_IPC_CONNECT_REQ,
|
AQH_MSGTYPE_IPC_CONNECT_REQ,
|
||||||
@@ -492,7 +493,7 @@ AQH_MESSAGE *AQH_ToolClient_WaitForNodeMsg(AQH_OBJECT *o, int nodeSrcAddr, uint8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_ERROR(NULL, "Received unexpected message %d (%x), ignoring", code, code);
|
DBG_INFO(NULL, "Received unexpected message %d (%x), ignoring", code, code);
|
||||||
}
|
}
|
||||||
GWEN_Tag16_List_free(tagList);
|
GWEN_Tag16_List_free(tagList);
|
||||||
}
|
}
|
||||||
@@ -543,7 +544,6 @@ int _sendWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
|
||||||
return _waitAndHandle(o, xo, msgId);
|
return _waitAndHandle(o, xo, msgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,7 +630,7 @@ int _nodesWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
|||||||
if (msgIn) {
|
if (msgIn) {
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
DBG_ERROR(NULL, "Handling node message %d", AQH_NodeMessage_GetMsgType(msgIn));
|
DBG_INFO(NULL, "Handling node message %d", AQH_NodeMessage_GetMsgType(msgIn));
|
||||||
rv=_handleNodeResponseMessage(o, msgIn, first);
|
rv=_handleNodeResponseMessage(o, msgIn, first);
|
||||||
AQH_Message_free(msgIn);
|
AQH_Message_free(msgIn);
|
||||||
first=0;
|
first=0;
|
||||||
@@ -639,7 +639,7 @@ int _nodesWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
else if (rv==1) {
|
else if (rv==1) {
|
||||||
DBG_ERROR(NULL, "Done.");
|
DBG_INFO(NULL, "Done.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ int AQH_Tool_GetNodes(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetFlags(o, AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG | AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG);
|
AQH_ToolClient_SetFlags(o, AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG);
|
||||||
AQH_ToolClient_SetAcceptedGroups(o, AQH_MSG_TYPEGROUP_ALL);
|
|
||||||
|
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
@@ -141,7 +140,7 @@ void _printNode(const AQH_NODE_INFO *ni)
|
|||||||
uint32_t u;
|
uint32_t u;
|
||||||
const GWEN_TIMESTAMP *ts;
|
const GWEN_TIMESTAMP *ts;
|
||||||
|
|
||||||
fprintf(stdout, "- node: addr=%d, uid=0x%08x, device=",
|
fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=",
|
||||||
AQH_NodeInfo_GetBusAddress(ni),
|
AQH_NodeInfo_GetBusAddress(ni),
|
||||||
(unsigned int) AQH_NodeInfo_GetUid(ni));
|
(unsigned int) AQH_NodeInfo_GetUid(ni));
|
||||||
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
|
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, GWEN_UNUSED co
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_ERROR(NULL, "Unexpected message \"%d\"", code);
|
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ int _handleMsgSent(AQH_OBJECT *o)
|
|||||||
if (xo) {
|
if (xo) {
|
||||||
AQH_MESSAGE *msg;
|
AQH_MESSAGE *msg;
|
||||||
|
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "Messages in outlist: %d", AQH_Message_List_GetCount(xo->msgOutList));
|
DBG_ERROR(AQH_LOGDOMAIN, "Messages in outlist: %d", AQH_Message_List_GetCount(xo->msgOutList));
|
||||||
msg=AQH_Message_List_First(xo->msgOutList);
|
msg=AQH_Message_List_First(xo->msgOutList);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
/* remove sent message from list */
|
/* remove sent message from list */
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_
|
|||||||
AQH_MESSAGE *msg;
|
AQH_MESSAGE *msg;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
AQH_EventLoop_Run(AQH_Object_GetEventLoop(ipcEndpoint), 500);
|
while( (msg=AQH_Endpoint_GetNextMsgIn(ipcEndpoint)) ) {
|
||||||
msg=AQH_Endpoint_GetNextMsgIn(ipcEndpoint);
|
|
||||||
if (msg) {
|
|
||||||
if (refMsgId==0 || refMsgId==AQH_IpcMessage_GetRefMsgId(msg))
|
if (refMsgId==0 || refMsgId==AQH_IpcMessage_GetRefMsgId(msg))
|
||||||
return msg;
|
return msg;
|
||||||
else {
|
else {
|
||||||
@@ -91,6 +89,7 @@ AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_
|
|||||||
DBG_INFO(NULL, "Timeout");
|
DBG_INFO(NULL, "Timeout");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
AQH_EventLoop_Run(AQH_Object_GetEventLoop(ipcEndpoint), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject)
|
|||||||
|
|
||||||
if (xo->bytesLeft) {
|
if (xo->bytesLeft) {
|
||||||
if (!(xo->flags & AQH_MSGWRITER_FLAGS_MSGSTARTED)) {
|
if (!(xo->flags & AQH_MSGWRITER_FLAGS_MSGSTARTED)) {
|
||||||
DBG_ERROR(NULL, "Starting message");
|
DBG_INFO(NULL, "Starting message");
|
||||||
rv=_startMsg(xo, fdObject);
|
rv=_startMsg(xo, fdObject);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
if (rv==GWEN_ERROR_TRY_AGAIN) {
|
if (rv==GWEN_ERROR_TRY_AGAIN) {
|
||||||
@@ -167,7 +167,7 @@ int _handleSocketReady(AQH_OBJECT *o, AQH_OBJECT *fdObject)
|
|||||||
const uint8_t *msgPtr;
|
const uint8_t *msgPtr;
|
||||||
|
|
||||||
_endMsg(xo, fdObject);
|
_endMsg(xo, fdObject);
|
||||||
DBG_ERROR(NULL, "Ended message");
|
DBG_INFO(NULL, "Ended message");
|
||||||
msgPtr=xo->msgBufPtr;
|
msgPtr=xo->msgBufPtr;
|
||||||
msgLen=xo->msgBufLen;
|
msgLen=xo->msgBufLen;
|
||||||
_resetBuffer(o);
|
_resetBuffer(o);
|
||||||
|
|||||||
Reference in New Issue
Block a user