diff --git a/apps/aqhome-react/aqhome_react.c b/apps/aqhome-react/aqhome_react.c index dd43675..46e244a 100644 --- a/apps/aqhome-react/aqhome_react.c +++ b/apps/aqhome-react/aqhome_react.c @@ -90,6 +90,21 @@ int AqHomeReact_GetTimeout(const AQHOME_REACT *aqh) +time_t AqHomeReact_GetLatestNetworkFileTime(const AQHOME_REACT *aqh) +{ + return aqh?aqh->latestNetworkFileTime:0; +} + + + +void AqHomeReact_SetLatestNetworkFileTime(AQHOME_REACT *aqh, time_t t) +{ + if (aqh) + aqh->latestNetworkFileTime=t; +} + + + AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh) { return aqh?aqh->timerUnit:NULL; diff --git a/apps/aqhome-react/aqhome_react.h b/apps/aqhome-react/aqhome_react.h index 5b8b0a6..499fcda 100644 --- a/apps/aqhome-react/aqhome_react.h +++ b/apps/aqhome-react/aqhome_react.h @@ -30,6 +30,10 @@ void AqHomeReact_SetPidFile(AQHOME_REACT *aqh, const char *s); int AqHomeReact_GetTimeout(const AQHOME_REACT *aqh); +time_t AqHomeReact_GetLatestNetworkFileTime(const AQHOME_REACT *aqh); +void AqHomeReact_SetLatestNetworkFileTime(AQHOME_REACT *aqh, time_t t); + + AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh); AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh); diff --git a/apps/aqhome-react/aqhome_react_p.h b/apps/aqhome-react/aqhome_react_p.h index d5b7d0b..a017a64 100644 --- a/apps/aqhome-react/aqhome_react_p.h +++ b/apps/aqhome-react/aqhome_react_p.h @@ -12,6 +12,9 @@ #include "./aqhome_react.h" +#include + + #define AQHOME_REACT_DEFAULT_PIDFILE "/var/run/aqhome-react.pid" #define AQHOME_REACT_DEFAULT_DATADIR "/var/lib/aqhome-react" @@ -21,7 +24,6 @@ - struct AQHOME_REACT { GWEN_MSG_ENDPOINT *brokerEndpoint; @@ -33,6 +35,8 @@ struct AQHOME_REACT { AQHREACT_UNIT *varChangeUnit; AQHREACT_UNIT_LIST *unitList; AQHREACT_UNIT_NET_LIST *unitNetList; + + time_t latestNetworkFileTime; }; diff --git a/apps/aqhome-react/main.c b/apps/aqhome-react/main.c index 327318c..e43bfca 100644 --- a/apps/aqhome-react/main.c +++ b/apps/aqhome-react/main.c @@ -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"); diff --git a/apps/aqhome-react/net_read.c b/apps/aqhome-react/net_read.c index 03628fb..a5f201b 100644 --- a/apps/aqhome-react/net_read.c +++ b/apps/aqhome-react/net_read.c @@ -20,6 +20,11 @@ #include #include +#include +#include +#include +#include + /* ------------------------------------------------------------------------------------------------ @@ -41,6 +46,47 @@ static int _readLink(AQHOME_REACT *aqh, AQHREACT_UNIT_NET *unitNet, GWEN_XMLNODE * ------------------------------------------------------------------------------------------------ */ + +time_t AQHREACT_GetNewestUnitNetFiletime(const AQHOME_REACT *aqh) +{ + GWEN_STRINGLIST *sl; + time_t resultTime=0; + + sl=AQH_GetListOfMatchingDataFiles("aqhome/react/networks", "*.xml"); + if (sl) { + GWEN_STRINGLISTENTRY *se; + + se=GWEN_StringList_FirstEntry(sl); + while(se) { + const char *s; + + s=GWEN_StringListEntry_Data(se); + if (s && *s) { + struct stat sb; + + if (stat(s, &sb)==0) { + time_t t; + + t=sb.st_mtim.tv_sec; + if (t>resultTime) + resultTime=t; + } + else { + DBG_WARN(NULL, "Error on stat(%s): %s (%d)", s, strerror(errno), errno); + } + } + se=GWEN_StringListEntry_Next(se); + } + } + else { + DBG_ERROR(NULL, "No unit network files"); + } + + return resultTime; +} + + + AQHREACT_UNIT_NET_LIST *AQHREACT_ReadUnitNetFiles(AQHOME_REACT *aqh) { GWEN_STRINGLIST *sl; diff --git a/apps/aqhome-react/net_read.h b/apps/aqhome-react/net_read.h index de78638..4273bc3 100644 --- a/apps/aqhome-react/net_read.h +++ b/apps/aqhome-react/net_read.h @@ -15,6 +15,8 @@ AQHREACT_UNIT_NET_LIST *AQHREACT_ReadUnitNetFiles(AQHOME_REACT *aqh); +time_t AQHREACT_GetNewestUnitNetFiletime(const AQHOME_REACT *aqh); + #endif