moved code for device module into its own folder. Implement graphs.
This commit is contained in:
129
apps/aqhome-cgi/modules/devices/mdevices_init.c
Normal file
129
apps/aqhome-cgi/modules/devices/mdevices_init.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
* 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 <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "./mdevices_init.h"
|
||||
|
||||
#include "aqhome-cgi/service/module.h"
|
||||
#include "aqhome-cgi/modules/mdataclient.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defs and enums
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define GBAS GWEN_Buffer_AppendString
|
||||
#define GBAA GWEN_Buffer_AppendArgs
|
||||
|
||||
#define P_DEVICEREAD AQH_MODDEVICES_PERMS_DEVICEREAD
|
||||
#define P_VALUEREAD AQH_MODDEVICES_PERMS_VALUEREAD
|
||||
#define P_VALUEWRITE AQH_MODDEVICES_PERMS_VALUEWRITE
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _createPermDefList(AQH_MODULE *m);
|
||||
static void _createRoleList(AQH_MODULE *m);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int AQH_ModDevices_Create(AQH_SERVICE *sv)
|
||||
{
|
||||
AQH_MODULE *m;
|
||||
int rv;
|
||||
|
||||
m=AQH_Module_new();
|
||||
AQH_Module_SetName(m, "devices");
|
||||
AQH_Module_SetDescr(m, "device module");
|
||||
AQH_Module_SetGuestPerms(m, 0);
|
||||
|
||||
_createPermDefList(m);
|
||||
_createRoleList(m);
|
||||
|
||||
rv=AQH_Service_AddModule(sv, m);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
}
|
||||
AQH_Module_free(m);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _createPermDefList(AQH_MODULE *m)
|
||||
{
|
||||
AQH_PERMDEF_LIST *permDefList;
|
||||
|
||||
permDefList=AQH_PermDef_List_new();
|
||||
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceRead", 0x001, "Read and list devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceWrite", 0x002, "Modify devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceAdd", 0x004, "Add devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceDel", 0x008, "Remove devices");
|
||||
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueRead", 0x010, "Read and list values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueWrite", 0x020, "Modify values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueAdd", 0x040, "Add values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueDel", 0x080, "Remove values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueSet", 0x100, "Set values");
|
||||
|
||||
AQH_Module_SetPermDefList(m, permDefList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _createRoleList(AQH_MODULE *m)
|
||||
{
|
||||
AQH_ROLE_LIST *roleList;
|
||||
int id=0;
|
||||
|
||||
roleList=AQH_Role_List_new();
|
||||
AQH_ModService_AddRole(roleList, id++, "Reader",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD,
|
||||
"Read devices and values");
|
||||
AQH_ModService_AddRole(roleList, id++, "Writer",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_DEVICEWRITE |
|
||||
AQH_MODDEVICES_PERMS_DEVICEADD |
|
||||
AQH_MODDEVICES_PERMS_DEVICEDEL |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEWRITE |
|
||||
AQH_MODDEVICES_PERMS_VALUEADD |
|
||||
AQH_MODDEVICES_PERMS_VALUEDEL |
|
||||
AQH_MODDEVICES_PERMS_VALUESET,
|
||||
"Read and write devices and values");
|
||||
AQH_ModService_AddRole(roleList, id++, "Setter",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUESET,
|
||||
"Set values");
|
||||
AQH_Module_SetRoleList(m, roleList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user