More work on aqhome-react.

- added some units
- added some types
This commit is contained in:
Martin Preuss
2024-03-10 20:15:21 +01:00
parent 656c9cf66f
commit d3a6256c8c
35 changed files with 1159 additions and 80 deletions

View File

@@ -49,6 +49,7 @@
param_p.h
unit.h
unit_p.h
unitnet.h
</headers>
<sources>
@@ -59,6 +60,7 @@
link.c
param.c
unit.c
unitnet.c
</sources>
<useTargets>

View File

@@ -10,8 +10,6 @@
#define AQHOME_REACT_DATAOBJECT_H
#include "aqhome-react/aqhome_react.h"
#include <gwenhywfar/list.h>
@@ -26,6 +24,9 @@ enum {
};
#include "aqhome-react/aqhome_react.h"
AQHREACT_DATAOBJECT *AQHREACT_DataObject_new();
void AQHREACT_DataObject_free(AQHREACT_DATAOBJECT *dataObject);

View File

@@ -10,8 +10,6 @@
#define AQHOME_REACT_INPUTSLOT_H
#include "aqhome-react/aqhome_react.h"
#include <gwenhywfar/list.h>
@@ -19,6 +17,7 @@ typedef struct AQHREACT_INPUT_SLOT AQHREACT_INPUT_SLOT;
GWEN_LIST_FUNCTION_DEFS(AQHREACT_INPUT_SLOT, AQHREACT_InputSlot)
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/dataobject.h"

View File

@@ -9,8 +9,6 @@
#ifndef AQHOME_REACT_OUTPUTSLOT_H
#define AQHOME_REACT_OUTPUTSLOT_H
#include "aqhome-react/aqhome_react.h"
#include <gwenhywfar/list.h>
@@ -18,6 +16,7 @@ typedef struct AQHREACT_OUTPUT_SLOT AQHREACT_OUTPUT_SLOT;
GWEN_LIST_FUNCTION_DEFS(AQHREACT_OUTPUT_SLOT, AQHREACT_OutputSlot)
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/link.h"

View File

@@ -9,15 +9,15 @@
#ifndef AQHOME_REACT_PARAM_H
#define AQHOME_REACT_PARAM_H
#include "aqhome-react/aqhome_react.h"
#include <gwenhywfar/list.h>
typedef struct AQHREACT_PARAM AQHREACT_PARAM;
GWEN_LIST_FUNCTION_DEFS(AQHREACT_PARAM, AQHREACT_Param)
#include "aqhome-react/aqhome_react.h"
AQHREACT_PARAM *AQHREACT_Param_new();
void AQHREACT_Param_free(AQHREACT_PARAM *param);

View File

@@ -21,7 +21,7 @@ GWEN_INHERIT_FUNCTIONS(AQHREACT_UNIT)
AQHREACT_UNIT *AQHREACT_Unit_new()
AQHREACT_UNIT *AQHREACT_Unit_new(void)
{
AQHREACT_UNIT *unit;
@@ -151,6 +151,21 @@ void AQHREACT_Unit_SubFlags(AQHREACT_UNIT *unit, uint32_t i)
uint64_t AQHREACT_Unit_GetGpTimestamp(const AQHREACT_UNIT *unit)
{
return unit?unit->gpTimestamp:0;
}
void AQHREACT_Unit_SetGpTimestamp(AQHREACT_UNIT *unit, uint64_t t)
{
if (unit)
unit->gpTimestamp=t;
}
AQHREACT_INPUT_SLOT_LIST *AQHREACT_Unit_GetInputSlots(const AQHREACT_UNIT *unit)
{
return unit?unit->inputSlotList:NULL;
@@ -566,5 +581,27 @@ int AQHREACT_Unit_InputHasChanged(const AQHREACT_UNIT *unit)
AQHREACT_UNIT *AQHREACT_Unit_List_GetById(const AQHREACT_UNIT_LIST *unitList, const char *id)
{
if (unitList && id && *id) {
AQHREACT_UNIT *unit;
unit=AQHREACT_Unit_List_First(unitList);
while(unit) {
const char *s;
s=AQHREACT_Unit_GetId(unit);
if (s && *s && strcasecmp(s, id)==0)
return unit;
unit=AQHREACT_Unit_List_Next(unit);
}
}
return NULL;
}

View File

@@ -10,8 +10,6 @@
#define AQHOME_REACT_UNIT_H
#include "aqhome-react/aqhome_react.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
@@ -26,9 +24,11 @@ GWEN_INHERIT_FUNCTION_DEFS(AQHREACT_UNIT)
#define AQHREACT_UNIT_FLAGS_MULTI 0x20000000
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/inputslot.h"
#include "aqhome-react/types/outputslot.h"
#include "aqhome-react/types/param.h"
#include "aqhome-react/types/dataobject.h"
typedef void (*AQHREACT_UNIT_INPUTDATA_FN)(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
@@ -36,7 +36,7 @@ typedef int (*AQHREACT_UNIT_PROCESS_FN)(AQHREACT_UNIT *unit);
AQHREACT_UNIT *AQHREACT_Unit_new();
AQHREACT_UNIT *AQHREACT_Unit_new(void);
void AQHREACT_Unit_free(AQHREACT_UNIT *unit);
const char *AQHREACT_Unit_GetName(const AQHREACT_UNIT *unit);
@@ -56,6 +56,11 @@ void AQHREACT_Unit_SetFlags(AQHREACT_UNIT *unit, uint32_t i);
void AQHREACT_Unit_AddFlags(AQHREACT_UNIT *unit, uint32_t i);
void AQHREACT_Unit_SubFlags(AQHREACT_UNIT *unit, uint32_t i);
/** general purpose timestamp, unit is free to use it */
uint64_t AQHREACT_Unit_GetGpTimestamp(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_SetGpTimestamp(AQHREACT_UNIT *unit, uint64_t t);
AQHREACT_INPUT_SLOT_LIST *AQHREACT_Unit_GetInputSlots(const AQHREACT_UNIT *unit);
void AQHREACT_Unit_AddInputSlot(AQHREACT_UNIT *unit, AQHREACT_INPUT_SLOT *inSlot);
AQHREACT_INPUT_SLOT *AQHREACT_Unit_GetInputSlotByIdForUnit(const AQHREACT_UNIT *unit, int id);
@@ -86,6 +91,12 @@ void AQHREACT_Unit_OutputStringData(AQHREACT_UNIT *unit, int slotIndex, const ch
void AQHREACT_Unit_InputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/**
* Process inputs and generate output.
*
* @return >0 if something done, 0 if nothing done (response of internal implementation), <0 on error
* @param unit unit object
*/
int AQHREACT_Unit_Process(AQHREACT_UNIT *unit);
@@ -93,6 +104,8 @@ AQHREACT_UNIT_INPUTDATA_FN AQHREACT_Unit_SetInputDataFn(AQHREACT_UNIT *unit, AQH
AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_PROCESS_FN f);
AQHREACT_UNIT *AQHREACT_Unit_List_GetById(const AQHREACT_UNIT_LIST *unitList, const char *id);
#endif

View File

@@ -22,6 +22,7 @@ struct AQHREACT_UNIT {
char *id;
uint32_t flags;
uint64_t gpTimestamp;
int nextInputSlotId;

View File

@@ -0,0 +1,111 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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 "./unitnet_p.h"
#include <gwenhywfar/debug.h>
GWEN_LIST_FUNCTIONS(AQHREACT_UNIT_NET, AQHREACT_UnitNet)
AQHREACT_UNIT_NET *AQHREACT_UnitNet_new(void)
{
AQHREACT_UNIT_NET *unitNet;
GWEN_NEW_OBJECT(AQHREACT_UNIT_NET, unitNet);
GWEN_LIST_INIT(AQHREACT_UNIT_NET, unitNet);
unitNet->unitList=AQHREACT_UnitNet_List_new();
return unitNet;
}
void AQHREACT_UnitNet_free(AQHREACT_UNIT_NET *unitNet)
{
if (unitNet) {
GWEN_LIST_FINI(AQHREACT_UNIT_NET, unitNet);
AQHREACT_UnitNet_List_free(unitNet->unitList);
GWEN_FREE_OBJECT(unitNet);
}
}
const char *AQHREACT_UnitNet_GetName(const AQHREACT_UNIT_NET *unitNet)
{
return unitNet?unitNet->name:NULL;
}
void AQHREACT_UnitNet_SetName(AQHREACT_UNIT_NET *unitNet, const char *s)
{
if (unitNet) {
free(unitNet->name);
unitNet->name=s?strdup(s):NULL;
}
}
AQHREACT_UNIT_LIST *AQHREACT_UnitNet_GetUnitList(const AQHREACT_UNIT_NET *unitNet)
{
return unitNet?unitNet->unitList:NULL;
}
AQHREACT_UNIT *AQHREACT_UnitNet_GetUnitById(const AQHREACT_UNIT_NET *unitNet, const char *s)
{
return (unitNet && s && *s)?AQHREACT_Unit_List_GetById(unitNet->unitList, s):NULL;
}
void AQHREACT_UnitNet_AddUnit(AQHREACT_UNIT_NET *unitNet, AQHREACT_UNIT *unit)
{
if (unitNet && unit)
AQHREACT_Unit_List_Add(unit, unitNet->unitList);
}
AQHREACT_UNIT_NET *AQHREACT_UnitNet_List_GetByName(const AQHREACT_UNIT_NET_LIST *unitNetList, const char *name)
{
if (unitNetList && name && *name) {
AQHREACT_UNIT_NET *unitNet;
unitNet=AQHREACT_UnitNet_List_First(unitNetList);
while(unitNet) {
const char *s;
s=AQHREACT_UnitNet_GetName(unitNet);
if (s && *s && strcasecmp(s, name)==0)
return unitNet;
unitNet=AQHREACT_UnitNet_List_Next(unitNet);
}
}
return NULL;
}

View File

@@ -0,0 +1,39 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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 AQHOME_REACT_UNIT_NET_H
#define AQHOME_REACT_UNIT_NET_H
#include <gwenhywfar/list.h>
typedef struct AQHREACT_UNIT_NET AQHREACT_UNIT_NET;
GWEN_LIST_FUNCTION_DEFS(AQHREACT_UNIT_NET, AQHREACT_UnitNet)
#include "aqhome-react/aqhome_react.h"
AQHREACT_UNIT_NET *AQHREACT_UnitNet_new(void);
void AQHREACT_UnitNet_free(AQHREACT_UNIT_NET *unitNet);
const char *AQHREACT_UnitNet_GetName(const AQHREACT_UNIT_NET *unitNet);
void AQHREACT_UnitNet_SetName(AQHREACT_UNIT_NET *unitNet, const char *s);
AQHREACT_UNIT_LIST *AQHREACT_UnitNet_GetUnitList(const AQHREACT_UNIT_NET *unitNet);
AQHREACT_UNIT *AQHREACT_UnitNet_GetUnitById(const AQHREACT_UNIT_NET *unitNet, const char *s);
void AQHREACT_UnitNet_AddUnit(AQHREACT_UNIT_NET *unitNet, AQHREACT_UNIT *unit);
AQHREACT_UNIT_NET *AQHREACT_UnitNet_List_GetByName(const AQHREACT_UNIT_NET_LIST *unitNetList, const char *name);
#endif

View File

@@ -0,0 +1,25 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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 AQHOME_REACT_UNIT_NET_P_H
#define AQHOME_REACT_UNIT_NET_P_H
#include "aqhome-react/types/unitnet.h"
struct AQHREACT_UNIT_NET {
GWEN_LIST_ELEMENT(AQHREACT_UNIT_NET)
char *name;
AQHREACT_UNIT_LIST *unitList;
};
#endif