aqhome-react: major rebuild of unit handling.
now nested networks are allowed to allow for complex networks.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include "./aqhome_react_p.h"
|
||||
#include "./net_read.h"
|
||||
#include "aqhome-react/units/u_logical.h"
|
||||
#include "aqhome-react/units/u_valuefilter.h"
|
||||
#include "aqhome-react/units/u_valueset.h"
|
||||
@@ -30,7 +31,6 @@ AQHOME_REACT *AqHomeReact_new()
|
||||
AQHOME_REACT *aqh;
|
||||
|
||||
GWEN_NEW_OBJECT(AQHOME_REACT, aqh);
|
||||
aqh->unitNetList=AQHREACT_UnitNet_List_new();
|
||||
aqh->unitList=AQHREACT_Unit_List_new();
|
||||
|
||||
return aqh;
|
||||
@@ -41,7 +41,6 @@ AQHOME_REACT *AqHomeReact_new()
|
||||
void AqHomeReact_free(AQHOME_REACT *aqh)
|
||||
{
|
||||
if (aqh) {
|
||||
AQHREACT_UnitNet_List_free(aqh->unitNetList);
|
||||
AQHREACT_Unit_List_free(aqh->unitList);
|
||||
GWEN_MsgEndpoint_free(aqh->brokerEndpoint);
|
||||
GWEN_DB_Group_free(aqh->dbArgs);
|
||||
@@ -121,57 +120,17 @@ AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT_NET_LIST *AqHomeReact_GetUnitNetList(const AQHOME_REACT *aqh)
|
||||
{
|
||||
return aqh?aqh->unitNetList:NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AqHomeReact_AddUnitNet(AQHOME_REACT *aqh, AQHREACT_UNIT_NET *unitNet)
|
||||
{
|
||||
if (aqh)
|
||||
AQHREACT_UnitNet_List_Add(unitNet, aqh->unitNetList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT_NET *AqHomeReact_GetUnitNetByName(const AQHOME_REACT *aqh, const char *s)
|
||||
{
|
||||
return (aqh && s && *s)?AQHREACT_UnitNet_List_GetByName(aqh->unitNetList, s):NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT *AqHomeReact_FindUnitByNetNameAndUnitId(const AQHOME_REACT *aqh, const char *netName, const char *unitId)
|
||||
AQHREACT_UNIT *AqHomeReact_FindUnitByUnitId(const AQHOME_REACT *aqh, const char *unitId)
|
||||
{
|
||||
if (aqh && unitId && *unitId) {
|
||||
AQHREACT_UNIT_LIST *unitList=NULL;
|
||||
AQHREACT_UNIT *unit;
|
||||
|
||||
if (netName && *netName) {
|
||||
AQHREACT_UNIT_NET *unitNet;
|
||||
|
||||
unitNet=AQHREACT_UnitNet_List_GetByName(aqh->unitNetList, netName);
|
||||
if (unitNet)
|
||||
unitList=AQHREACT_UnitNet_GetUnitList(unitNet);
|
||||
else {
|
||||
DBG_ERROR(NULL, "Unit net \"%s\" not found", netName);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
unitList=aqh->unitList;
|
||||
|
||||
if (unitList) {
|
||||
AQHREACT_UNIT *unit;
|
||||
|
||||
unit=AQHREACT_Unit_List_GetById(unitList, unitId);
|
||||
if (unit==NULL) {
|
||||
DBG_ERROR(NULL, "Unit \"%s/%s\" not found", netName, unitId);
|
||||
return NULL;
|
||||
}
|
||||
return unit;
|
||||
unit=AQHREACT_Unit_List_GetById(aqh->unitList, unitId);
|
||||
if (unit==NULL) {
|
||||
DBG_ERROR(NULL, "Unit \"%s\" not found", unitId);
|
||||
return NULL;
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -210,8 +169,25 @@ AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitT
|
||||
else if (strcasecmp(unitType, "zeroPosNegString")==0)
|
||||
return AqHomeReact_UnitZeroPosNegString_new(aqh);
|
||||
else {
|
||||
DBG_ERROR(NULL, "Unknown unit type \"%s\"", unitType);
|
||||
return NULL;
|
||||
AQHREACT_UNIT *unit;
|
||||
|
||||
DBG_INFO(NULL, "Trying to load network \"%s\"", unitType);
|
||||
unit=AQHomeReact_FindAndReadDataDirNetwork(aqh, unitType);
|
||||
if (unit==NULL) {
|
||||
DBG_ERROR(NULL, "Unknown unit type \"%s\"", unitType);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
const char *s;
|
||||
|
||||
s=AQHREACT_Unit_GetName(unit);
|
||||
if (!(s && *s && strcasecmp(s, unitType)==0)) {
|
||||
DBG_ERROR(NULL, "ERROR: Network file for type \"%s\" contains type \"%s\" instead", unitType, s?s:"<no name>");
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user