aqhome-cgi: optionally check for last change.

This commit is contained in:
Martin Preuss
2026-08-31 12:18:23 +02:00
parent f9822dccec
commit 2f951ca684
3 changed files with 12 additions and 6 deletions

View File

@@ -511,8 +511,10 @@ void _writePageDataSet(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n
const char *sVarType; const char *sVarType;
const char *sModality; const char *sModality;
const char *sVarName; const char *sVarName;
const char *sLastChange;
int modality; int modality;
int varType; int varType;
uint64_t lastChange;
AQH_MD_PAGECTX *newCtx; AQH_MD_PAGECTX *newCtx;
/* prepare new context */ /* prepare new context */
@@ -520,9 +522,11 @@ void _writePageDataSet(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n
sRoom=GWEN_XMLNode_GetProperty(nElement, "room", NULL); sRoom=GWEN_XMLNode_GetProperty(nElement, "room", NULL);
sModality=GWEN_XMLNode_GetProperty(nElement, "modality", NULL); sModality=GWEN_XMLNode_GetProperty(nElement, "modality", NULL);
sVarName=GWEN_XMLNode_GetProperty(nElement, "varname", NULL); sVarName=GWEN_XMLNode_GetProperty(nElement, "varname", NULL);
sLastChange=GWEN_XMLNode_GetProperty(nElement, "lastChange", NULL);
modality=sModality?AQH_ValueModality_fromString(sModality):AQH_ValueModality_Unknown; modality=sModality?AQH_ValueModality_fromString(sModality):AQH_ValueModality_Unknown;
varType=sVarType?AQH_ValueType_fromString(sVarType):AQH_ValueType_Sensor; varType=sVarType?AQH_ValueType_fromString(sVarType):AQH_ValueType_Sensor;
newCtx=AQH_MDPageCtx_CopyWithMatchingVars(ctx, varType, sRoom, modality, sVarName); lastChange=sLastChange?AQH_ParseTime(sLastChange):0;
newCtx=AQH_MDPageCtx_CopyWithMatchingVars(ctx, varType, sRoom, modality, sVarName, lastChange);
/* enter context */ /* enter context */
_writePageChildElements(newCtx, sPageId, nElement, dbuf); _writePageChildElements(newCtx, sPageId, nElement, dbuf);
/* free new context */ /* free new context */

View File

@@ -33,7 +33,7 @@ GWEN_TREE2_FUNCTIONS(AQH_MD_PAGECTX, AQH_MDPageCtx);
* ------------------------------------------------------------------------------------------------ * ------------------------------------------------------------------------------------------------
*/ */
static int _valueMatches(const AQH_VALUE *value, int varType, const char *room, int modality, const char *vname); static int _valueMatches(const AQH_VALUE *value, int varType, const char *room, int modality, const char *vname, uint64_t lastChange);
@@ -71,7 +71,7 @@ void AQH_MDPageCtx_free(AQH_MD_PAGECTX *ctx)
AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx, AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx,
int varType, const char *room, int modality, const char *vname) int varType, const char *room, int modality, const char *vname, uint64_t lastChange)
{ {
AQH_MD_PAGECTX *ctx=NULL; AQH_MD_PAGECTX *ctx=NULL;
@@ -92,7 +92,7 @@ AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx,
valueList=AQH_Value_List_new(); valueList=AQH_Value_List_new();
vSrc=AQH_Value_List_First(octx->valueList); vSrc=AQH_Value_List_First(octx->valueList);
while(vSrc) { while(vSrc) {
if (_valueMatches(vSrc, varType, room, modality, vname)) { if (_valueMatches(vSrc, varType, room, modality, vname, lastChange)) {
AQH_VALUE *vDest; AQH_VALUE *vDest;
DBG_ERROR(NULL, "+ %s", AQH_Value_GetNameForSystem(vSrc)); DBG_ERROR(NULL, "+ %s", AQH_Value_GetNameForSystem(vSrc));
@@ -115,7 +115,7 @@ AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx,
int _valueMatches(const AQH_VALUE *value, int varType, const char *room, int modality, const char *vname) int _valueMatches(const AQH_VALUE *value, int varType, const char *room, int modality, const char *vname, uint64_t lastChange)
{ {
int matches=1; int matches=1;
@@ -125,6 +125,8 @@ int _valueMatches(const AQH_VALUE *value, int varType, const char *room, int mod
if (matches && modality && modality!=AQH_Value_GetModality(value)) if (matches && modality && modality!=AQH_Value_GetModality(value))
matches=0; matches=0;
/* then slower compares */ /* then slower compares */
if (matches && lastChange && AQH_Value_GetTimestampLastChange(value)<lastChange)
matches=0;
if (matches && vname) { if (matches && vname) {
const char *sName; const char *sName;

View File

@@ -34,7 +34,7 @@ AQH_MD_PAGECTX *AQH_MDPageCtx_new(AQCGI_MODULE *module, AQH_DATACLIENT *dataClie
void AQH_MDPageCtx_free(AQH_MD_PAGECTX *ctx); void AQH_MDPageCtx_free(AQH_MD_PAGECTX *ctx);
AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx, AQH_MD_PAGECTX *AQH_MDPageCtx_CopyWithMatchingVars(const AQH_MD_PAGECTX *octx,
int varType, const char *room, int modality, const char *vname); int varType, const char *room, int modality, const char *vname, uint64_t lastChange);
AQCGI_MODULE *AQH_MDPageCtx_GetModule(const AQH_MD_PAGECTX *ctx); AQCGI_MODULE *AQH_MDPageCtx_GetModule(const AQH_MD_PAGECTX *ctx);
AQH_DATACLIENT *AQH_MDPageCtx_GetDataClient(const AQH_MD_PAGECTX *ctx); AQH_DATACLIENT *AQH_MDPageCtx_GetDataClient(const AQH_MD_PAGECTX *ctx);