More work on aqhome-react.

This commit is contained in:
Martin Preuss
2024-03-09 01:23:06 +01:00
parent 605d78a2b7
commit a3efa18a61
28 changed files with 1661 additions and 61 deletions

View File

@@ -0,0 +1,71 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhreact_units" >
<includes type="c" >
$(gwenhywfar_cflags)
-I$(topsrcdir)
-I$(topbuilddir)
-I$(topsrcdir)/apps
-I$(topbuilddir)/apps
-I$(builddir)
-I$(srcdir)
</includes>
<includes type="tm2" >
--include=$(builddir)
--include=$(srcdir)
</includes>
<setVar name="local/cflags">$(visibility_cflags)</setVar>
<setVar name="tm2flags" >
</setVar>
<setVar name="local/typefiles" >
</setVar>
<setVar name="local/built_sources" >
</setVar>
<setVar name="local/built_headers_pub">
</setVar>
<setVar name="local/built_headers_priv" >
</setVar>
<headers dist="true" >
u_or.h
u_varchanges.h
u_valuefilter.h
</headers>
<sources>
$(local/typefiles)
u_or.c
u_varchanges.c
u_valuefilter.c
</sources>
<useTargets>
</useTargets>
<libraries>
</libraries>
<subdirs>
</subdirs>
<extradist>
</extradist>
</target>
</gwbuild>

View File

@@ -0,0 +1,136 @@
/****************************************************************************
* 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 "./u_or.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_OR_INSLOT_INPUT 0
#define AQHOMEREACT_UNIT_OR_INSLOT_AUTOINPUT 100
#define AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static int _cbProcessFn(AQHREACT_UNIT *unit);
static int _sampleInputSlots(const AQHREACT_INPUT_SLOT_LIST *inputSlotList);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitOr_new(AQHOME_REACT *aqh)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
unit=AQHREACT_Unit_new();
AQHREACT_Unit_SetName(unit, "or");
AQHREACT_Unit_SetDescription(unit, "Logical OR inputs");
AQHREACT_Unit_SetProcessFn(unit, _cbProcessFn);
AQHREACT_Unit_SetNextInputSlotId(unit, AQHOMEREACT_UNIT_OR_INSLOT_AUTOINPUT); /* for auto-gen multi-slots */
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT);
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
inputSlot=AQHREACT_InputSlot_new();
AQHREACT_InputSlot_SetName(inputSlot, "input");
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_OR_INSLOT_INPUT);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_InputSlot_AddFlags(inputSlot, AQHREACT_UNIT_FLAGS_MULTI);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
return unit;
}
int _cbProcessFn(AQHREACT_UNIT *unit)
{
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
inputSlotList=AQHREACT_Unit_GetInputSlots(unit);
if (inputSlotList) {
int result;
result=_sampleInputSlots(inputSlotList);
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT, result?1.0:0.0);
}
}
return 0;
}
int _sampleInputSlots(const AQHREACT_INPUT_SLOT_LIST *inputSlotList)
{
const AQHREACT_INPUT_SLOT *inputSlot;
int result=0;
inputSlot=AQHREACT_InputSlot_List_First(inputSlotList);
while(inputSlot) {
const char *slotName;
const AQHREACT_DATAOBJECT *dataObject;
slotName=AQHREACT_InputSlot_GetName(inputSlot);
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
if (dataObject) {
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
double d;
d=AQHREACT_DataObject_GetDoubleData(dataObject);
if (d>0.0)
result|=1;
}
else {
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", slotName?slotName:"<unnamed>");
}
}
else {
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", slotName?slotName:"<unnamed>");
}
inputSlot=AQHREACT_InputSlot_List_Next(inputSlot);
}
return result;
}

View File

@@ -0,0 +1,23 @@
/****************************************************************************
* 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 AQHOMEREACT_U_OR_H
#define AQHOMEREACT_U_OR_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
AQHREACT_UNIT *AqHomeReact_UnitOr_new(AQHOME_REACT *aqh);
#endif

View File

@@ -0,0 +1,96 @@
/****************************************************************************
* 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 "./u_valuefilter.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE 0
#define AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitValueFilter_new(AQHOME_REACT *aqh)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
AQHREACT_PARAM *param;
unit=AQHREACT_Unit_new();
AQHREACT_Unit_SetName(unit, "valuefilter");
AQHREACT_Unit_SetDescription(unit, "Filter values received from unit VarChanges by value path");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT);
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
inputSlot=AQHREACT_InputSlot_new();
AQHREACT_InputSlot_SetName(inputSlot, "input");
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
param=AQHREACT_Param_new();
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME);
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_STRING);
AQHREACT_Unit_AddParam(unit, param);
return unit;
}
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE) {
const char *sSystemValueId;
sSystemValueId=AQHREACT_DataObject_GetSystemValueId(dataObject);
if (sSystemValueId && *sSystemValueId) {
const char *sFilter;
sFilter=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME, NULL);
if (sFilter && *sFilter && strcasecmp(sSystemValueId, sFilter)==0)
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT, dataObject);
}
}
}

View File

@@ -0,0 +1,26 @@
/****************************************************************************
* 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 AQHOMEREACT_U_VALUEFILTER_H
#define AQHOMEREACT_U_VALUEFILTER_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#define AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME "valueName"
AQHREACT_UNIT *AqHomeReact_UnitValueFilter_new(AQHOME_REACT *aqh);
#endif

View File

@@ -0,0 +1,81 @@
/****************************************************************************
* 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 "./u_varchanges.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_VARCHANGES_INSLOT_CHANGE 0
#define AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_RESULT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
unit=AQHREACT_Unit_new();
AQHREACT_Unit_SetName(unit, "varchanges");
AQHREACT_Unit_SetDescription(unit, "Propagates changes of values on the data server");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_RESULT);
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
inputSlot=AQHREACT_InputSlot_new();
AQHREACT_InputSlot_SetName(inputSlot, "input");
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_VARCHANGES_INSLOT_CHANGE);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
return unit;
}
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit && dataObject && slotIdForUnit==0)
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_RESULT, dataObject);
}

View File

@@ -0,0 +1,23 @@
/****************************************************************************
* 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 AQHOMEREACT_U_VARCHANGES_H
#define AQHOMEREACT_U_VARCHANGES_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh);
#endif