diff --git a/aqhome/msg/endpointmgr.c b/aqhome/msg/endpointmgr.c index 972a81a..f7bdb08 100644 --- a/aqhome/msg/endpointmgr.c +++ b/aqhome/msg/endpointmgr.c @@ -27,11 +27,6 @@ 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 _distributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *srcEp, const GWEN_MSG *msg); - - @@ -62,55 +57,10 @@ void _freeData(void *bp, void *p) -int AQH_MsgEndpointMgr_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr, int groupId) -{ - int rv; - - rv=GWEN_MsgEndpointMgr_IoLoopOnce(emgr); - AQH_MsgEndpointMgr_LoopOnceOverNodeEndpoints(emgr, groupId); - GWEN_MsgEndpointMgr_RunAllEndpoints(emgr); - return rv; -} - - - -void AQH_MsgEndpointMgr_LoopOnceOverNodeEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr, int groupId) -{ - 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)==groupId) - _handleNodeEndpoint(emgr, ep); - ep=GWEN_MsgEndpoint_List_Next(ep); - } - } -} - - - -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 _distributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *srcEp, const GWEN_MSG *msg) +void AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, + GWEN_MSG_ENDPOINT *srcEp, + const GWEN_MSG *msg, + int groupId) { GWEN_MSG_ENDPOINT_LIST *endpointList; @@ -126,28 +76,31 @@ void _distributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOI ep=GWEN_MsgEndpoint_List_First(endpointList); while(ep) { if (ep!=srcEp) { - uint32_t acceptedMsgGroups; + if (srcGroupId & groupId) { + uint32_t acceptedMsgGroups; - acceptedMsgGroups=AQH_NodeEndpoint_GetAcceptedMsgGroups(ep); - DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s (msgGroup=%08x, accept: %08x, flags: %08x)", - GWEN_MsgEndpoint_GetName(ep), - msgGroup, acceptedMsgGroups, - GWEN_MsgEndpoint_GetFlags(ep)); + acceptedMsgGroups=AQH_NodeEndpoint_GetAcceptedMsgGroups(ep); + DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s (msgGroup=%08x, accept: %08x, flags: %08x)", + GWEN_MsgEndpoint_GetName(ep), + msgGroup, acceptedMsgGroups, + GWEN_MsgEndpoint_GetFlags(ep)); - if ( - !(GWEN_MsgEndpoint_GetFlags(ep) & AQH_MSGEP_NODE_FLAGS_NOMESSAGES) && - (msgGroup & acceptedMsgGroups) - ) { - /* endpoint accepts this message */ - DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s accepts message", GWEN_MsgEndpoint_GetName(ep)); - GWEN_MsgEndpoint_ProcessOutMessage(ep, GWEN_Msg_dup(msg)); - } + if (!(GWEN_MsgEndpoint_GetFlags(ep) & AQH_MSGEP_NODE_FLAGS_NOMESSAGES) && + (msgGroup & acceptedMsgGroups)) { + /* endpoint accepts this message */ + DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s accepts message", GWEN_MsgEndpoint_GetName(ep)); + GWEN_MsgEndpoint_ProcessOutMessage(ep, GWEN_Msg_dup(msg)); + } + else { + DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not accept message", GWEN_MsgEndpoint_GetName(ep)); + } + } /* if (srcGroupId & groupId) */ else { - DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not accept message", GWEN_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint does not contain groupId %d (%02x)", groupId, groupId); } - } + } /* if (ep!=srcEp) */ ep=GWEN_MsgEndpoint_List_Next(ep); - } + } /* while */ } } diff --git a/aqhome/msg/endpointmgr.h b/aqhome/msg/endpointmgr.h index 92c6ca7..7f0b97d 100644 --- a/aqhome/msg/endpointmgr.h +++ b/aqhome/msg/endpointmgr.h @@ -17,11 +17,11 @@ AQHOME_API GWEN_MSG_ENDPOINT_MGR *AQH_MsgEndpointMgr_new(uint8_t busAddr); -AQHOME_API int AQH_MsgEndpointMgr_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr, int groupId); - -AQHOME_API void AQH_MsgEndpointMgr_LoopOnceOverNodeEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr, int groupId); - +AQHOME_API void AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, + GWEN_MSG_ENDPOINT *srcEp, + const GWEN_MSG *msg, + int groupId); diff --git a/aqhome/msgmanager.c b/aqhome/msgmanager.c index 4f758c1..63be9ca 100644 --- a/aqhome/msgmanager.c +++ b/aqhome/msgmanager.c @@ -13,14 +13,17 @@ #include "aqhome/msgmanager.h" #include "aqhome/msg/endpointmgr.h" +#include "aqhome/msg/msg_node.h" #include #include -void _loopOnceOverIpcEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr); -void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep); +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); @@ -38,15 +41,14 @@ 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); + _loopOnceOverEndpoints(emgr); GWEN_MsgEndpointMgr_RunAllEndpoints(emgr); return rv; } -void _loopOnceOverIpcEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr) +void _loopOnceOverEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr) { GWEN_MSG_ENDPOINT_LIST *endpointList; @@ -57,25 +59,53 @@ void _loopOnceOverIpcEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr) 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); + _handleEndpoint(emgr, ep); ep=GWEN_MsgEndpoint_List_Next(ep); - } + } /* while */ } } -void _handleIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep) +void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep) { GWEN_MSG *msg; while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) { - /* exec IPC message */ + 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 */ +} + + + + +