/**************************************************************************** * This file is part of the project AqHome. * AqHome (c) by 2025 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 #endif #include "./mdevices_device.h" #include "aqhome-cgi/service/module.h" #include "aqhome-cgi/modules/mdataclient.h" #include #include #include /* ------------------------------------------------------------------------------------------------ * defs and enums * ------------------------------------------------------------------------------------------------ */ #define GBAS GWEN_Buffer_AppendString #define GBAA GWEN_Buffer_AppendArgs #define I18N(msg) msg /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ static void _runDeviceWithArgs(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, const char *sDeviceName, GWEN_BUFFER *dbuf); static void _mkDeviceForm(AQH_DATACLIENT *dc, const char *sDeviceName, const AQH_DEVICE *device, GWEN_BUFFER *dbuf); static void _addFieldToForm(const char *sFieldTitle, const char *sFieldName, const char *sFieldContent, GWEN_BUFFER *dbuf); /* ------------------------------------------------------------------------------------------------ * code * ------------------------------------------------------------------------------------------------ */ void AQH_ModDevices_RunDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf) { GWEN_DB_NODE *dbQuery; const char *sDeviceName; DBG_ERROR(NULL, "RunValue"); dbQuery=AQCGI_Request_GetDbQuery(rq); sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL); if (sDeviceName && *sDeviceName) { GWEN_BUFFER *bufDeviceName; bufDeviceName=GWEN_Buffer_new(0, 64, 0, 1); GWEN_Text_UnescapeToBufferTolerant(sDeviceName, bufDeviceName); _runDeviceWithArgs(m, rq, session, dc, GWEN_Buffer_GetStart(bufDeviceName), dbuf); GWEN_Buffer_free(bufDeviceName); } } void _runDeviceWithArgs(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, const char *sDeviceName, GWEN_BUFFER *dbuf) { GWEN_DB_NODE *dbQuery; AQH_DEVICE *device; dbQuery=AQCGI_Request_GetDbQuery(rq); DBG_ERROR(NULL, "Device=%s", sDeviceName?sDeviceName:""); GBAA(dbuf,"

Device %s

\n", sDeviceName); device=AQH_ModDevices_GetDevice(dc, sDeviceName); if (device) { _mkDeviceForm(dc, sDeviceName, device, dbuf); AQH_Device_free(device); } } void _mkDeviceForm(AQH_DATACLIENT *dc, const char *sDeviceName, const AQH_DEVICE *device, GWEN_BUFFER *dbuf) { const char *s; GBAS(dbuf,"
\n"); GBAA(dbuf, "\n", sDeviceName); GBAS(dbuf,"\n"); _addFieldToForm(I18N("Room"), "roomName", AQH_Device_GetRoomName(device), dbuf); _addFieldToForm(I18N("GUI Name"), "nameForGui", AQH_Device_GetNameForGui(device), dbuf); _addFieldToForm(I18N("Location"), "location", AQH_Device_GetLocation(device), dbuf); _addFieldToForm(I18N("Description"), "description", AQH_Device_GetDescription(device), dbuf); GBAS(dbuf,"
\n"); GBAS(dbuf,"
\n"); GBAS(dbuf,""); GBAS(dbuf, "
\n\n"); } void _addFieldToForm(const char *sFieldTitle, const char *sFieldName, const char *sFieldContent, GWEN_BUFFER *dbuf) { GBAS(dbuf, ""); GBAA(dbuf, "", sFieldName, sFieldTitle); GBAA(dbuf, "", sFieldName, sFieldContent?sFieldContent:""); GBAS(dbuf, ""); }