diff --git a/.gitignore b/.gitignore index d684224..3a57432 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,7 @@ aqhome-data.pid aqhome-nodes.db aqhome-nodes.log aqhome-nodes.pid +aqhome-nodes.vg +aqhome-tool.vg aqhome-mqtt.pid diff --git a/apps/aqhome-nodes/aqhomed.c b/apps/aqhome-nodes/aqhomed.c index 0c3b5c4..1649125 100644 --- a/apps/aqhome-nodes/aqhomed.c +++ b/apps/aqhome-nodes/aqhomed.c @@ -157,3 +157,12 @@ void AqHomed_SetDbFile(AQHOMED *aqh, const char *s) +int AqHomed_GetTimeout(const AQHOMED *aqh) +{ + return aqh?aqh->timeout:0; +} + + + + + diff --git a/apps/aqhome-nodes/aqhomed.h b/apps/aqhome-nodes/aqhomed.h index 0d45834..a56033a 100644 --- a/apps/aqhome-nodes/aqhomed.h +++ b/apps/aqhome-nodes/aqhomed.h @@ -39,6 +39,8 @@ void AqHomed_SetPidFile(AQHOMED *aqh, const char *s); const char *AqHomed_GetDbFile(const AQHOMED *aqh); void AqHomed_SetDbFile(AQHOMED *aqh, const char *s); +int AqHomed_GetTimeout(const AQHOMED *aqh); + #endif diff --git a/apps/aqhome-nodes/aqhomed_p.h b/apps/aqhome-nodes/aqhomed_p.h index 8e7c9d3..574b9fd 100644 --- a/apps/aqhome-nodes/aqhomed_p.h +++ b/apps/aqhome-nodes/aqhomed_p.h @@ -41,6 +41,8 @@ struct AQHOMED { char *logFile; char *pidFile; + int timeout; /* timeout for run e.g. inside valgrind */ + int nodeAddress; }; diff --git a/apps/aqhome-nodes/init.c b/apps/aqhome-nodes/init.c index fa38552..827843b 100644 --- a/apps/aqhome-nodes/init.c +++ b/apps/aqhome-nodes/init.c @@ -101,6 +101,8 @@ int AqHomed_Init(AQHOMED *aqh, int argc, char **argv) } } + aqh->timeout=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 0); + aqh->nodeAddress=GWEN_DB_GetIntValue(dbArgs, "nodeAddress", 0, AQHOMED_DEFAULT_NODEADDR); _setupDb(aqh, dbArgs); diff --git a/apps/aqhome-nodes/main.c b/apps/aqhome-nodes/main.c index 87c1050..74ab103 100644 --- a/apps/aqhome-nodes/main.c +++ b/apps/aqhome-nodes/main.c @@ -44,6 +44,7 @@ * ------------------------------------------------------------------------------------------------ */ +static void _runService(AQHOMED *aqh); #ifdef HAVE_SIGNAL_H static int _setSignalHandlers(void); static int _setupSigAction(struct sigaction *sa, int sig); @@ -108,10 +109,7 @@ int main(int argc, char **argv) return 2; } - while(!stopService) { - DBG_DEBUG(NULL, "Next loop"); - AqHomed_Loop(aqh, 2000); - } + _runService(aqh); AqHomed_Fini(aqh); AqHomed_free(aqh); @@ -124,6 +122,30 @@ int main(int argc, char **argv) +void _runService(AQHOMED *aqh) +{ + time_t timeStart; + int timeout; + + timeout=AqHomed_GetTimeout(aqh); + timeStart=time(NULL); + + while(!stopService) { + AqHomed_Loop(aqh, 2000); + if (timeout) { + time_t now; + + now=time(NULL); + if (timeout && ((int)difftime(now, timeStart))>timeout) { + DBG_INFO(NULL, "Timeout"); + break; + } + } + } /* while */ +} + + + int _setSignalHandlers(void) { #ifdef HAVE_SIGNAL_H diff --git a/apps/aqhome-tool/data/watch.c b/apps/aqhome-tool/data/watch.c index c424b55..27a7284 100644 --- a/apps/aqhome-tool/data/watch.c +++ b/apps/aqhome-tool/data/watch.c @@ -190,10 +190,14 @@ int _doWatch(GWEN_DB_NODE *dbArgs) void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const char *tmpl) { + time_t tStart; + + tStart=time(NULL); + for (;;) { GWEN_MSG *msg; - msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_DATACHANGED, timeoutInSeconds); + msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_DATACHANGED, 2); if (msg) { uint16_t code; @@ -207,6 +211,15 @@ void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const GWEN_Msg_free(msg); } } + if (timeoutInSeconds) { + time_t now; + + now=time(NULL); + if ((int)(difftime(now, tStart))>=timeoutInSeconds) { + DBG_INFO(NULL, "Timeout"); + break; + } + } } /* for */ } diff --git a/apps/aqhome-tool/main.c b/apps/aqhome-tool/main.c index a61edf0..703a29f 100644 --- a/apps/aqhome-tool/main.c +++ b/apps/aqhome-tool/main.c @@ -163,9 +163,15 @@ int main(int argc, char **argv) rv=1; } - GWEN_Fini(); + GWEN_DB_Group_free(dbArgs); + AQH_Fini(); + GWEN_Gui_SetGui(NULL); + GWEN_Gui_free(gui); + + GWEN_Fini(); + return rv; } diff --git a/aqhome/ipc/msg_ipc_tag16.c b/aqhome/ipc/msg_ipc_tag16.c index 6376127..733971d 100644 --- a/aqhome/ipc/msg_ipc_tag16.c +++ b/aqhome/ipc/msg_ipc_tag16.c @@ -64,6 +64,7 @@ void _freeData(void *bp, void *p) xmsg=(AQH_MSG_IPC_TAG16*) p; GWEN_Tag16_List_free(xmsg->tagList); + GWEN_FREE_OBJECT(xmsg); } diff --git a/vg_data.sh b/vg_data.sh new file mode 100755 index 0000000..7882db8 --- /dev/null +++ b/vg_data.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +export AQHOME_LOGLEVEL=info +export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH" + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqf15 --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free --suppressions=../../../../debug/valgrind.supp /usr/local/bin/aqfinance + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqhomed.vg --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free 0-build/apps/aqhomed/aqhomed -l aqhome.log -db aqhome.db -ma 192.168.117.192 -mp 1883 -t 127.0.0.1 -T 300 + +valgrind \ + --tool=memcheck --trace-children=yes -v --log-file=aqhome-data.vg --leak-check=full --show-reachable=yes \ + --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free \ + 0-build/apps/aqhome-data/aqhome-data \ + --datafolder=apps/aqhome-data/test/data \ + -t 127.0.0.1 -P 1899 \ + -p ./aqhome-data.pid \ + -T 90 + diff --git a/vg_nodes.sh b/vg_nodes.sh new file mode 100755 index 0000000..5995a1b --- /dev/null +++ b/vg_nodes.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +export AQHOME_LOGLEVEL=info +export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH" + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqf15 --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free --suppressions=../../../../debug/valgrind.supp /usr/local/bin/aqfinance + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqhomed.vg --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free 0-build/apps/aqhomed/aqhomed -l aqhome.log -db aqhome.db -ma 192.168.117.192 -mp 1883 -t 127.0.0.1 -T 300 + +valgrind \ + --tool=memcheck --trace-children=yes -v --log-file=aqhome-nodes.vg --leak-check=full --show-reachable=yes \ + --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free \ + 0-build/apps/aqhome-nodes/aqhome-nodes -l aqhome-nodes.log -db aqhome-nodes.db -p aqhome-nodes.pid \ + -T 90 + diff --git a/vg_watch.sh b/vg_watch.sh new file mode 100755 index 0000000..6aae424 --- /dev/null +++ b/vg_watch.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +export AQHOME_LOGLEVEL=info +export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH" + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqf15 --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free --suppressions=../../../../debug/valgrind.supp /usr/local/bin/aqfinance + +# valgrind --tool=memcheck --trace-children=yes -v --log-file=aqhomed.vg --leak-check=full --show-reachable=yes --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free 0-build/apps/aqhomed/aqhomed -l aqhome.log -db aqhome.db -ma 192.168.117.192 -mp 1883 -t 127.0.0.1 -T 300 + +#valgrind \ +# --tool=memcheck --trace-children=yes -v --log-file=aqhome-mqttlog.vg --leak-check=full --show-reachable=yes \ +# --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free \ +# 0-build/apps/aqhome-mqttlog/aqhome-mqttlog \ +# -ma 192.168.117.192 -mp 1883 --mqttclientid=AQHOMEMQTTLOGTEST \ +# -W /tmp/aqhome/mqttlog \ +# -i apps/aqhome-mqttlog/mqttlog.conf \ +# -T 30 + + + +valgrind \ + --tool=memcheck --trace-children=yes -v --log-file=aqhome-tool.vg --leak-check=full --show-reachable=yes \ + --track-origins=yes --num-callers=50 --keep-stacktraces=alloc-and-free \ + 0-build/apps/aqhome-tool/aqhome-tool watch \ + -T 300