Started working on aqhome-nodes which will replace aqhomed.

This commit is contained in:
Martin Preuss
2023-09-13 23:31:02 +02:00
parent 161b979e84
commit 9b7d043682
49 changed files with 3143 additions and 258 deletions

View File

@@ -46,6 +46,7 @@
<headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint_ipc.h
endpoint_ipcclient.h
msg_ipc_result.h
msg_ipc_qwords.h
msg_ipc_tag16.h
@@ -61,6 +62,7 @@
$(local/typefiles)
endpoint_ipc.c
endpoint_ipcclient.c
msg_ipc_result.c
msg_ipc_qwords.c
msg_ipc_tag16.c

View File

@@ -49,7 +49,7 @@
msg_data_values.h
msg_data_datapoints.h
msg_data_connect.h
msg_data_addvalue.h
msg_data_value.h
msg_data_singledata.h
msg_data_multidata.h
msg_data_getdata.h
@@ -67,7 +67,7 @@
msg_data_values.c
msg_data_datapoints.c
msg_data_connect.c
msg_data_addvalue.c
msg_data_value.c
msg_data_singledata.c
msg_data_multidata.c
msg_data_getdata.c

View File

@@ -23,18 +23,18 @@
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x010 /* serviceName, userName, password */
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x100 /* AQH_DataPointsDataIpcMsg */ /* TODO Multi */
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x200 /* AQH_DataPointsDataIpcMsg */ /* TODO */
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x100 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x200 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_SingleDataDataIpcMsg */ /* Single */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_SingleDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x400 /* AQH_AddValueDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x500 /* AQH_GetDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x600 /* AQH_DataPointsDataIpcMsg */ /* TODO */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x700 /* AQH_DataPointsDataIpcMsg (0 datapoints) */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x800 /* AQH_DataPointsDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x700 /* AQH_ValueDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x800 /* AQH_SingleDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x900 /* GWEN_IpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0xa00 /* AQH_ValuesDataIpcMsg */ /* TODO */

View File

@@ -1,46 +0,0 @@
/****************************************************************************
* 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_DATA_ADDVALUE_H
#define AQH_MSG_IPC_DATA_ADDVALUE_H
#include <aqhome/api.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/msg_ipc.h>
/**
* This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUE_REQ.
*/
#define AQH_MSGDATA_ADDVALUE_TAGS_NAME 0x0001
#define AQH_MSGDATA_ADDVALUE_TAGS_UNITS 0x0002
#define AQH_MSGDATA_ADDVALUE_TAGS_TYPE 0x0003
AQHOME_API GWEN_MSG *AQH_AddValueDataIpcMsg_new(uint16_t code,
const char *valueName,
const char *valueUnits,
int valueType);
AQHOME_API void AQH_AddValueDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -10,7 +10,7 @@
# include <config.h>
#endif
#include <aqhome/ipc/data/msg_data_addvalue.h>
#include <aqhome/ipc/data/msg_data_value.h>
#include <aqhome/ipc/data/ipc_data.h>
#include <aqhome/ipc/msg_ipc_tag16.h>
@@ -22,25 +22,25 @@
#define AQH_MSGDATA_ADDVALUE_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD
#define AQH_MSGDATA_VALUE_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD
GWEN_MSG *AQH_AddValueDataIpcMsg_new(uint16_t code,
const char *valueName,
const char *valueUnits,
int valueType)
GWEN_MSG *AQH_ValueDataIpcMsg_new(uint16_t code,
const char *valueName,
const char *valueUnits,
int valueType)
{
GWEN_MSG *msg;
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 256, 0, 1);
if (valueName && *valueName)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_ADDVALUE_TAGS_NAME, valueName, buf);
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_VALUE_TAGS_NAME, valueName, buf);
if (valueUnits && *valueUnits)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_ADDVALUE_TAGS_UNITS, valueUnits, buf);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_ADDVALUE_TAGS_TYPE, valueType, buf);
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_VALUE_TAGS_UNITS, valueUnits, buf);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_VALUE_TAGS_TYPE, valueType, buf);
msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
@@ -51,9 +51,9 @@ GWEN_MSG *AQH_AddValueDataIpcMsg_new(uint16_t code,
void AQH_AddValueDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
void AQH_ValueDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_ADDVALUE_MINSIZE) {
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_VALUE_MINSIZE) {
GWEN_TAG16_LIST *tagList;
char *valueName=NULL;
char *valueUnits=NULL;
@@ -63,18 +63,18 @@ void AQH_AddValueDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf,
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_ADDVALUE_TAGS_NAME);
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_VALUE_TAGS_NAME);
valueName=tag?GWEN_Tag16_GetTagDataAsNewString(tag, NULL):NULL;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_ADDVALUE_TAGS_UNITS);
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_VALUE_TAGS_UNITS);
valueUnits=tag?GWEN_Tag16_GetTagDataAsNewString(tag, NULL):NULL;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_ADDVALUE_TAGS_TYPE);
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_VALUE_TAGS_TYPE);
valueType=tag?GWEN_Tag16_GetTagDataAsUint32(tag, 0):0;
}
GWEN_Buffer_AppendArgs(dbuf,
"ADDVALUE (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d)\n",
"VALUE (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg),

View File

@@ -0,0 +1,46 @@
/****************************************************************************
* 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_DATA_VALUE_H
#define AQH_MSG_IPC_DATA_VALUE_H
#include <aqhome/api.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/msg_ipc.h>
/**
* This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUE_REQ.
*/
#define AQH_MSGDATA_VALUE_TAGS_NAME 0x0001
#define AQH_MSGDATA_VALUE_TAGS_UNITS 0x0002
#define AQH_MSGDATA_VALUE_TAGS_TYPE 0x0003
AQHOME_API GWEN_MSG *AQH_ValueDataIpcMsg_new(uint16_t code,
const char *valueName,
const char *valueUnits,
int valueType);
AQHOME_API void AQH_ValueDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -58,6 +58,7 @@ void _freeData(void *bp, void *p)
free(xep->serviceName);
free(xep->userName);
free(xep->password);
GWEN_FREE_OBJECT(xep);
}
@@ -177,6 +178,35 @@ void AQH_IpcEndpoint_SetUserName(GWEN_MSG_ENDPOINT *ep, const char *s)
const char *AQH_IpcEndpoint_GetPassword(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep)
return xep->password;
}
return NULL;
}
void AQH_IpcEndpoint_SetPassword(GWEN_MSG_ENDPOINT *ep, const char *s)
{
if (ep) {
AQH_ENDPOINT_IPC *xep;
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep);
if (xep) {
free(xep->password);
xep->password=s?strdup(s):NULL;
}
}
}
uint32_t AQH_IpcEndpoint_GetPermissions(const GWEN_MSG_ENDPOINT *ep)
{
if (ep) {

View File

@@ -44,6 +44,9 @@ AQHOME_API void AQH_IpcEndpoint_SetServiceName(GWEN_MSG_ENDPOINT *ep, const char
AQHOME_API const char *AQH_IpcEndpoint_GetUserName(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_IpcEndpoint_SetUserName(GWEN_MSG_ENDPOINT *ep, const char *s);
AQHOME_API const char *AQH_IpcEndpoint_GetPassword(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_IpcEndpoint_SetPassword(GWEN_MSG_ENDPOINT *ep, const char *s);
AQHOME_API uint32_t AQH_IpcEndpoint_GetPermissions(const GWEN_MSG_ENDPOINT *ep);
AQHOME_API void AQH_IpcEndpoint_SetPermissions(GWEN_MSG_ENDPOINT *ep, uint32_t i);

View File

@@ -22,6 +22,7 @@ struct AQH_ENDPOINT_IPC {
uint32_t acceptedMsgGroups;
char *serviceName;
char *userName;
char *password;
uint32_t permissions;
};

View File

@@ -0,0 +1,135 @@
/****************************************************************************
* 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_ipcclient.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/data/msg_data_connect.h"
#include "aqhome/ipc/msg_ipc_result.h"
#include <gwenhywfar/endpoint_ipc.h>
#include <gwenhywfar/endpoint_tcpc.h>
#include <gwenhywfar/endpoint_multilayer.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_ENDPOINT_IPCCLIENT_NAME "ipc-client"
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild);
static void _checkSockets(GWEN_MSG_ENDPOINT *ep,
GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet,
GWEN_SOCKETSET *writeSet,
GWEN_SOCKETSET *xSet);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
GWEN_MSG_ENDPOINT *AQH_ClientIpcEndpoint_new(const char *name, int groupId)
{
GWEN_MSG_ENDPOINT *ep;
ep=GWEN_MultilayerEndpoint_new(name?name:AQH_MSG_ENDPOINT_IPCCLIENT_NAME, groupId);
GWEN_MultilayerEndpoint_SetStartConnectFn(ep, _startConnect);
GWEN_MultilayerEndpoint_SetCheckSocketsFn(ep, _checkSockets);
return ep;
}
int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild)
{
if (epChild) {
int rv;
GWEN_MSG *msg;
uint32_t flagsForConnectMsg;
flagsForConnectMsg=(GWEN_MsgEndpoint_GetFlags(ep) & AQH_ENDPOINT_IPCCLIENT_FLAGS_WANTUPDATES)?AQH_IPCENDPOINT_FLAGS_WANTUPDATES:0;
rv=GWEN_TcpcEndpoint_StartConnect(epChild);
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect child layer (%d)", rv);
return rv;
}
msg=AQH_ConnectDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_CONNECT_REQ,
AQH_IpcEndpoint_GetServiceName(epChild),
AQH_IpcEndpoint_GetUserName(epChild),
AQH_IpcEndpoint_GetPassword(epChild),
flagsForConnectMsg);
GWEN_MsgEndpoint_AddSendMessage(epChild, msg);
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING);
return rv; /* result from GWEN_TcpcEndpoint_StartConnect() above */
}
return GWEN_ERROR_GENERIC;
}
void _checkSockets(GWEN_MSG_ENDPOINT *ep,
GWEN_MSG_ENDPOINT *epChild,
GWEN_SOCKETSET *readSet,
GWEN_SOCKETSET *writeSet,
GWEN_SOCKETSET *xSet)
{
GWEN_MSG *msg;
GWEN_MsgEndpoint_CheckSockets(epChild, readSet, writeSet, xSet); /* let base layer work */
msg=GWEN_MsgEndpoint_GetFirstReceivedMessage(epChild);
while(msg) {
GWEN_MSG *msgNext;
uint16_t code;
msgNext=GWEN_Msg_List_Next(msg);
code=GWEN_IpcMsg_GetCode(msg);
if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
uint32_t resultCode;
GWEN_Msg_List_Del(msg); /* remove from list */
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
if (resultCode==AQH_MSG_IPC_SUCCESS) {
DBG_INFO(AQH_LOGDOMAIN, "Positive CONNECT response, connected");
GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED);
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Negative CONNECT response (%d)", code);
GWEN_MsgEndpoint_Disconnect(epChild);
GWEN_MsgEndpoint_Disconnect(ep);
}
GWEN_Msg_free(msg);
break;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%u)", code);
GWEN_Msg_free(msg);
}
msg=msgNext;
} /* while */
}

View File

@@ -0,0 +1,46 @@
/****************************************************************************
* 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_IPCCLIENT_H
#define AQH_ENDPOINT_IPCCLIENT_H
#include <aqhome/api.h>
#include <gwenhywfar/endpoint.h>
#define AQH_ENDPOINT_IPCCLIENT_FLAGS_WANTUPDATES 0x0001
/**
* This class expects to later have a child endpoint derived in any form from GWEN_TcpcEndpoint and from
* AQH_IpcEndpoint. It allows for automatic connect/reconnect including automatic exchange of AQH_ConnectDataIpcMsg
* messages thereby combining physical and logical connection to a server in one class.
*
* Use this class like this:
* <code>
* GWEN_MSG_ENDPOINT *clientEndpoint;
* GWEN_MSG_ENDPOINT *ipcBaseEndpoint;
*
* clientEndpoint=AQH_ClientIpcEndpoint_new("testClient", 0);
* ipcBaseEndpoint=AQH_IpcEndpoint_CreateIpcTcpClient("127.0.0.1", 1234, "ipcBaseClient", 0);
* AQH_IpcEndpoint_SetServiceName(ipcBaseEndpoint, "testclient");
* AQH_IpcEndpoint_SetUserName(ipcBaseEndpoint, "testUser");
* ...
* GWEN_MsgEndpoint_Tree2_AddChild(clientEndpoint, ipcBaseEndpoint);
* </code>
*
*/
AQHOME_API GWEN_MSG_ENDPOINT *AQH_ClientIpcEndpoint_new(const char *name, int groupId);
#endif