More work on IPC code, added aqhomed daemon.

This commit is contained in:
Martin Preuss
2023-03-18 23:25:21 +01:00
parent c26119d34c
commit d1c21322b8
23 changed files with 1127 additions and 61 deletions

84
aqhome/ipc/0BUILD Normal file
View File

@@ -0,0 +1,84 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhipc" >
<includes type="c" >
$(gwenhywfar_cflags)
-I$(topsrcdir)
-I$(topbuilddir)
</includes>
<includes type="tm2" >
--include=$(builddir)
--include=$(srcdir)
</includes>
<define name="BUILDING_AQHOME" />
<setVar name="local/cflags">$(visibility_cflags)</setVar>
<setVar name="tm2flags" >
--api=AQHOME_API
</setVar>
<setVar name="local/typefiles" >
</setVar>
<setVar name="local/built_sources" >
</setVar>
<setVar name="local/built_headers_pub">
</setVar>
<setVar name="local/built_headers_priv" >
</setVar>
<headers dist="false" install="$(pkgincludedir)/ipc" >
$(local/built_headers_pub)
</headers>
<headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint_node_ipc.h
endpoint_node_ipc_tcp.h
msg_ipc.h
msg_forward.h
</headers>
<headers dist="true" >
</headers>
<sources>
$(local/typefiles)
endpoint_node_ipc.c
endpoint_node_ipc_tcp.c
msg_ipc.c
msg_forward.c
</sources>
<extradist>
</extradist>
<useTargets>
</useTargets>
<subdirs>
</subdirs>
</target>
</gwbuild>

View File

@@ -0,0 +1,64 @@
/****************************************************************************
* 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/ipc/endpoint_node_ipc.h"
#include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/ipc/msg_forward.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/gwentime.h>
#include <gwenhywfar/endpoint_ipc.h>
#define AQH_MSG_ENDPOINT_NODEIPC_NAME "nodeipc"
static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *m);
GWEN_MSG_ENDPOINT *AQH_IpcNodeEndpoint_new(const char *name, int groupId)
{
int fd;
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_IpcEndpoint_new(name?name:AQH_MSG_ENDPOINT_NODEIPC_NAME, groupId);
AQH_NodeEndpoint_Extend(ep);
GWEN_MsgEndpoint_SetProcessOutMsgFn(ep, _processOutMessage);
AQH_NodeEndpoint_SetAcceptedMsgGroups(ep, AQH_MSG_TYPEGROUP_ALL);
return ep;
}
void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
ipcMsg=AQH_ForwardMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(nodeMsg), GWEN_Msg_GetBytesInBuffer(nodeMsg));
GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg);
GWEN_Msg_free(nodeMsg);
}

View File

@@ -0,0 +1,24 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_NODE_IPC_H
#define AQH_ENDPOINT_NODE_IPC_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint.h>
AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcNodeEndpoint_new(const char *name, int groupId);
AQHOME_API int AQH_IpcNodeEndpointMgr_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr);
#endif

View File

@@ -0,0 +1,63 @@
/****************************************************************************
* 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/ipc/endpoint_node_ipc_tcp.h"
#include "aqhome/ipc/endpoint_node_ipc.h"
#include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/ipc/msg_forward.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/gwentime.h>
#include <gwenhywfar/endpoint_ipc_tcp.h>
#define AQH_MSG_ENDPOINT_NODEIPCTCP_NAME "nodeipctcp"
static GWEN_MSG_ENDPOINT *_createChild(GWEN_MSG_ENDPOINT *ep);
GWEN_MSG_ENDPOINT *AQH_TcpIpcNodeEndpoint_new(const char *name, const char *host, int port, int groupId)
{
int fd;
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_TcpIpcEndpoint_new(name?name:AQH_MSG_ENDPOINT_NODEIPCTCP_NAME, host, port, groupId);
GWEN_MsgEndpoint_AddFlags(ep, AQH_MSGEP_NODE_FLAGS_NOMESSAGES);
GWEN_MsgEndpoint_SetCreateChildFn(ep, _createChild);
return ep;
}
GWEN_MSG_ENDPOINT *_createChild(GWEN_MSG_ENDPOINT *ep)
{
DBG_INFO(AQH_LOGDOMAIN, "Creating child endpoint for %s", GWEN_MsgEndpoint_GetName(ep));
return AQH_IpcNodeEndpoint_new(NULL, GWEN_MsgEndpoint_GetGroupId(ep));
}

View File

@@ -0,0 +1,22 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_ENDPOINT_NODE_IPC_TCP_H
#define AQH_ENDPOINT_NODE_IPC_TCP_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint_ipc_tcp.h>
AQHOME_API GWEN_MSG_ENDPOINT *AQH_TcpIpcNodeEndpoint_new(const char *name, const char *host, int port, int groupId);
#endif

82
aqhome/ipc/msg_forward.c Normal file
View File

@@ -0,0 +1,82 @@
/****************************************************************************
* 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/ipc/msg_forward.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/msg_ipc.h>
GWEN_MSG *AQH_ForwardMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len)
{
return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_ID, AQH_IPC_PROTOCOL_VERSION, code, len, ptr);
}
const uint8_t *AQH_ForwardMsg_GetMsgPtr(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE)
return GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_FORWARD_MSG;
return NULL;
}
uint32_t AQH_ForwardMsg_GetMsgLen(const GWEN_MSG *msg)
{
uint32_t len;
len=GWEN_Msg_GetBytesInBuffer(msg);
if (len>AQH_MSG_FORWARD_MINSIZE) {
return len-AQH_MSG_OFFS_FORWARD_MSG;
}
return 0;
}
void AQH_ForwardMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) {
const uint8_t *ptr;
uint32_t len;
ptr=AQH_ForwardMsg_GetMsgPtr(msg);
len=AQH_ForwardMsg_GetMsgLen(msg);
GWEN_Buffer_AppendArgs(dbuf, "FORWARD (code=%d, protocol=%d, protocol version=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg));
if (ptr && len) {
GWEN_Text_DumpString2Buffer(ptr, len, dbuf, 2);
GWEN_Buffer_AppendByte(dbuf, '\n');
}
}
}

37
aqhome/ipc/msg_forward.h Normal file
View File

@@ -0,0 +1,37 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_FORWARD_H
#define AQH_MSG_FORWARD_H
#include <aqhome/api.h>
#include <aqhome/ipc/msg_ipc.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSG_OFFS_FORWARD_MSG (GWEN_MSGIPC_OFFS_PAYLOAD+0)
#define AQH_MSG_FORWARD_MINSIZE (AQH_MSG_OFFS_FORWARD_MSG+AQH_MSG_OFFS_ALL_DATA_BEGIN)
AQHOME_API GWEN_MSG *AQH_ForwardMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len);
AQHOME_API const uint8_t *AQH_ForwardMsg_GetMsgPtr(const GWEN_MSG *msg);
AQHOME_API uint32_t AQH_ForwardMsg_GetMsgLen(const GWEN_MSG *msg);
AQHOME_API void AQH_ForwardMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

16
aqhome/ipc/msg_ipc.c Normal file
View File

@@ -0,0 +1,16 @@
/****************************************************************************
* 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/ipc/msg_ipc.h>

30
aqhome/ipc/msg_ipc.h Normal file
View File

@@ -0,0 +1,30 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_IPC_H
#define AQH_MSG_IPC_H
#include <aqhome/api.h>
#include <gwenhywfar/msg_ipc.h>
#include <gwenhywfar/buffer.h>
#define AQH_IPC_PROTOCOL_ID 1
#define AQH_IPC_PROTOCOL_VERSION 1
#define AQH_MSGTYPE_IPC_FORWARD 0x100
#endif