198 lines
4.0 KiB
C
198 lines
4.0 KiB
C
/****************************************************************************
|
|
* 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 "./aqhome_react_p.h"
|
|
#include "aqhome-react/units/u_or.h"
|
|
#include "aqhome-react/units/u_valuefilter.h"
|
|
#include "aqhome-react/units/u_stabilize.h"
|
|
#include "aqhome-react/units/u_lowpass.h"
|
|
#include "aqhome-react/units/u_highpass.h"
|
|
|
|
|
|
#include <gwenhywfar/misc.h>
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
free(aqh->pidFile);
|
|
|
|
GWEN_FREE_OBJECT(aqh);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG_ENDPOINT *AqHomeReact_GetBrokerEndpoint(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?(aqh->brokerEndpoint):NULL;
|
|
}
|
|
|
|
|
|
|
|
GWEN_DB_NODE *AqHomeReact_GetDbArgs(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?(aqh->dbArgs):NULL;
|
|
}
|
|
|
|
|
|
|
|
const char *AqHomeReact_GetPidFile(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?aqh->pidFile:NULL;
|
|
}
|
|
|
|
|
|
|
|
void AqHomeReact_SetPidFile(AQHOME_REACT *aqh, const char *s)
|
|
{
|
|
if (aqh) {
|
|
free(aqh->pidFile);
|
|
aqh->pidFile=s?strdup(s):NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int AqHomeReact_GetTimeout(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?aqh->timeout:0;
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?aqh->timerUnit:NULL;
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh)
|
|
{
|
|
return aqh?aqh->varChangeUnit:NULL;
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
{
|
|
if (aqh && unitId && *unitId) {
|
|
AQHREACT_UNIT_LIST *unitList=NULL;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType)
|
|
{
|
|
/* this does not include u_timer and u_varchanges, because those are only created once globally in init.c */
|
|
if (aqh && unitType && *unitType) {
|
|
if (strcasecmp(unitType, "or")==0)
|
|
return AqHomeReact_UnitOr_new();
|
|
else if (strcasecmp(unitType, "valueFilter")==0)
|
|
return AqHomeReact_UnitValueFilter_new();
|
|
else if (strcasecmp(unitType, "stabilize")==0)
|
|
return AqHomeReact_UnitStabilize_new();
|
|
else if (strcasecmp(unitType, "lowPass")==0)
|
|
return AqHomeReact_UnitLowPass_new();
|
|
else if (strcasecmp(unitType, "highPass")==0)
|
|
return AqHomeReact_UnitHighPass_new();
|
|
else {
|
|
DBG_ERROR(NULL, "Unknown unit type \"%s\"", unitType);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|