aqhome: completed adapting to msgio2 interface.

This commit is contained in:
Martin Preuss
2023-07-12 13:33:04 +02:00
parent 39987b31c7
commit 08c3875a26
66 changed files with 1765 additions and 3914 deletions

View File

@@ -12,6 +12,8 @@
#include "./loop.h"
#include "./loop_tty.h"
#include "./loop_ipc.h"
#include "./aqhomed_p.h"
#include "./tty_log.h"
#include "./tty_write.h"
@@ -47,11 +49,6 @@
* ------------------------------------------------------------------------------------------------
*/
static void _readTtyMessages(AQHOMED *aqh);
static void _handleTtyMsg(AQHOMED *aqh, const GWEN_MSG *msg);
static void _forwardTtyMsgToIpcClients(AQHOMED *aqh, const GWEN_MSG *msg);
static void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
static void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
@@ -64,7 +61,8 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs)
{
if (aqh) {
GWEN_MsgEndpoint2_ChildrenIoLoop(aqh->rootEndpoint, timeoutInMsecs);
_readTtyMessages(aqh);
AqHomed_ReadAndHandleTtyMessages(aqh);
AqHomed_ReadAndHandleIpcMessages(aqh);
if (AQH_NodeDb_IsModified(aqh->nodeDb)) {
if (aqh->dbFile) {
@@ -81,88 +79,3 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs)
void _readTtyMessages(AQHOMED *aqh)
{
GWEN_MSG *msg;
while( (msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(aqh->ttyEndpoint)) ) {
_handleTtyMsg(aqh, msg);
GWEN_Msg_free(msg);
}
}
void _handleTtyMsg(AQHOMED *aqh, const GWEN_MSG *msg)
{
if (aqh->logFile)
AqHomed_LogTtyMsg(aqh, msg);
if (aqh->writeFolder)
AqHomed_WriteTtyMsg(aqh, msg);
if (aqh->nodeDb)
AqHomed_NodeMsgToDb(aqh, msg);
if (aqh->ipcdEndpoint)
_forwardTtyMsgToIpcClients(aqh, msg);
}
void _forwardTtyMsgToIpcClients(AQHOMED *aqh, const GWEN_MSG *msg)
{
uint32_t msgGroup;
msgGroup=AQH_NodeMsg_GetMsgGroup(AQH_NodeMsg_GetMsgType(msg));
if (msgGroup) {
GWEN_MSG_ENDPOINT2 *ep;
ep=GWEN_MsgEndpoint2_Tree2_GetFirstChild(aqh->ipcdEndpoint);
while(ep) {
if (msgGroup & AQH_IpcEndpoint2_GetAcceptedMsgGroups(ep)) {
DBG_INFO(NULL, "Endpoint accepts msg group %d", msgGroup);
switch(AQH_NodeMsg_GetMsgType(msg)) {
case AQH_MSG_TYPE_VALUE2:
_forwardValue2MsgToIpc(ep, msg);
break;
default:
_forwardAnyMsgToIpc(ep, msg);
break;
}
}
ep=GWEN_MsgEndpoint2_Tree2_GetNext(ep);
}
}
else {
DBG_ERROR(NULL, "Message type %d not in any message group, ignoring message", AQH_NodeMsg_GetMsgType(msg));
}
}
void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
ipcMsg=AQH_ValueIpcMsg_new(AQH_MSGTYPE_IPC_VALUE,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
AQH_Value2Msg_GetValueType(nodeMsg),
AQH_Value2Msg_GetValueNom(nodeMsg),
AQH_Value2Msg_GetValueDenom(nodeMsg));
GWEN_MsgEndpoint2_AddSendMessage(ep, ipcMsg);
}
void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
ipcMsg=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(nodeMsg), GWEN_Msg_GetBytesInBuffer(nodeMsg));
GWEN_MsgEndpoint2_AddSendMessage(ep, ipcMsg);
}