aqhome-cgi: allow use of <ForEveryValue> nearly everywhere.

This commit is contained in:
Martin Preuss
2026-08-25 00:42:42 +02:00
parent b72bc7d8b5
commit d47a496c3f
3 changed files with 86 additions and 44 deletions

View File

@@ -62,6 +62,7 @@ static void _writePage(AQCGI_MODULE *m, AQH_DATACLIENT *dc, GWEN_XMLNODE *nPage,
static void _writePageChildElements(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n, GWEN_BUFFER *dbuf);
static void _writeHtmlElement(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf);
static void _writePageElement(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n, GWEN_BUFFER *dbuf);
static void _writePageForEveryValue(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf);
static void _writePageDataSet(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf);
static void _writePageItem(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf);
static AQH_MD_PAGECTX *_createInitialCtx(AQCGI_MODULE *m, AQH_DATACLIENT *dc);
@@ -153,6 +154,47 @@ void AQH_ModDevices_SetCharValue(GWEN_DB_NODE *dbDest, uint32_t flags, const cha
void AQH_ModDevices_SetupDbForDeviceAndValue(const AQH_VALUE *v, GWEN_DB_NODE *dbCtx)
{
GWEN_DB_NODE *db;
AQH_DEVICE *device;
db=GWEN_DB_GetGroup(dbCtx, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "value");
AQH_Value_toDb(v, db);
device=AQH_Value_GetDevicePtr(v);
if (device) {
const char *sNameForSystem;
const char *sLocation;
const char *sDescription;
GWEN_BUFFER *tbuf;
db=GWEN_DB_GetGroup(dbCtx, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "device");
AQH_Device_toDb(device, db);
/* generate descriptive name */
sNameForSystem=AQH_Device_GetNameForSystem(device);
sLocation=AQH_Device_GetLocation(device);
sDescription=AQH_Device_GetDescription(device);
tbuf=GWEN_Buffer_new(0, 256, 0, 1);
if (sLocation && sDescription)
GBAA(tbuf, "%s - %s", sDescription, sLocation);
else if (sLocation)
GBAA(tbuf, "%s", sLocation);
else if (sDescription)
GBAA(tbuf, "%s", sDescription);
else
GBAA(tbuf, "%s", sNameForSystem);
GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "descriptiveName", GWEN_Buffer_GetStart(tbuf));
GWEN_Buffer_free(tbuf);
}
else {
DBG_ERROR(NULL, "No device pointer in device %s", AQH_Value_GetNameForSystem(v));
}
}
void _sendPageList(AQCGI_MODULE *m, GWEN_BUFFER *dbuf)
{
GWEN_STRINGLIST *sl;
@@ -323,6 +365,8 @@ void _writePageElement(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n
_writePageDataSet(ctx, sPageId, nElement, dbuf);
else if (strcasecmp(sElementName, "item")==0)
_writePageItem(ctx, sPageId, nElement, dbuf);
else if (strcasecmp(sElementName, "forEveryValue")==0)
_writePageForEveryValue(ctx, sPageId, nElement, dbuf);
else if (strcasecmp(sElementName, "table")==0 ||
strcasecmp(sElementName, "tr")==0 ||
strcasecmp(sElementName, "td")==0 ||
@@ -366,6 +410,31 @@ void _writeHtmlElement(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *n
void _writePageForEveryValue(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf)
{
AQH_VALUE_LIST *valueList;
valueList=AQH_MDPageCtx_GetValues(ctx);
if (valueList) {
const AQH_VALUE *v;
GWEN_DB_NODE *dbCtx;
dbCtx=AQH_MDPageCtx_GetDbVars(ctx);
v=AQH_Value_List_First(valueList);
while(v) {
DBG_ERROR(NULL, "Writing for value %s", AQH_Value_GetNameForSystem(v));
AQH_ModDevices_SetupDbForDeviceAndValue(v, dbCtx);
_writePageChildElements(ctx, sPageId, nElement, dbuf);
v=AQH_Value_List_Next(v);
}
}
else {
DBG_ERROR(NULL, "No values");
}
}
void _writePageDataSet(AQH_MD_PAGECTX *ctx, const char *sPageId, GWEN_XMLNODE *nElement, GWEN_BUFFER *dbuf)
{
const char *sRoom;

View File

@@ -18,12 +18,14 @@
#include <aqcgi/request.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/xml.h>
void AQH_ModDevices_RunPage2Get(AQCGI_MODULE *m, AQCGI_REQUEST *rq, AQCGI_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
void AQH_ModDevices_RunPage2Graph(AQCGI_MODULE *m, AQCGI_REQUEST *rq, AQCGI_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
void AQH_ModDevices_SetCharValue(GWEN_DB_NODE *dbDest, uint32_t flags, const char *sVar, const char *sValue, GWEN_DB_NODE *dbCtx);
void AQH_ModDevices_SetupDbForDeviceAndValue(const AQH_VALUE *v, GWEN_DB_NODE *dbCtx);
#endif

View File

@@ -54,7 +54,6 @@
static int _isGraphConfFileCurrent(AQH_MD_PAGECTX *ctx, const char *sPageId, const char *sGraphId, int refreshTime);
static void _mkGraphConfigForEveryValue(AQH_MD_PAGECTX *ctx, GWEN_DB_NODE *dbGraph, GWEN_XMLNODE *n);
static void _setupDbForDeviceAndValue(const AQH_VALUE *v, GWEN_DB_NODE *dbCtx);
static void _mkGraphConfigCurve(AQH_MD_PAGECTX *ctx, GWEN_DB_NODE *dbGraph, GWEN_XMLNODE *nElement);
static GWEN_DB_NODE *_dbGraphFromXml(GWEN_XMLNODE *nElement, GWEN_DB_NODE *dbCtx);
static GWEN_DB_NODE *_dbCurveFromXml(GWEN_XMLNODE *nElement, GWEN_DB_NODE *dbCtx);
@@ -74,6 +73,7 @@ void AQH_ModDevices_PageWriteGraph(AQH_MD_PAGECTX *ctx, const char *sPageId, GWE
{
const char *sGraphId;
const char *sLink;
GWEN_BUFFER *bufGraphId=NULL;
int w;
int h;
@@ -81,6 +81,18 @@ void AQH_ModDevices_PageWriteGraph(AQH_MD_PAGECTX *ctx, const char *sPageId, GWE
w=GWEN_XMLNode_GetIntProperty(nElement, "width", DEFAULT_GRAPH_WIDTH);
h=GWEN_XMLNode_GetIntProperty(nElement, "height", DEFAULT_GRAPH_HEIGHT);
sGraphId=GWEN_XMLNode_GetProperty(nElement, "id", NULL);
if (sGraphId) {
GWEN_BUFFER *tbuf;;
tbuf=GWEN_Buffer_new(0, 256, 0, 1);
bufGraphId=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_DB_ReplaceVars(AQH_MDPageCtx_GetDbVars(ctx), sGraphId, tbuf);
AQH_ModService_EscapeToBuffer(GWEN_Buffer_GetStart(tbuf), bufGraphId);
GWEN_Buffer_free(tbuf);
sGraphId=GWEN_Buffer_GetStart(bufGraphId);
}
DBG_ERROR(NULL, "GraphId: %s", sGraphId);
if (!_isGraphConfFileCurrent(ctx, sPageId, sGraphId, DEFAULT_GRAPHCONF_REFRESH)) {
GWEN_DB_NODE *dbGraph;
GWEN_XMLNODE *n;
@@ -121,6 +133,7 @@ void AQH_ModDevices_PageWriteGraph(AQH_MD_PAGECTX *ctx, const char *sPageId, GWE
/* write graph link */
_addGraphLink(sPageId, sGraphId, w, h, sLink, dbuf);
GWEN_Buffer_free(bufGraphId);
}
@@ -153,7 +166,7 @@ void _mkGraphConfigForEveryValue(AQH_MD_PAGECTX *ctx, GWEN_DB_NODE *dbGraph, GWE
while(v) {
GWEN_XMLNODE *n;
_setupDbForDeviceAndValue(v, dbCtx);
AQH_ModDevices_SetupDbForDeviceAndValue(v, dbCtx);
n=GWEN_XMLNode_GetFirstTag(nElement);
while(n) {
const char *sName;
@@ -179,48 +192,6 @@ void _mkGraphConfigForEveryValue(AQH_MD_PAGECTX *ctx, GWEN_DB_NODE *dbGraph, GWE
void _setupDbForDeviceAndValue(const AQH_VALUE *v, GWEN_DB_NODE *dbCtx)
{
GWEN_DB_NODE *db;
AQH_DEVICE *device;
db=GWEN_DB_GetGroup(dbCtx, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "value");
AQH_Value_toDb(v, db);
device=AQH_Value_GetDevicePtr(v);
if (device) {
const char *sNameForSystem;
const char *sLocation;
const char *sDescription;
GWEN_BUFFER *tbuf;
db=GWEN_DB_GetGroup(dbCtx, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "device");
AQH_Device_toDb(device, db);
/* generate descriptive name */
sNameForSystem=AQH_Device_GetNameForSystem(device);
sLocation=AQH_Device_GetLocation(device);
sDescription=AQH_Device_GetDescription(device);
tbuf=GWEN_Buffer_new(0, 256, 0, 1);
if (sLocation && sDescription)
GBAA(tbuf, "%s - %s", sDescription, sLocation);
else if (sLocation)
GBAA(tbuf, "%s", sLocation);
else if (sDescription)
GBAA(tbuf, "%s", sDescription);
else
GBAA(tbuf, "%s", sNameForSystem);
GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "descriptiveName", GWEN_Buffer_GetStart(tbuf));
GWEN_Buffer_free(tbuf);
}
else {
DBG_ERROR(NULL, "No device pointer in device %s", AQH_Value_GetNameForSystem(v));
}
}
void _mkGraphConfigCurve(AQH_MD_PAGECTX *ctx, GWEN_DB_NODE *dbGraph, GWEN_XMLNODE *nElement)
{
GWEN_DB_NODE *dbCurve;