Simplified IPC code to use less different IPC messages. Share more code. More qork on MQTT code.

This commit is contained in:
Martin Preuss
2023-10-01 21:31:02 +02:00
parent 0f896c1729
commit 1e27223dfa
50 changed files with 1326 additions and 698 deletions

View File

@@ -48,7 +48,7 @@
static void _readAndHandleIpcMessages(AQHOME_DATA *aqh);
static void _handleIpcEndpoint(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep);
static void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg);
@@ -110,14 +110,7 @@ AQH_VALUE *AqHomeData_GetOrCreateValueForDriver(AQHOME_DATA *aqh,
serviceName=AQH_IpcEndpoint_GetServiceName(epDriver);
buf=GWEN_Buffer_new(0, 256, 0, 1);
if (serviceName && *serviceName) {
GWEN_Buffer_AppendString(buf, serviceName);
GWEN_Buffer_AppendString(buf, "/");
}
else {
GWEN_Buffer_AppendString(buf, "unknown/");
}
GWEN_Buffer_AppendString(buf, nameForDriver);
GWEN_Buffer_AppendArgs(buf, "%s/%s", (serviceName && *serviceName)?serviceName:"unknown", nameForDriver);
v=AQH_Storage_GetValueByNameForSystem(aqh->storage, GWEN_Buffer_GetStart(buf));
if (v==NULL) {
@@ -143,6 +136,47 @@ AQH_VALUE *AqHomeData_GetOrCreateValueForDriver(AQHOME_DATA *aqh,
AQH_VALUE *AqHomeData_GetOrCreateValueForDriverWithTemplate(AQHOME_DATA *aqh,
GWEN_MSG_ENDPOINT *epDriver,
const AQH_VALUE *valueTemplate)
{
const char *serviceName;
AQH_VALUE *v;
GWEN_BUFFER *buf;
const char *nameForDriver;
serviceName=AQH_IpcEndpoint_GetServiceName(epDriver);
nameForDriver=AQH_Value_GetNameForDriver(valueTemplate);
buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendArgs(buf, "%s/%s", (serviceName && *serviceName)?serviceName:"unknown", nameForDriver);
v=AQH_Storage_GetValueByNameForSystem(aqh->storage, GWEN_Buffer_GetStart(buf));
if (v==NULL) {
if (AQH_IpcEndpoint_GetPermissions(epDriver) & AQH_IPCENDPOINT_PERMS_ADDVALUE) {
/* TODO: get or create device */
DBG_INFO(AQH_LOGDOMAIN, "Creating value \"%s\"", GWEN_Buffer_GetStart(buf));
v=AQH_Value_new();
AQH_Value_SetDriver(v, serviceName);
AQH_Value_SetNameForDriver(v, AQH_Value_GetNameForDriver(valueTemplate));
AQH_Value_SetNameForSystem(v, GWEN_Buffer_GetStart(buf));
AQH_Value_SetValueUnits(v, AQH_Value_GetValueUnits(valueTemplate));
AQH_Value_SetValueType(v, AQH_Value_GetValueType(valueTemplate));
AQH_Value_SetTimestampCreation(v, (uint64_t) time(NULL));
AQH_Storage_AddValue(aqh->storage, v);
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "No permissions to create value \"%s\"", GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return NULL;
}
}
GWEN_Buffer_free(buf);
return v;
}
void _readAndHandleIpcMessages(AQHOME_DATA *aqh)
{
if (aqh->ipcdEndpoint) {
@@ -170,7 +204,7 @@ void _handleIpcEndpoint(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep)
void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg)
{
uint16_t code;