aqhome-react: peridocally write vars.
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "aqhome-react/units/u_timeprogram.h"
|
||||
#include "aqhome-react/units/u_statfns.h"
|
||||
|
||||
#include "aqhome/data/vars_dbwrite.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
@@ -295,6 +297,22 @@ int AqHomeReact_DecIntValue(AQHOME_REACT *aqh, const char *path, int startValue,
|
||||
|
||||
|
||||
|
||||
int AqHomeReact_WriteVarsFile(AQHOME_REACT *aqh)
|
||||
{
|
||||
if (aqh && aqh->localVars && aqh->varsFile) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_Vars_WriteDbFile(aqh->localVars, aqh->varsFile);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType)
|
||||
{
|
||||
/* this does not include u_timer and u_varchanges, because those are only created once globally in init.c */
|
||||
|
||||
@@ -60,6 +60,7 @@ int AqHomeReact_GetIntValue(AQHOME_REACT *aqh, const char *path, int idx, int de
|
||||
int AqHomeReact_IncIntValue(AQHOME_REACT *aqh, const char *path, int startValue, int defaultValue);
|
||||
int AqHomeReact_DecIntValue(AQHOME_REACT *aqh, const char *path, int startValue, int defaultValue);
|
||||
|
||||
int AqHomeReact_WriteVarsFile(AQHOME_REACT *aqh);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
#define FULL_DEBUG
|
||||
|
||||
#define AQHOME_REACT_READNET_INTERVAL 300
|
||||
|
||||
#define AQHOME_REACT_SAVE_INTERVAL 300
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -166,12 +166,14 @@ void _serve(AQHOME_REACT *aqh)
|
||||
time_t startTime;
|
||||
time_t lastTimerTime;
|
||||
time_t lastFileScanTime;
|
||||
time_t lastSaveTime;
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
AQHREACT_UNIT *timerUnit;
|
||||
|
||||
startTime=time(NULL);
|
||||
lastTimerTime=startTime;
|
||||
lastFileScanTime=startTime;
|
||||
lastSaveTime=startTime;
|
||||
|
||||
AqHomeReact_SetLatestNetworkFileTime(aqh, AQHomeReact_GetNewestUnitNetFiletime());
|
||||
|
||||
@@ -216,6 +218,15 @@ void _serve(AQHOME_REACT *aqh)
|
||||
lastFileScanTime=now;
|
||||
}
|
||||
|
||||
if (now-lastSaveTime>AQHOME_REACT_SAVE_INTERVAL) {
|
||||
DBG_ERROR(NULL, "Writing var file");
|
||||
rv=AqHomeReact_WriteVarsFile(aqh);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error writing runtime data");
|
||||
}
|
||||
lastSaveTime=time(NULL);
|
||||
}
|
||||
|
||||
if (timeout) {
|
||||
if ((now-startTime)>timeout) {
|
||||
DBG_ERROR(NULL, "Timeout, stopping service");
|
||||
|
||||
Reference in New Issue
Block a user