aqhome-apps: all apps now work again.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
|
||||
* AqHome (c) by 2025 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.
|
||||
@@ -10,18 +10,17 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "./init.h"
|
||||
#include "./fini.h"
|
||||
#include "./loop.h"
|
||||
#include "./server.h"
|
||||
#include "./net_read.h"
|
||||
#include "aqhome-react/units/u_timer.h"
|
||||
#include "aqhome-react/types/prgrule-t.h"
|
||||
#include "aqhome-react/types/prgrule.h"
|
||||
//#include "aqhome-react/types/prgrule-t.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/data/path-t.h"
|
||||
#include "aqhome/data/vars-t.h"
|
||||
#include "aqhome/data/vars_dbread-t.h"
|
||||
#include "aqhome/data/vars_dbwrite-t.h"
|
||||
//#include "aqhome/data/vars_dbread-t.h"
|
||||
//#include "aqhome/data/vars_dbwrite-t.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/args.h>
|
||||
@@ -59,20 +58,24 @@
|
||||
#define AQHOME_REACT_READNET_INTERVAL 300
|
||||
#define AQHOME_REACT_SAVE_INTERVAL 300
|
||||
|
||||
#define CONNCLEAN_INTERVAL_IN_SECS 2
|
||||
#define CONNCHECK_INTERVAL_IN_SECS 10
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _serve(AQHOME_REACT *aqh);
|
||||
static int _testModules(int argc, char **argv);
|
||||
static void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop);
|
||||
static int _diffInSeconds(time_t t1, time_t t0);
|
||||
//static int _testModules(int argc, char **argv);
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
static int _setSignalHandlers(void);
|
||||
static int _setupSigAction(struct sigaction *sa, int sig);
|
||||
static void _signalHandler(int s);
|
||||
static struct sigaction saINT,saTERM, saHUP, saTSTP, saCONT;
|
||||
static struct sigaction saINT,saTERM, saHUP, saTSTP, saCONT, saPIPE;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -93,11 +96,10 @@ static int stopService=0;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
AQHOME_REACT *aqh;
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
int rv;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
AQH_OBJECT *aqh;
|
||||
GWEN_GUI *gui;
|
||||
const char *s;
|
||||
|
||||
rv=GWEN_Init();
|
||||
if (rv) {
|
||||
@@ -106,7 +108,14 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
GWEN_Logger_Open(0, "aqhome-react", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);
|
||||
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Warning);
|
||||
//GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Warning);
|
||||
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
|
||||
|
||||
rv=_setSignalHandlers();
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
@@ -115,127 +124,93 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
gui=GWEN_Gui_CGui_new();
|
||||
GWEN_Gui_SetGui(gui);
|
||||
|
||||
aqh=AqHomeReact_new();
|
||||
rv=AqHomeReact_Init(aqh, argc, argv);
|
||||
dbArgs=AqHomeReact_GetDbArgs(aqh);
|
||||
DBG_ERROR(NULL, "RV=%d", rv);
|
||||
eventLoop=AQH_EventLoop_new();
|
||||
aqh=AQH_ReactServer_new(eventLoop);
|
||||
rv=AQH_ReactServer_Init(aqh, argc, argv);
|
||||
if (rv<0) {
|
||||
if (rv==GWEN_ERROR_CLOSE)
|
||||
return 1;
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
else if (rv>0) {
|
||||
argc-=rv;
|
||||
argv+=rv;
|
||||
|
||||
s=GWEN_DB_GetCharValue(dbArgs, "params", 0, NULL);
|
||||
if (s && *s && strcasecmp(s, "modtest")==0)
|
||||
rv=_testModules(argc, argv);
|
||||
else {
|
||||
DBG_ERROR(NULL, "Invalid command \"%s\"", s?s:"<no command>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s=GWEN_DB_GetCharValue(dbArgs, "charset", 0, NULL);
|
||||
if (s && *s)
|
||||
GWEN_Gui_SetCharSet(gui, s);
|
||||
GWEN_Gui_SetGui(gui);
|
||||
_runService(aqh, eventLoop);
|
||||
|
||||
_serve(aqh);
|
||||
rv=0;
|
||||
}
|
||||
|
||||
AqHomeReact_Fini(aqh);
|
||||
AqHomeReact_free(aqh);
|
||||
//AQH_NodeServer_Fini(aqh);
|
||||
AQH_Object_free(aqh);
|
||||
|
||||
GWEN_Gui_SetGui(NULL);
|
||||
GWEN_Gui_free(gui);
|
||||
|
||||
return rv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _serve(AQHOME_REACT *aqh)
|
||||
void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
int rv;
|
||||
time_t timeStart;
|
||||
int timeout;
|
||||
time_t startTime;
|
||||
time_t lastTimerTime;
|
||||
time_t timeLastConnCheck;
|
||||
time_t lastFileScanTime;
|
||||
time_t lastSaveTime;
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
AQHREACT_UNIT *timerUnit;
|
||||
|
||||
startTime=time(NULL);
|
||||
lastTimerTime=startTime;
|
||||
lastFileScanTime=startTime;
|
||||
lastSaveTime=startTime;
|
||||
timeout=AQH_ReactServer_GetTimeout(aqh);
|
||||
timeStart=time(NULL);
|
||||
timeLastConnCheck=time(NULL);
|
||||
lastFileScanTime=timeStart;
|
||||
lastSaveTime=timeStart;
|
||||
|
||||
AqHomeReact_SetLatestNetworkFileTime(aqh, AQHomeReact_GetNewestUnitNetFiletime());
|
||||
|
||||
dbArgs=AqHomeReact_GetDbArgs(aqh);
|
||||
timerUnit=AqHomeReact_GetTimerUnit(aqh);
|
||||
|
||||
rv=_setSignalHandlers();
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error setting signal handlers (%d)", rv);
|
||||
return;
|
||||
}
|
||||
|
||||
timeout=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 0);
|
||||
AQH_ReactServer_SetLatestNetworkFileTime(aqh, AQH_ReactServer_GetNewestUnitNetFiletime());
|
||||
|
||||
while(!stopService) {
|
||||
time_t now;
|
||||
int rv;
|
||||
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
|
||||
AqHomeReact_IoLoop(aqh, 500);
|
||||
AQH_EventLoop_Run(eventLoop, 2000);
|
||||
AQH_ReactServer_HandleBrokerMsgs(aqh);
|
||||
|
||||
now=time(NULL);
|
||||
if (now!=lastTimerTime) {
|
||||
lastTimerTime=now;
|
||||
AqHomeReact_UnitTimer_GenerateTick(timerUnit);
|
||||
|
||||
if (_diffInSeconds(now, timeLastConnCheck)>CONNCHECK_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Check connections");
|
||||
AQH_ReactServer_CheckBrokerConnection(aqh);
|
||||
timeLastConnCheck=now;
|
||||
}
|
||||
|
||||
AqHomeReact_ProcessAllUnits(aqh);
|
||||
AQH_ReactServer_ProcessAllUnits(aqh);
|
||||
|
||||
if ((now-lastFileScanTime)>AQHOME_REACT_READNET_INTERVAL) {
|
||||
if (_diffInSeconds(now, lastFileScanTime)>AQHOME_REACT_READNET_INTERVAL) {
|
||||
time_t tNew;
|
||||
time_t t;
|
||||
|
||||
DBG_INFO(NULL, "Checking network files");
|
||||
tNew=AQHomeReact_GetNewestUnitNetFiletime();
|
||||
t=AqHomeReact_GetLatestNetworkFileTime(aqh);
|
||||
tNew=AQH_ReactServer_GetNewestUnitNetFiletime();
|
||||
t=AQH_ReactServer_GetLatestNetworkFileTime(aqh);
|
||||
if (tNew && tNew>t) {
|
||||
DBG_INFO(NULL, "Reloading network files");
|
||||
AqHomeReact_ReloadUnitNets(aqh);
|
||||
AqHomeReact_SetLatestNetworkFileTime(aqh, tNew);
|
||||
AQH_ReactServer_ReloadUnitNets(aqh);
|
||||
AQH_ReactServer_SetLatestNetworkFileTime(aqh, tNew);
|
||||
}
|
||||
lastFileScanTime=now;
|
||||
}
|
||||
|
||||
if (now-lastSaveTime>AQHOME_REACT_SAVE_INTERVAL) {
|
||||
if (_diffInSeconds(now, lastSaveTime)>AQHOME_REACT_SAVE_INTERVAL) {
|
||||
DBG_ERROR(NULL, "Writing var file");
|
||||
rv=AqHomeReact_WriteVarsFile(aqh);
|
||||
rv=AQH_ReactServer_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");
|
||||
break;
|
||||
}
|
||||
if (timeout && (_diffInSeconds(now, timeStart)>timeout)) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
|
||||
} /* while */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +232,10 @@ int _setSignalHandlers(void)
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
rv=_setupSigAction(&saPIPE, SIGPIPE);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
# ifdef SIGTSTP
|
||||
rv=_setupSigAction(&saTSTP, SIGTSTP);
|
||||
if (rv)
|
||||
@@ -298,6 +277,9 @@ void _signalHandler(int s)
|
||||
DBG_WARN(0, "Received signal %d, stopping service in next loop.",s);
|
||||
stopService=1;
|
||||
break;
|
||||
case SIGPIPE:
|
||||
DBG_WARN(0, "Received PIPE signal");
|
||||
break;
|
||||
default:
|
||||
DBG_WARN(0, "Unknown signal %d",s);
|
||||
break;
|
||||
@@ -305,7 +287,7 @@ void _signalHandler(int s)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
int _testModules(int argc, char **argv)
|
||||
{
|
||||
GWEN_GUI *gui;
|
||||
@@ -362,7 +344,13 @@ int _testModules(int argc, char **argv)
|
||||
GWEN_Gui_free(gui);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
int _diffInSeconds(time_t t1, time_t t0)
|
||||
{
|
||||
return t1-t0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user