aqhome: re-implemented aqhomed.
- added IPC endpoint2
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/ipc" >
|
||||
endpoint2_ipc.h
|
||||
endpoint_node_ipc.h
|
||||
endpoint_node_ipc_tcpd.h
|
||||
endpoint_ipc_tcpc.h
|
||||
@@ -61,12 +62,14 @@
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
endpoint2_ipc_p.h
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
endpoint2_ipc.c
|
||||
endpoint_node_ipc.c
|
||||
endpoint_node_ipc_tcpd.c
|
||||
endpoint_ipc_tcpc.c
|
||||
|
||||
139
aqhome/ipc/endpoint2_ipc.c
Normal file
139
aqhome/ipc/endpoint2_ipc.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
* 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/endpoint2_ipc_p.h"
|
||||
|
||||
#include <gwenhywfar/endpoint2_ipc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_ENDPOINT2_IPC_NAME "ipc"
|
||||
|
||||
|
||||
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT2_IPC)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AQH_IpcEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep)
|
||||
{
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_ENDPOINT2_IPC, xep);
|
||||
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep, xep, _freeData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
{
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
xep=(AQH_ENDPOINT2_IPC*) p;
|
||||
GWEN_FREE_OBJECT(xep);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_IpcEndpoint2_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT2 *ep)
|
||||
{
|
||||
if (ep) {
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
|
||||
if (xep) {
|
||||
return xep->acceptedMsgGroups;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcEndpoint2_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
|
||||
{
|
||||
if (ep) {
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
|
||||
if (xep)
|
||||
xep->acceptedMsgGroups=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcEndpoint2_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
|
||||
{
|
||||
if (ep) {
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
|
||||
if (xep)
|
||||
xep->acceptedMsgGroups|=i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_IpcEndpoint2_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i)
|
||||
{
|
||||
if (ep) {
|
||||
AQH_ENDPOINT2_IPC *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_ENDPOINT2_IPC, ep);
|
||||
if (xep)
|
||||
xep->acceptedMsgGroups&=~i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT2 *ep;
|
||||
|
||||
ep=GWEN_IpcEndpoint2_CreateIpcTcpClient(host, port, name?name:AQH_MSG_ENDPOINT2_IPC_NAME, groupId);
|
||||
AQH_IpcEndpoint2_Extend(ep);
|
||||
return ep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT2 *ep;
|
||||
|
||||
ep=GWEN_IpcEndpoint2_CreateIpcTcpServiceForSocket(sk, name?name:AQH_MSG_ENDPOINT2_IPC_NAME, groupId);
|
||||
AQH_IpcEndpoint2_Extend(ep);
|
||||
return ep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
31
aqhome/ipc/endpoint2_ipc.h
Normal file
31
aqhome/ipc/endpoint2_ipc.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
* 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_ENDPOINT2_IPC_H
|
||||
#define AQH_ENDPOINT2_IPC_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/endpoint.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API void AQH_IpcEndpoint2_Extend(GWEN_MSG_ENDPOINT2 *ep);
|
||||
|
||||
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId);
|
||||
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_IpcEndpoint2_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId);
|
||||
|
||||
AQHOME_API uint32_t AQH_IpcEndpoint2_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT2 *ep);
|
||||
AQHOME_API void AQH_IpcEndpoint2_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
|
||||
AQHOME_API void AQH_IpcEndpoint2_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
|
||||
AQHOME_API void AQH_IpcEndpoint2_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *ep, uint32_t i);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
38
aqhome/ipc/endpoint2_ipc_p.h
Normal file
38
aqhome/ipc/endpoint2_ipc_p.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
* 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_ENDPOINT2_IPC_P_H
|
||||
#define AQH_ENDPOINT2_IPC_P_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/endpoint2.h>
|
||||
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
|
||||
|
||||
typedef struct AQH_ENDPOINT2_IPC AQH_ENDPOINT2_IPC;
|
||||
struct AQH_ENDPOINT2_IPC {
|
||||
uint32_t acceptedMsgGroups;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +155,34 @@ uint16_t AQH_MqttClientEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep)
|
||||
|
||||
|
||||
|
||||
const char *AQH_MqttClientEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep)
|
||||
{
|
||||
if (ep) {
|
||||
GWEN_MSG_ENDPOINT2 *epChild;
|
||||
|
||||
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
|
||||
if (epChild)
|
||||
return AQH_MqttEndpoint2_GetTopicPrefix(epChild);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MqttClientEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s)
|
||||
{
|
||||
if (ep) {
|
||||
GWEN_MSG_ENDPOINT2 *epChild;
|
||||
|
||||
epChild=GWEN_MsgEndpoint2_Tree2_GetFirstChild(ep);
|
||||
if (epChild)
|
||||
AQH_MqttEndpoint2_SetTopicPrefix(epChild, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet)
|
||||
|
||||
@@ -31,6 +31,9 @@ AQHOME_API void AQH_MqttClientEndpoint2_SetKeepAliveTime(GWEN_MSG_ENDPOINT2 *ep,
|
||||
|
||||
AQHOME_API uint16_t AQH_MqttClientEndpoint2_GetNextPacketId(const GWEN_MSG_ENDPOINT2 *ep);
|
||||
|
||||
AQHOME_API const char *AQH_MqttClientEndpoint2_GetTopicPrefix(const GWEN_MSG_ENDPOINT2 *ep);
|
||||
AQHOME_API void AQH_MqttClientEndpoint2_SetTopicPrefix(GWEN_MSG_ENDPOINT2 *ep, const char *s);
|
||||
|
||||
|
||||
AQHOME_API int AQH_MqttClientEndpoint2_StartConnect(GWEN_MSG_ENDPOINT2 *ep);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ static int _isAttnLow(GWEN_MSG_ENDPOINT2 *ep);
|
||||
*/
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint_new(const char *devicePath, int groupId)
|
||||
GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT2 *ep;
|
||||
AQH_MSG_ENDPOINT2_TTY *xep;
|
||||
@@ -117,7 +117,7 @@ void _addSockets(GWEN_MSG_ENDPOINT2 *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET
|
||||
int rv;
|
||||
|
||||
/* (re)connect, set state */
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Starting to (re-)connect");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect");
|
||||
rv=GWEN_TtyEndpoint2_Connect(ep);
|
||||
if (rv<0) {
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
|
||||
@@ -141,6 +141,7 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
|
||||
if (GWEN_MsgEndpoint2_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
|
||||
int fd;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Connecting TTY device");
|
||||
fd=_openDevice(ep);
|
||||
if (fd<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", fd);
|
||||
@@ -152,6 +153,8 @@ int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep)
|
||||
sk=GWEN_Socket_fromFile(fd);
|
||||
GWEN_MsgEndpoint2_SetSocket(ep, sk);
|
||||
GWEN_MsgEndpoint2_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
|
||||
GWEN_MsgEndpoint2_DiscardInput(ep);
|
||||
_attnHigh(ep);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -171,8 +174,9 @@ int _getSocketFd(GWEN_MSG_ENDPOINT2 *ep)
|
||||
GWEN_SOCKET *sk;
|
||||
|
||||
sk=GWEN_MsgEndpoint2_GetSocket(ep);
|
||||
if (sk)
|
||||
if (sk) {
|
||||
return GWEN_Socket_GetSocketInt(sk);
|
||||
}
|
||||
}
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
@@ -188,11 +192,13 @@ int _openDevice(GWEN_MSG_ENDPOINT2 *ep)
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT2, AQH_MSG_ENDPOINT2_TTY, ep);
|
||||
assert(xep);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName);
|
||||
fd=open(xep->deviceName, O_NOCTTY | O_NDELAY | O_RDWR);
|
||||
if (fd<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on open(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Device %s open (socket %d)", xep->deviceName, fd);
|
||||
rv=tcgetattr(fd, &(xep->previousOptions));
|
||||
if (rv<0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on tcgetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno);
|
||||
@@ -284,7 +290,7 @@ int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT2 *ep, GWEN_MSG *msg)
|
||||
|
||||
bytesInMsg=GWEN_Msg_GetBytesInBuffer(msg);
|
||||
if (bytesInMsg<AQH_MSG_OFFS_ALL_DATA_BEGIN) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Header not yet complete");
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Header not yet complete (%d)", bytesInMsg);
|
||||
return (int) (AQH_MSG_OFFS_ALL_DATA_BEGIN-bytesInMsg);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#define AQH_MSG_ENDPOINT2_TTY_NAME "tty"
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG_ENDPOINT *AQH_TtyNodeEndpoint2_new(const char *devicePath, int groupId);
|
||||
AQHOME_API GWEN_MSG_ENDPOINT2 *AQH_TtyEndpoint2_new(const char *devicePath, int groupId);
|
||||
|
||||
AQHOME_API int GWEN_TtyEndpoint2_Connect(GWEN_MSG_ENDPOINT2 *ep);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user