112 lines
2.7 KiB
C
112 lines
2.7 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 "aqhome/msg/msg_node.h"
|
|
|
|
#include <gwenhywfar/misc.h>
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
static void _loopOnceOverEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr);
|
|
static void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
|
|
static void _handleNodeMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
|
static void _handleIpcMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
_loopOnceOverEndpoints(emgr);
|
|
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
void _loopOnceOverEndpoints(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) {
|
|
_handleEndpoint(emgr, ep);
|
|
ep=GWEN_MsgEndpoint_List_Next(ep);
|
|
} /* while */
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
|
|
{
|
|
GWEN_MSG *msg;
|
|
|
|
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
|
|
int groupId;
|
|
|
|
groupId=GWEN_Msg_GetGroupId(msg);
|
|
switch(groupId) {
|
|
case AQH_MSGMGR_ENDPOINTGROUP_NODE: _handleNodeMsg(emgr, ep, msg); break;
|
|
case AQH_MSGMGR_ENDPOINTGROUP_IPC: _handleIpcMsg(emgr, ep, msg); break;
|
|
default:
|
|
DBG_ERROR(AQH_LOGDOMAIN, "unhandled groupId %d (%02x), ignoring message", groupId, groupId);
|
|
break;
|
|
}
|
|
|
|
GWEN_Msg_free(msg);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _handleNodeMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
|
{
|
|
DBG_INFO(AQH_LOGDOMAIN,
|
|
" - msg %d from %d to %d",
|
|
AQH_NodeMsg_GetMsgType(msg), AQH_NodeMsg_GetSourceAddress(msg), AQH_NodeMsg_GetDestAddress(msg));
|
|
|
|
AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(emgr, ep, msg, AQH_MSGMGR_ENDPOINTGROUP_NODE);
|
|
}
|
|
|
|
|
|
|
|
void _handleIpcMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
|
{
|
|
/* exec IPC message */
|
|
}
|
|
|
|
|
|
|
|
|
|
|