aqhome: started working on database code.
This commit is contained in:
158
aqhome/data/storage.c
Normal file
158
aqhome/data/storage.c
Normal file
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (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/data/storage_p.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
AQH_STORAGE *AQH_Storage_new(void)
|
||||
{
|
||||
AQH_STORAGE *sto;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_STORAGE, sto);
|
||||
sto->deviceList=AQH_Device_List_new();
|
||||
sto->mqttTopicList=AQH_MqttTopic_List_new();
|
||||
sto->valueList=AQH_Value_List_new();
|
||||
|
||||
return sto;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Storage_free(AQH_STORAGE *sto)
|
||||
{
|
||||
if (sto) {
|
||||
AQH_Value_List_free(sto->valueList);
|
||||
AQH_MqttTopic_List_free(sto->mqttTopicList);
|
||||
AQH_Device_List_free(sto->deviceList);
|
||||
|
||||
GWEN_FREE_OBJECT(sto);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Storage_AddDevice(AQH_STORAGE *sto, AQH_DEVICE *dev)
|
||||
{
|
||||
if (sto && dev) {
|
||||
uint64_t id;
|
||||
|
||||
id=++(sto->lastDeviceId);
|
||||
AQH_Device_SetId(dev, id);
|
||||
AQH_Device_List_Add(dev, sto->deviceList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE_LIST *AQH_Storage_GetDeviceList(const AQH_STORAGE *sto)
|
||||
{
|
||||
return sto?sto->deviceList:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *AQH_Storage_GetDeviceById(const AQH_STORAGE *sto, uint64_t id)
|
||||
{
|
||||
return sto?AQH_Device_List_GetById(sto->deviceList, id):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Storage_AddMqttTopic(AQH_STORAGE *sto, AQH_MQTT_TOPIC *t)
|
||||
{
|
||||
if (sto && t) {
|
||||
uint64_t id;
|
||||
|
||||
id=++(sto->lastTopicId);
|
||||
AQH_MqttTopic_SetId(t, id);
|
||||
AQH_MqttTopic_List_Add(t, sto->mqttTopicList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MQTT_TOPIC_LIST *AQH_Storage_GetMqttTopicList(const AQH_STORAGE *sto)
|
||||
{
|
||||
return sto?sto->mqttTopicList:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicById(const AQH_STORAGE *sto, uint64_t id)
|
||||
{
|
||||
return sto?AQH_MqttTopic_List_GetById(sto->mqttTopicList, id):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MQTT_TOPIC *AQH_Storage_GetMqttTopicByTopic(const AQH_STORAGE *sto, const char *topic)
|
||||
{
|
||||
return sto?AQH_MqttTopic_List_GetByMqttTopic(sto->mqttTopicList, topic):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Storage_AddValue(AQH_STORAGE *sto, AQH_VALUE *value)
|
||||
{
|
||||
if (sto && value) {
|
||||
uint64_t id;
|
||||
|
||||
id=++(sto->lastValueId);
|
||||
AQH_Value_SetId(value, id);
|
||||
AQH_Value_List_Add(value, sto->valueList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE_LIST *AQH_Storage_GetValueList(const AQH_STORAGE *sto)
|
||||
{
|
||||
return sto?sto->valueList:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *AQH_Storage_GetValueById(const AQH_STORAGE *sto, uint64_t id)
|
||||
{
|
||||
return sto?AQH_Value_List_GetById(sto->valueList, id):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Storage_HandleMqttPublish(AQH_STORAGE *sto, const char *topic, const char *value)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user