/**************************************************************************** * 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_getvalues.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_values.h" #include "aqhome/msg/ipc/m_ipc_result.h" #include "aqhome/msg/ipc/m_ipc_tag16.h" #include /* ------------------------------------------------------------------------------------------------ * defines * ------------------------------------------------------------------------------------------------ */ #define AQHOMEDATA_VALUESPERMSG 10 /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ static void _sendValueList(AQH_OBJECT *ep, const AQH_VALUE_LIST *vl, uint32_t flags, uint32_t refMsgId); /* ------------------------------------------------------------------------------------------------ * implementations * ------------------------------------------------------------------------------------------------ */ void AqHomeDataServer_HandleGetValues(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg) { AQHOME_SERVER *xo; xo=AqHomeDataServer_GetServerData(o); if (xo) { const AQH_VALUE_LIST *origValueList; uint32_t refMsgId; refMsgId=AQH_IpcMessage_GetMsgId(msg); DBG_INFO(NULL, "HandleGetValues"); origValueList=AQH_Storage_GetValueList(xo->storage); if (origValueList) { DBG_INFO(NULL, "Have a list of %d values", AQH_Value_List_GetCount(origValueList)); if (AQH_Value_List_GetCount(origValueList)=AQHOMEDATA_VALUESPERMSG) { DBG_INFO(NULL, "Sending %d values", AQH_Value_List_GetCount(tmpValueList)); _sendValueList(ep, tmpValueList, next?0:AQH_MSGDATA_VALUES_FLAGS_LASTMSG, refMsgId); AQH_Value_List_Clear(tmpValueList); } v=next; } if (AQH_Value_List_GetCount(tmpValueList)) { DBG_INFO(NULL, "Sending %d values", AQH_Value_List_GetCount(tmpValueList)); _sendValueList(ep, tmpValueList, AQH_MSGDATA_VALUES_FLAGS_LASTMSG, refMsgId); /* send remaining */ } AQH_Value_List_free(tmpValueList); } } else { /* empty list */ _sendValueList(ep, NULL, AQH_MSGDATA_VALUES_FLAGS_LASTMSG, refMsgId); } } } void _sendValueList(AQH_OBJECT *ep, const AQH_VALUE_LIST *vl, uint32_t flags, uint32_t refMsgId) { AQH_MESSAGE *msg; DBG_ERROR(NULL, "Sending msg (refMsgId=%d)", refMsgId); msg=AQH_IpcdMessageValues_new(AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP, AQH_Endpoint_GetNextMessageId(ep), refMsgId, flags, vl); AQH_Endpoint_AddMsgOut(ep, msg); }