aqhome: completed adapting to msgio2 interface.
This commit is contained in:
118
apps/aqhomed/loop_tty_ipc.c
Normal file
118
apps/aqhomed/loop_tty_ipc.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
* 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 "./loop_tty_ipc.h"
|
||||
#include "./aqhomed_p.h"
|
||||
#include "./tty_log.h"
|
||||
#include "./tty_write.h"
|
||||
#include "./db.h"
|
||||
|
||||
#include "aqhome/msg/endpoint2_tty.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msg/msg_value2.h"
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_forward.h"
|
||||
#include "aqhome/ipc/msg_ipc_value.h"
|
||||
#include "aqhome/mqtt/endpoint2_mqttc.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endpoint2_tcpd.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defines
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define I18N(msg) msg
|
||||
#define I18S(msg) msg
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _forwardValue2MsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
|
||||
static void _forwardAnyMsgToIpc(GWEN_MSG_ENDPOINT2 *ep, const GWEN_MSG *nodeMsg);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AqHomed_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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user