Files
aqhomecontrol/aqhome/msgmanager.c
2023-03-18 23:25:21 +01:00

82 lines
1.9 KiB
C

/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 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 "aqhome/msgmanager.h"
#include "aqhome/msg/endpointmgr.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
void _loopOnceOverIpcEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr);
void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
GWEN_MSG_ENDPOINT_MGR *AQH_MsgManager_new(uint8_t busAddr)
{
return AQH_MsgEndpointMgr_new(busAddr);
}
int AQH_MsgManager_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr)
{
int rv;
rv=GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
AQH_MsgEndpointMgr_LoopOnceOverNodeEndpoints(emgr, AQH_MSGMGR_ENDPOINTGROUP_NODE);
_loopOnceOverIpcEndpoints(emgr);
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
return rv;
}
void _loopOnceOverIpcEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr)
{
GWEN_MSG_ENDPOINT_LIST *endpointList;
DBG_DEBUG(AQH_LOGDOMAIN, "Handle endpoint messages");
endpointList=GWEN_MsgEndpointMgr_GetEndpointList(emgr);
if (endpointList) {
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_MsgEndpoint_List_First(endpointList);
while(ep) {
DBG_DEBUG(AQH_LOGDOMAIN, "- endpoint(%s)", GWEN_MsgEndpoint_GetName(ep));
if (GWEN_MsgEndpoint_GetGroupId(ep)==AQH_MSGMGR_ENDPOINTGROUP_IPC)
_handleIpcEndpoint(emgr, ep);
ep=GWEN_MsgEndpoint_List_Next(ep);
}
}
}
void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
{
GWEN_MSG *msg;
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
/* exec IPC message */
GWEN_Msg_free(msg);
}
}