From a53f6eb1f374d4c6d14fe8b55e5cdfa975de2102 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 16 Apr 2020 17:43:04 +0100 Subject: [PATCH] Start main / winmain / control reorganisation --- control.cc | 43 ++++++++++++++++++++++++++++++++++++++++--- control.h | 17 +++++------------ main.cc | 34 ++++++++++++---------------------- winmain.cc | 26 ++------------------------ 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/control.cc b/control.cc index e4802a4..f0ba317 100644 --- a/control.cc +++ b/control.cc @@ -19,8 +19,13 @@ // FIXME rename to Control and move stuff from main to here +#ifndef WIN32 +#include // for reboot +#include +#include +#endif -#include "control.h" +#include #ifdef WIN32 #include "inputwin.h" @@ -55,6 +60,7 @@ #include "wjpeg.h" #include "osdvector.h" +#include "control.h" Control* Control::instance = NULL; @@ -81,8 +87,30 @@ int Control::init(bool tcrashed) initted = true; crashed = tcrashed; + + SkinFactory::InitSkin(0); + + logger = Log::getInstance(); - boxstack = BoxStack::getInstance(); + + + bool success; + boxstack = new BoxStack(); + + success = boxstack->init(); + if (success) + { + logger->log("Core", Log::INFO, "BoxStack module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "BoxStack module failed to initialise"); + shutdown(); + } + + + + inputMan = InputMan::getInstance(); if (!logger || !boxstack || !inputMan) @@ -91,13 +119,22 @@ int Control::init(bool tcrashed) return 0; } - SkinFactory::InitSkin(0); + + return 1; } int Control::shutdown() { + if (boxstack) + { + boxstack->shutdown(); + delete boxstack; + boxstack = NULL; + logger->log("Core", Log::NOTICE, "BoxStack module shut down"); + } + if (!initted) return 0; initted = false; return 1; diff --git a/control.h b/control.h index 6ed82be..c424a8c 100644 --- a/control.h +++ b/control.h @@ -20,17 +20,6 @@ #ifndef COMMAND_H #define COMMAND_H -#ifndef WIN32 -#include // for reboot -#include -#include -#endif - -#include -#ifndef WIN32 -#include // why? -#endif - #include #include @@ -77,6 +66,11 @@ class Control : public MessageQueue ASLPrefList &getASLList() { return langcodes; }; private: + // I own: + BoxStack* boxstack{}; + + + void handleCommand(int); void doStandby(); void doPowerOn(); @@ -91,7 +85,6 @@ class Control : public MessageQueue static Control* instance; Log* logger; - BoxStack* boxstack; InputMan* inputMan; bool initted{}; diff --git a/main.cc b/main.cc index 3453100..a333c46 100644 --- a/main.cc +++ b/main.cc @@ -17,6 +17,11 @@ along with VOMP. If not, see . */ +// FIXME +// Work towards main and winmain only containing what they need for their own platforms +// Move anything common to utils or control. Move any module startup / shutdown that can +// be done in control to there. + #include #include #include @@ -42,7 +47,6 @@ #include "log.h" #include "timers.h" #include "vdr.h" -#include "boxstack.h" #include "control.h" #include "inputman.h" #include "wol.h" @@ -79,7 +83,6 @@ InputMan* inputMan; Led* led; Osd* osd; Timers* timers; -BoxStack* boxstack; Control* control; VDR* vdr; Video* video; @@ -140,12 +143,11 @@ int main(int argc, char** argv) audio = new Audio_TYPE(); video = new Video_TYPE(); - boxstack = new BoxStack(); control = new Control(); wol = new Wol(); sleeptimer = new Sleeptimer(); - if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !boxstack || !control || !wol || !sleeptimer) + if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !control || !wol || !sleeptimer) { printf("Could not create objects. Memory problems?\n"); shutdown(1); @@ -312,16 +314,9 @@ int main(int argc, char** argv) shutdown(1); } - success = boxstack->init(); - if (success) - { - logger->log("Core", Log::INFO, "BoxStack module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "BoxStack module failed to initialise"); - shutdown(1); - } + + + success = control->init(crashed); if (success) @@ -344,6 +339,9 @@ int main(int argc, char** argv) control->run(); // When that returns quit ------------------------------------------------------------------------------------------ + + control->shutdown(); + shutdown(0); return 0; } @@ -375,17 +373,9 @@ void threadSignalReceiverFunction() void shutdown(int code) { - if (boxstack) - { - boxstack->shutdown(); - delete boxstack; - logger->log("Core", Log::NOTICE, "BoxStack module shut down"); - } - // FIXME, send a del all to boxstack first, then get rid of it after control? if (control) // shut down control here in case views have posted messages { - control->shutdown(); delete control; control = NULL; logger->log("Core", Log::NOTICE, "Control module shut down"); diff --git a/winmain.cc b/winmain.cc index 726eb25..dd5587f 100644 --- a/winmain.cc +++ b/winmain.cc @@ -45,7 +45,6 @@ #else #include "osdwinvector.h" #endif -#include "boxstack.h" #include "control.h" #include "wol.h" #include "vsleeptimer.h" @@ -62,7 +61,6 @@ InputWin* inputWin; Led* led; Osd* osd; Timers* timers; -BoxStack* boxstack; Control* control; VDR* vdr; Video* video; @@ -113,6 +111,7 @@ int getClockRealTime(struct timespec *tp){ DWORD WINAPI controlthreadStart(void *arg) { control->run(); + control->shutdown(); return 0; } @@ -169,12 +168,11 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd vdr = new VDR(); video = new VideoWin(); audio = new AudioWin(); - boxstack = new BoxStack(); control = new Control(); wol = new Wol(); sleeptimer = new Sleeptimer(); - if (!logger || !remote || !led || !osd || !video || !audio || !boxstack || !control || !sleeptimer) + if (!logger || !remote || !led || !osd || !video || !audio || !control || !sleeptimer) { ERROR_MSG("Could not create objects. Memory problems?\n"); shutdown(1); @@ -298,19 +296,6 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd return 0; } - success = boxstack->init(); - if (success) - { - logger->log("Core", Log::INFO, "BoxStack module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "BoxStack module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - success = control->init(); if (success) { @@ -830,13 +815,6 @@ bool InitApp(HINSTANCE hinst,int cmdshow) { void shutdown(int code) { - if (boxstack) - { - boxstack->shutdown(); - delete boxstack; - logger->log("Core", Log::NOTICE, "BoxStack module shut down"); - } - if (control) // shut down control here in case views have posted messages { control->shutdown(); -- 2.39.2