aqhome-react: periodically check for network file changes and reload if necessary.

This commit is contained in:
Martin Preuss
2024-03-24 14:21:20 +01:00
parent e0476924c1
commit 6f9e20095a
6 changed files with 91 additions and 1 deletions

View File

@@ -20,6 +20,11 @@
#include <gwenhywfar/text.h>
#include <gwenhywfar/debug.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
/* ------------------------------------------------------------------------------------------------
@@ -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;