aqhome: started reworking message code to use gwen's new msgio code.
This commit is contained in:
165
aqhome/msg/endpointmgr.c
Normal file
165
aqhome/msg/endpointmgr.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
* 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/msg/endpointmgr_p.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msg/endpoint_node.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_INHERIT(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_ENDPOINT_MGR);
|
||||
|
||||
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
|
||||
static void _handleNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
|
||||
static void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
|
||||
static void _distributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *srcEp, const GWEN_MSG *msg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT_MGR *AQH_MsgEndpointMgr_new(uint8_t busAddr)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT_MGR *mgr;
|
||||
AQH_MSG_ENDPOINT_MGR *xmgr;
|
||||
|
||||
mgr=GWEN_MsgEndpointMgr_new();
|
||||
GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_MGR, xmgr);
|
||||
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_ENDPOINT_MGR, mgr, xmgr, _freeData);
|
||||
|
||||
xmgr->busAddr=busAddr;
|
||||
|
||||
return mgr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
{
|
||||
AQH_MSG_ENDPOINT_MGR *xmgr;
|
||||
|
||||
xmgr=(AQH_MSG_ENDPOINT_MGR*) p;
|
||||
GWEN_FREE_OBJECT(xmgr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _msgLoopOnce(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));
|
||||
_handleEndpoint(emgr, ep);
|
||||
ep=GWEN_MsgEndpoint_List_Next(ep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
switch(GWEN_MsgEndpoint_GetGroupId(ep)) {
|
||||
case AQH_MSG_ENDPOINTGROUP_NODE: _handleNodeEndpoint(emgr, ep); break;
|
||||
case AQH_MSG_ENDPOINTGROUP_IPC: _handleIpcEndpoint(emgr, ep); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
|
||||
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
|
||||
DBG_INFO(AQH_LOGDOMAIN,
|
||||
" - msg %d from %d to %d",
|
||||
AQH_NodeMsg_GetMsgType(msg), AQH_NodeMsg_GetSourceAddress(msg), AQH_NodeMsg_GetDestAddress(msg));
|
||||
_distributeMsgFromNodeEndpoint(emgr, ep, msg);
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
/* TODO: handle IPC messages */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _distributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *srcEp, const GWEN_MSG *msg)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT_LIST *endpointList;
|
||||
|
||||
endpointList=GWEN_MsgEndpointMgr_GetEndpointList(emgr);
|
||||
if (endpointList) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
int srcGroupId;
|
||||
uint32_t msgGroup;
|
||||
|
||||
msgGroup=AQH_NodeMsg_GetMsgGroup(AQH_NodeMsg_GetMsgType(msg));
|
||||
srcGroupId=GWEN_MsgEndpoint_GetGroupId(srcEp);
|
||||
|
||||
ep=GWEN_MsgEndpoint_List_First(endpointList);
|
||||
while(ep) {
|
||||
if (ep!=srcEp) {
|
||||
uint32_t acceptedGroupIds;
|
||||
uint32_t acceptedMsgGroups;
|
||||
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s", GWEN_MsgEndpoint_GetName(ep));
|
||||
acceptedGroupIds=AQH_NodeEndpoint_GetAcceptedMsgGroups(ep);
|
||||
acceptedMsgGroups=AQH_NodeEndpoint_GetAcceptedMsgGroups(ep);
|
||||
|
||||
if (
|
||||
!(GWEN_MsgEndpoint_GetFlags(ep) & AQH_MSGEP_NODE_FLAGS_NOMESSAGES) &&
|
||||
(acceptedMsgGroups & msgGroup) &&
|
||||
(acceptedGroupIds & srcGroupId)
|
||||
) {
|
||||
/* endpoint accepts this message */
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s accepts message", GWEN_MsgEndpoint_GetName(ep));
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, GWEN_Msg_dup(msg));
|
||||
}
|
||||
else {
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not accept message", GWEN_MsgEndpoint_GetName(ep));
|
||||
}
|
||||
}
|
||||
ep=GWEN_MsgEndpoint_List_Next(ep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user