aqhome-react: allow for int values.
those will be used e.g. to count number of open windows etc.
This commit is contained in:
@@ -216,6 +216,36 @@ double AqHomeReact_GetDoubleValue(AQHOME_REACT *aqh, const char *path, int idx,
|
||||
|
||||
|
||||
|
||||
int AqHomeReact_SetIntValue(AQHOME_REACT *aqh, const char *path, int value)
|
||||
{
|
||||
if (aqh && aqh->localVars && path && *path) {
|
||||
int rv;
|
||||
uint64_t timestamp;
|
||||
|
||||
timestamp=(uint64_t) time(NULL);
|
||||
rv=AQH_Vars_SetIntValue(aqh->localVars, AQH_VARS_PATHFLAGS_OVERWRITE_VARS, path, value);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
AqHomeReact_UnitVarChanges_IntVarUpdated(aqh->localVarChangeUnit, path, timestamp, value);
|
||||
return 0;
|
||||
}
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeReact_GetIntValue(AQHOME_REACT *aqh, const char *path, int idx, int defaultValue)
|
||||
{
|
||||
if (aqh && aqh->localVars && path && *path) {
|
||||
return AQH_Vars_GetIntValue(aqh->localVars, path, idx, defaultValue);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
@@ -51,5 +51,9 @@ const char *AqHomeReact_GetCharValue(AQHOME_REACT *aqh, const char *path, int id
|
||||
int AqHomeReact_SetDoubleValue(AQHOME_REACT *aqh, const char *path, double value);
|
||||
double AqHomeReact_GetDoubleValue(AQHOME_REACT *aqh, const char *path, int idx, double defaultValue);
|
||||
|
||||
int AqHomeReact_SetIntValue(AQHOME_REACT *aqh, const char *path, int value);
|
||||
int AqHomeReact_GetIntValue(AQHOME_REACT *aqh, const char *path, int idx, int defaultValue);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@
|
||||
|
||||
<links>
|
||||
<!-- (sourceNet), sourceUnit, sourcePort, (targetNet), targetUnit, targetPort -->
|
||||
<link sourceUnit=".updatedValue" sourcePort="output" targetUnit="valueFilterInPlug" targetPort="input" />
|
||||
<link sourceUnit="valueFilterInPlug" sourcePort="output" targetUnit="delayedOff1" targetPort="input" />
|
||||
<link sourceUnit=".timer" sourcePort="output" targetUnit="suntime1" targetPort="timer" />
|
||||
<link sourceUnit="suntime1" sourcePort="output" targetUnit="and1" targetPort="input" />
|
||||
<link sourceUnit="delayedOff1" sourcePort="output" targetUnit="and1" targetPort="input" />
|
||||
<link sourceUnit="and1" sourcePort="output" targetUnit="zeroPosNegString1" targetPort="input" />
|
||||
<link sourceUnit="zeroPosNegString1" sourcePort="output" targetUnit="valueSetOutPlug" targetPort="input" />
|
||||
<link sourceUnit=".updatedValue" sourcePort="doubleOutput" targetUnit="valueFilterInPlug" targetPort="input" />
|
||||
<link sourceUnit="valueFilterInPlug" sourcePort="output" targetUnit="delayedOff1" targetPort="input" />
|
||||
<link sourceUnit=".timer" sourcePort="output" targetUnit="suntime1" targetPort="timer" />
|
||||
<link sourceUnit="suntime1" sourcePort="output" targetUnit="and1" targetPort="input" />
|
||||
<link sourceUnit="delayedOff1" sourcePort="output" targetUnit="and1" targetPort="input" />
|
||||
<link sourceUnit="and1" sourcePort="output" targetUnit="zeroPosNegString1" targetPort="input" />
|
||||
<link sourceUnit="zeroPosNegString1" sourcePort="output" targetUnit="valueSetOutPlug" targetPort="input" />
|
||||
</links>
|
||||
</network>
|
||||
|
||||
@@ -68,6 +68,7 @@ AQHREACT_DATAOBJECT *AQHREACT_DataObject_dup(const AQHREACT_DATAOBJECT *origObje
|
||||
dataObject->timestamp=origObject->timestamp;
|
||||
dataObject->dataType=origObject->dataType;
|
||||
dataObject->doubleData=origObject->doubleData;
|
||||
dataObject->intData=origObject->intData;
|
||||
AQHREACT_DataObject_SetStringData(dataObject, origObject->stringData);
|
||||
return dataObject;
|
||||
}
|
||||
@@ -188,11 +189,27 @@ void AQHREACT_DataObject_SetStringData(AQHREACT_DATAOBJECT *dataObject, const ch
|
||||
|
||||
|
||||
|
||||
int AQHREACT_DataObject_GetIntData(const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
return dataObject?(dataObject->intData):0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQHREACT_DataObject_SetIntData(AQHREACT_DATAOBJECT *dataObject, int i)
|
||||
{
|
||||
if (dataObject)
|
||||
dataObject->intData=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQHREACT_DataObjectType_toString(int t)
|
||||
{
|
||||
switch(t) {
|
||||
case AQHREACT_DATAOBJECTTYPE_DOUBLE: return "double";
|
||||
case AQHREACT_DATAOBJECTTYPE_STRING: return "string";
|
||||
case AQHREACT_DATAOBJECTTYPE_INT: return "int";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
@@ -206,6 +223,8 @@ int AQHREACT_DataObjectType_fromString(const char *s)
|
||||
return AQHREACT_DATAOBJECTTYPE_DOUBLE;
|
||||
else if (strcasecmp(s, "string")==0)
|
||||
return AQHREACT_DATAOBJECTTYPE_STRING;
|
||||
else if (strcasecmp(s, "int")==0)
|
||||
return AQHREACT_DATAOBJECTTYPE_INT;
|
||||
}
|
||||
|
||||
return AQHREACT_DATAOBJECTTYPE_UNKNOWN;
|
||||
@@ -230,6 +249,9 @@ void AQHREACT_DataObject_Dump(const AQHREACT_DATAOBJECT *dataObject, GWEN_BUFFER
|
||||
case AQHREACT_DATAOBJECTTYPE_STRING:
|
||||
GWEN_Buffer_AppendArgs(buf, "%s (STRING) [%s]\n", AQHREACT_DataObject_GetStringData(dataObject), sVarSystemId?sVarSystemId:"");
|
||||
break;
|
||||
case AQHREACT_DATAOBJECTTYPE_INT:
|
||||
GWEN_Buffer_AppendArgs(buf, "%d (INT) [%s]\n", AQHREACT_DataObject_GetIntData(dataObject), sVarSystemId?sVarSystemId:"");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ GWEN_LIST_FUNCTION_DEFS(AQHREACT_DATAOBJECT, AQHREACT_DataObject)
|
||||
enum {
|
||||
AQHREACT_DATAOBJECTTYPE_UNKNOWN=0,
|
||||
AQHREACT_DATAOBJECTTYPE_DOUBLE,
|
||||
AQHREACT_DATAOBJECTTYPE_STRING
|
||||
AQHREACT_DATAOBJECTTYPE_STRING,
|
||||
AQHREACT_DATAOBJECTTYPE_INT
|
||||
};
|
||||
|
||||
|
||||
@@ -55,6 +56,9 @@ void AQHREACT_DataObject_SetDoubleData(AQHREACT_DATAOBJECT *dataObject, double i
|
||||
const char *AQHREACT_DataObject_GetStringData(const AQHREACT_DATAOBJECT *dataObject);
|
||||
void AQHREACT_DataObject_SetStringData(AQHREACT_DATAOBJECT *dataObject, const char *s);
|
||||
|
||||
int AQHREACT_DataObject_GetIntData(const AQHREACT_DATAOBJECT *dataObject);
|
||||
void AQHREACT_DataObject_SetIntData(AQHREACT_DATAOBJECT *dataObject, int i);
|
||||
|
||||
void AQHREACT_DataObject_Dump(const AQHREACT_DATAOBJECT *dataObject, GWEN_BUFFER *buf, int indent);
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ struct AQHREACT_DATAOBJECT {
|
||||
uint64_t timestamp;
|
||||
int dataType;
|
||||
double doubleData;
|
||||
int intData;
|
||||
char *stringData;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#endif
|
||||
|
||||
#include "./u_varchanges.h"
|
||||
#include "./u_passthrough.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
@@ -20,10 +19,29 @@
|
||||
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
unit=AqHomeReact_UnitPassthrough_new(aqh);
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
AQHREACT_Unit_SetTypeName(unit, "varchanges");
|
||||
AQHREACT_Unit_SetDescription(unit, "Propagates changes of values on the data server");
|
||||
AQHREACT_Unit_SetDescription(unit, "Propagates changes of values (server or local)");
|
||||
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "intOutput");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTINT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_INT);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "doubleOutput");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTDOUBLE);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "stringOutput");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTSTRING);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
return unit;
|
||||
}
|
||||
@@ -34,7 +52,7 @@ void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALU
|
||||
{
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTDOUBLE);
|
||||
if (outputPort) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
@@ -56,7 +74,7 @@ void AqHomeReact_UnitVarChanges_DoubleVarUpdated(AQHREACT_UNIT *unit, const char
|
||||
{
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTDOUBLE);
|
||||
if (outputPort) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
@@ -77,7 +95,7 @@ void AqHomeReact_UnitVarChanges_StringVarUpdated(AQHREACT_UNIT *unit, const char
|
||||
{
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTSTRING);
|
||||
if (outputPort) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
@@ -94,6 +112,28 @@ void AqHomeReact_UnitVarChanges_StringVarUpdated(AQHREACT_UNIT *unit, const char
|
||||
|
||||
|
||||
|
||||
void AqHomeReact_UnitVarChanges_IntVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, int data)
|
||||
{
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTINT);
|
||||
if (outputPort) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
DBG_DEBUG(NULL, "Variable \"%s\" changed (int)", varName);
|
||||
dataObject=AQHREACT_DataObject_new();
|
||||
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_INT);
|
||||
AQHREACT_DataObject_SetTimestamp(dataObject, timestamp);
|
||||
AQHREACT_DataObject_SetIntData(dataObject, data);
|
||||
AQHREACT_DataObject_SetSystemValueId(dataObject, varName);
|
||||
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||
AQHREACT_DataObject_free(dataObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
#include "aqhome/data/value.h"
|
||||
|
||||
|
||||
#define AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTINT 0
|
||||
#define AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTDOUBLE 1
|
||||
#define AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_OUTSTRING 2
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh);
|
||||
|
||||
/**
|
||||
@@ -34,6 +40,12 @@ void AqHomeReact_UnitVarChanges_DoubleVarUpdated(AQHREACT_UNIT *unit, const char
|
||||
void AqHomeReact_UnitVarChanges_StringVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, const char *data);
|
||||
|
||||
|
||||
/**
|
||||
* Called from AqHomeReact when a local variable changed (see @ref AqHomeReact_SetIntValue).
|
||||
*/
|
||||
void AqHomeReact_UnitVarChanges_IntVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, int data);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user