started working on storage service.

This commit is contained in:
Martin Preuss
2023-07-19 18:17:10 +02:00
parent 06b5ab26c8
commit db5d6cb980
20 changed files with 1443 additions and 1 deletions

View File

@@ -11,8 +11,12 @@
#endif
#include "aqhome/data/storage_p.h"
#include "aqhome/data/storage_readxml.h"
#include "aqhome/data/storage_writexml.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/xml.h>
#include <gwenhywfar/directory.h>
@@ -25,7 +29,6 @@
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
@@ -37,6 +40,7 @@ AQH_STORAGE *AQH_Storage_new(void)
AQH_STORAGE *sto;
GWEN_NEW_OBJECT(AQH_STORAGE, sto);
sto->roomList=AQH_Room_List_new();
sto->deviceList=AQH_Device_List_new();
sto->mqttTopicList=AQH_MqttTopic_List_new();
sto->valueList=AQH_Value_List_new();
@@ -52,6 +56,8 @@ void AQH_Storage_free(AQH_STORAGE *sto)
AQH_Value_List_free(sto->valueList);
AQH_MqttTopic_List_free(sto->mqttTopicList);
AQH_Device_List_free(sto->deviceList);
AQH_Room_List_free(sto->roomList);
free(sto->stateFile);
GWEN_FREE_OBJECT(sto);
}
@@ -59,6 +65,23 @@ void AQH_Storage_free(AQH_STORAGE *sto)
const char *AQH_Storage_GetStateFile(const AQH_STORAGE *sto)
{
return sto?(sto->stateFile):NULL;
}
void AQH_Storage_SetStateFile(AQH_STORAGE *sto, const char *s)
{
if (sto) {
free(sto->stateFile);
sto->stateFile=s?strdup(s):NULL;
}
}
void AQH_Storage_AddDevice(AQH_STORAGE *sto, AQH_DEVICE *dev)
{
if (sto && dev) {
@@ -154,5 +177,43 @@ void AQH_Storage_HandleMqttPublish(AQH_STORAGE *sto, const char *topic, const ch
int AQH_Storage_Init(AQH_STORAGE *sto)
{
int rv;
rv=GWEN_Directory_GetPath(sto->stateFile,
GWEN_PATH_FLAGS_CHECKROOT | GWEN_PATH_FLAGS_PATHMUSTEXIST | GWEN_PATH_FLAGS_NAMEMUSTEXIST);
if (rv==0) {
rv=AQH_Storage_ReadStateFile(sto, sto->stateFile);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
else {
DBG_WARN(AQH_LOGDOMAIN, "State file \"%s\" not available, will try to create it later", sto->stateFile);
}
return 0;
}
int AQH_Storage_WriteState(AQH_STORAGE *sto)
{
int rv;
rv=AQH_Storage_WriteStateFile(sto, sto->stateFile);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
return 0;
}