aqhome-react: periodically check for network file changes and reload if necessary.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "./init.h"
|
||||
#include "./fini.h"
|
||||
#include "./loop.h"
|
||||
#include "./net_read.h"
|
||||
#include "aqhome-react/units/u_timer.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
@@ -49,6 +50,8 @@
|
||||
|
||||
#define FULL_DEBUG
|
||||
|
||||
#define AQHOME_REACT_READNET_INTERVAL 60
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -140,11 +143,13 @@ void _serve(AQHOME_REACT *aqh)
|
||||
int timeout;
|
||||
time_t startTime;
|
||||
time_t lastTimerTime;
|
||||
time_t lastFileScanTime;
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
AQHREACT_UNIT *timerUnit;
|
||||
|
||||
startTime=time(NULL);
|
||||
lastTimerTime=startTime;
|
||||
lastFileScanTime=startTime;
|
||||
|
||||
dbArgs=AqHomeReact_GetDbArgs(aqh);
|
||||
timerUnit=AqHomeReact_GetTimerUnit(aqh);
|
||||
@@ -172,6 +177,20 @@ void _serve(AQHOME_REACT *aqh)
|
||||
|
||||
AqHomeReact_ProcessAllUnits(aqh);
|
||||
|
||||
if ((now-lastFileScanTime)>AQHOME_REACT_READNET_INTERVAL) {
|
||||
time_t tNew;
|
||||
time_t t;
|
||||
|
||||
DBG_INFO(NULL, "Checking network files");
|
||||
tNew=AQHREACT_GetNewestUnitNetFiletime(aqh);
|
||||
t=AqHomeReact_GetLatestNetworkFileTime(aqh);
|
||||
if (tNew && tNew>t) {
|
||||
DBG_INFO(NULL, "Reloading network files");
|
||||
AqHomeReact_ReloadUnitNets(aqh);
|
||||
AqHomeReact_SetLatestNetworkFileTime(aqh, tNew);
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout) {
|
||||
if ((now-startTime)>timeout) {
|
||||
DBG_ERROR(NULL, "Timeout, stopping service");
|
||||
|
||||
Reference in New Issue
Block a user