aqhome: more work on transformation to event2/ipc2.
This commit is contained in:
@@ -13,10 +13,7 @@
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/aqhome.h>
|
||||
|
||||
#include "./aqhome_data.h"
|
||||
#include "./init.h"
|
||||
#include "./fini.h"
|
||||
#include "./loop.h"
|
||||
#include "./server.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/logger.h>
|
||||
@@ -58,8 +55,9 @@ static int _setupSigAction(struct sigaction *sa, int sig);
|
||||
static void _signalHandler(int s);
|
||||
#endif
|
||||
|
||||
static void _runService(AQHOME_DATA *aqh);
|
||||
static void _writeCurrentState(AQHOME_DATA *aqh);
|
||||
static void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop);
|
||||
static void _writeCurrentState(AQH_OBJECT *aqh);
|
||||
static int _diffInSeconds(time_t t1, time_t t0);
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +82,8 @@ static int stopService=0;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rv;
|
||||
AQHOME_DATA *aqh;
|
||||
AQH_EVENT_LOOP *eventLoop;
|
||||
AQH_OBJECT *aqh;
|
||||
GWEN_GUI *gui;
|
||||
|
||||
rv=GWEN_Init();
|
||||
@@ -111,17 +110,18 @@ int main(int argc, char **argv)
|
||||
gui=GWEN_Gui_CGui_new();
|
||||
GWEN_Gui_SetGui(gui);
|
||||
|
||||
aqh=AqHomeData_new();
|
||||
rv=AqHomeData_Init(aqh, argc, argv);
|
||||
eventLoop=AQH_EventLoop_new();
|
||||
aqh=AqHomeDataServer_new(eventLoop);
|
||||
rv=AqHomeDataServer_Init(aqh, argc, argv);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
_runService(aqh);
|
||||
_runService(aqh, eventLoop);
|
||||
|
||||
AqHomeData_Fini(aqh);
|
||||
AqHomeData_free(aqh);
|
||||
//AqHomeData_Fini(aqh);
|
||||
AQH_Object_free(aqh);
|
||||
|
||||
GWEN_Gui_SetGui(NULL);
|
||||
GWEN_Gui_free(gui);
|
||||
@@ -131,14 +131,14 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
void _runService(AQHOME_DATA *aqh)
|
||||
void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
|
||||
{
|
||||
time_t timeStart;
|
||||
time_t timeLastWrite;
|
||||
time_t timeLastConnectionCleanup;
|
||||
int timeout;
|
||||
|
||||
timeout=AqHomeData_GetTimeout(aqh);
|
||||
timeout=AqHomeDataServer_GetTimeout(aqh);
|
||||
timeStart=time(NULL);
|
||||
timeLastWrite=time(NULL);
|
||||
timeLastConnectionCleanup=time(NULL);
|
||||
@@ -146,25 +146,26 @@ void _runService(AQHOME_DATA *aqh)
|
||||
while(!stopService) {
|
||||
time_t now;
|
||||
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
AqHomeData_Loop(aqh, 2000);
|
||||
DBG_ERROR(NULL, "Next loop (%d clients)", AqHomeDataServer_GetClientNum(aqh));
|
||||
AQH_EventLoop_Run(eventLoop, 2000);
|
||||
AqHomeDataServer_HandleClientMsgs(aqh);
|
||||
|
||||
now=time(NULL);
|
||||
|
||||
if (((int)difftime(now, timeLastConnectionCleanup))>CONNCLEAN_INTERVAL_IN_SECS) {
|
||||
DBG_DEBUG(NULL, "Cleanup connections");
|
||||
GWEN_MsgEndpoint_RemoveUnconnectedAndEmptyChildren(AqHomeData_GetIpcdEndpoint(aqh));
|
||||
if (_diffInSeconds(now, timeLastConnectionCleanup)>CONNCLEAN_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Cleanup connections");
|
||||
AqHomeDataServer_CleanupClients(aqh);
|
||||
timeLastConnectionCleanup=now;
|
||||
}
|
||||
|
||||
if (((int)difftime(now, timeLastWrite))>WRITE_INTERVAL_IN_SECS) {
|
||||
DBG_DEBUG(NULL, "Write time");
|
||||
if (_diffInSeconds(now, timeLastWrite)>WRITE_INTERVAL_IN_SECS) {
|
||||
DBG_ERROR(NULL, "Write time");
|
||||
_writeCurrentState(aqh);
|
||||
timeLastWrite=now;
|
||||
}
|
||||
|
||||
if (timeout && ((int)difftime(now, timeStart))>timeout) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
if (timeout && (_diffInSeconds(now, timeStart)>timeout)) {
|
||||
DBG_ERROR(NULL, "Timeout");
|
||||
_writeCurrentState(aqh);
|
||||
break;
|
||||
}
|
||||
@@ -173,11 +174,17 @@ void _runService(AQHOME_DATA *aqh)
|
||||
|
||||
|
||||
|
||||
void _writeCurrentState(AQHOME_DATA *aqh)
|
||||
int _diffInSeconds(time_t t1, time_t t0)
|
||||
{
|
||||
return t1-t0;
|
||||
}
|
||||
|
||||
|
||||
void _writeCurrentState(AQH_OBJECT *aqh)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv=AqHomeData_WriteStorageIfChanged(aqh);
|
||||
rv=AqHomeDataServer_WriteStorageIfChanged(aqh);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "ATTENTION: Could not write storage statefile (%d)", rv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user