aqhome-nodes: started using requests.
This commit is contained in:
138
apps/aqhome-nodes/requests.c
Normal file
138
apps/aqhome-nodes/requests.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2024 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 "./requests.h"
|
||||
#include "./aqhomed_p.h"
|
||||
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
|
||||
#include <gwenhywfar/request.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
static void _freeFinishedRequests(GWEN_MSG_REQUEST *rq);
|
||||
|
||||
|
||||
|
||||
|
||||
void AqHomeNodes_Requests_CheckTimeouts(AQHOMED *aqh)
|
||||
{
|
||||
if (aqh && aqh->requestTree) {
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
GWEN_TIMESTAMP *now;
|
||||
|
||||
now=GWEN_Timestamp_NowInLocalTime();
|
||||
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
|
||||
while(rq) {
|
||||
const GWEN_TIMESTAMP *ts;
|
||||
|
||||
ts=GWEN_MsgRequest_GetExpiresAt(rq);
|
||||
if (GWEN_Timestamp_Compare(now, ts)>=0) {
|
||||
/* timeout */
|
||||
DBG_INFO(NULL, "Request timed out, aborting");
|
||||
GWEN_MsgRequest_Abort(rq);
|
||||
}
|
||||
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
GWEN_Timestamp_free(now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AqHomeNodes_Requests_Cleanup(AQHOMED *aqh)
|
||||
{
|
||||
if (aqh && aqh->requestTree) {
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
|
||||
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
|
||||
while(rq) {
|
||||
GWEN_MSG_REQUEST *nextSubRq;
|
||||
|
||||
nextSubRq=GWEN_MsgRequest_Tree2_GetNext(rq);
|
||||
_freeFinishedRequests(rq);
|
||||
rq=nextSubRq;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeNodes_Requests_HandleIpcMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg)
|
||||
{
|
||||
if (aqh && aqh->requestTree) {
|
||||
uint32_t refMsgId;
|
||||
|
||||
refMsgId=GWEN_IpcMsg_GetRefMsgId(recvdMsg);
|
||||
if (refMsgId) {
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
|
||||
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
|
||||
while(rq) {
|
||||
if (srcEp==GWEN_MsgRequest_GetEndpoint(rq) && refMsgId==GWEN_MsgRequest_GetRequestMsgId(rq)) {
|
||||
if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED)
|
||||
return GWEN_MSG_REQUEST_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Message has no reference msg id, not a response");
|
||||
}
|
||||
}
|
||||
return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeNodes_Requests_HandleTtyMsg(AQHOMED *aqh, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg)
|
||||
{
|
||||
if (aqh && aqh->requestTree) {
|
||||
GWEN_MSG_REQUEST *rq;
|
||||
|
||||
rq=GWEN_MsgRequest_Tree2_GetFirstChild(aqh->requestTree);
|
||||
while(rq) {
|
||||
if (srcEp==GWEN_MsgRequest_GetEndpoint(rq)) {
|
||||
if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED)
|
||||
return GWEN_MSG_REQUEST_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
rq=GWEN_MsgRequest_Tree2_GetBelow(rq);
|
||||
}
|
||||
}
|
||||
return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _freeFinishedRequests(GWEN_MSG_REQUEST *rq)
|
||||
{
|
||||
GWEN_MSG_REQUEST *subRq;
|
||||
|
||||
subRq=GWEN_MsgRequest_Tree2_GetFirstChild(rq);
|
||||
while(subRq) {
|
||||
GWEN_MSG_REQUEST *nextSubRq;
|
||||
|
||||
nextSubRq=GWEN_MsgRequest_Tree2_GetNext(subRq);
|
||||
_freeFinishedRequests(subRq);
|
||||
subRq=nextSubRq;
|
||||
}
|
||||
|
||||
if (GWEN_MsgRequest_GetState(rq)==GWEN_MSG_REQUEST_STATE_DONE)
|
||||
GWEN_MsgRequest_free(rq);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user