/**************************************************************************** * 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 "./s_getdevices.h" #include "./server_p.h" #include "aqhome/ipc2/endpoint.h" #include "aqhome/msg/ipc/m_ipc.h" #include "aqhome/msg/ipc/data/m_ipcd.h" #include "aqhome/msg/ipc/data/m_ipcd_devices.h" #include "aqhome/msg/ipc/m_ipc_result.h" #include "aqhome/msg/ipc/m_ipc_tag16.h" #include /* ------------------------------------------------------------------------------------------------ * defines * ------------------------------------------------------------------------------------------------ */ #define AQHOMEDATA_DEVICESPERMSG 10 /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ static void _sendDeviceList(AQH_OBJECT *ep, const AQH_DEVICE_LIST *vl, uint32_t flags, uint32_t refMsgId); /* ------------------------------------------------------------------------------------------------ * implementations * ------------------------------------------------------------------------------------------------ */ void AqHomeDataServer_HandleGetDevices(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList) { AQHOME_SERVER *xo; xo=AqHomeDataServer_GetServerData(o); if (xo) { const AQH_DEVICE_LIST *origDeviceList; uint32_t refMsgId; refMsgId=AQH_IpcMessage_GetMsgId(msg); DBG_ERROR(NULL, "HandleGetDevices"); origDeviceList=AQH_Storage_GetDeviceList(xo->storage); if (origDeviceList) { DBG_ERROR(NULL, "Have a list of %d devices", AQH_Device_List_GetCount(origDeviceList)); if (AQH_Device_List_GetCount(origDeviceList)=AQHOMEDATA_DEVICESPERMSG) { DBG_ERROR(NULL, "Sending %d devices", AQH_Device_List_GetCount(tmpDeviceList)); _sendDeviceList(ep, tmpDeviceList, next?0:AQH_MSGDATA_DEVICES_FLAGS_LASTMSG, refMsgId); AQH_Device_List_Clear(tmpDeviceList); } v=next; } if (AQH_Device_List_GetCount(tmpDeviceList)) { DBG_ERROR(NULL, "Sending %d devices", AQH_Device_List_GetCount(tmpDeviceList)); _sendDeviceList(ep, tmpDeviceList, AQH_MSGDATA_DEVICES_FLAGS_LASTMSG, refMsgId); /* send remaining */ } AQH_Device_List_free(tmpDeviceList); } } else { /* empty list */ _sendDeviceList(ep, NULL, AQH_MSGDATA_DEVICES_FLAGS_LASTMSG, refMsgId); } } } void _sendDeviceList(AQH_OBJECT *ep, const AQH_DEVICE_LIST *vl, uint32_t flags, uint32_t refMsgId) { AQH_MESSAGE *msg; DBG_ERROR(NULL, "Sending msg (refMsgId=%d)", refMsgId); msg=AQH_IpcdMessageDevices_new(AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP, AQH_Endpoint_GetNextMessageId(ep), refMsgId, flags, vl); AQH_Endpoint_AddMsgOut(ep, msg); }