From ca8e5ee01d3c2ad7f303cdae53c21e1d3980d9ee Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 16 Apr 2020 18:16:12 +0100 Subject: [PATCH] Control/main/winmain reorg --- control.cc | 73 ++++++++++++++++++++++++++++++++++++++---------------- control.h | 8 ++++-- main.cc | 22 +++------------- winmain.cc | 22 ++-------------- 4 files changed, 62 insertions(+), 63 deletions(-) diff --git a/control.cc b/control.cc index f0ba317..b60cf7c 100644 --- a/control.cc +++ b/control.cc @@ -81,39 +81,55 @@ Control* Control::getInstance() return instance; } -int Control::init(bool tcrashed) +bool Control::init(bool tcrashed) { - if (initted) return 0; - initted = true; + if (initted) return false; crashed = tcrashed; SkinFactory::InitSkin(0); - logger = Log::getInstance(); - bool success; - boxstack = new BoxStack(); - - success = boxstack->init(); - if (success) + try { - logger->log("Core", Log::INFO, "BoxStack module initialised"); + boxstack = new BoxStack(); if (!boxstack) throw 10; + if (!boxstack->init()) throw 20; + + sleeptimer = new Sleeptimer(); if (!sleeptimer) throw 30; + + wol = new Wol(); if (!wol) throw 40; + } - else + catch (int e) { - logger->log("Core", Log::EMERG, "BoxStack module failed to initialise"); - shutdown(); - } + if (e == 10) logger->log("Control", Log::EMERG, "BoxStack module failed to create"); + else if (e == 20) logger->log("Control", Log::EMERG, "BoxStack module failed to initialise"); + else if (e == 30) logger->log("Control", Log::EMERG, "SleepTimer module failed to create"); + else if (e == 40) logger->log("Control", Log::EMERG, "WOL module failed to create"); + switch(e) + { + case 40: + FALLTHROUGH + case 30: + FALLTHROUGH + case 20: + delete boxstack; + boxstack = NULL; + FALLTHROUGH + case 10: + FALLTHROUGH + } + return false; + } inputMan = InputMan::getInstance(); - if (!logger || !boxstack || !inputMan) + if (!inputMan) { initted = false; return 0; @@ -121,23 +137,36 @@ int Control::init(bool tcrashed) - - return 1; + initted = true; + return true; } -int Control::shutdown() +void Control::shutdown() { + if (!initted) return; + initted = false; + + if (wol) + { + delete wol; + logger->log("Control", Log::NOTICE, "WOL module shut down"); + } + + if (sleeptimer) + { + delete sleeptimer; + sleeptimer = NULL; + logger->log("Control", Log::NOTICE, "Sleeptimer module shut down"); + } + if (boxstack) { boxstack->shutdown(); delete boxstack; boxstack = NULL; - logger->log("Core", Log::NOTICE, "BoxStack module shut down"); + logger->log("Control", Log::NOTICE, "BoxStack module shut down"); } - if (!initted) return 0; - initted = false; - return 1; } void Control::stop() diff --git a/control.h b/control.h index c424a8c..70e4e1c 100644 --- a/control.h +++ b/control.h @@ -34,6 +34,8 @@ class BoxStack; class Log; class VInfo; class WJpeg; +class Sleeptimer; +class Wol; struct ASLPref { @@ -51,8 +53,8 @@ class Control : public MessageQueue ~Control(); static Control* getInstance(); - int init(bool crashed = false); - int shutdown(); + bool init(bool crashed = false); + void shutdown(); void run(); void stop(); void doReboot(); @@ -68,6 +70,8 @@ class Control : public MessageQueue private: // I own: BoxStack* boxstack{}; + Sleeptimer* sleeptimer{}; + Wol* wol{}; diff --git a/main.cc b/main.cc index a333c46..4a0e42f 100644 --- a/main.cc +++ b/main.cc @@ -49,8 +49,6 @@ #include "vdr.h" #include "control.h" #include "inputman.h" -#include "wol.h" -#include "vsleeptimer.h" #ifdef VOMP_PLATTFORM_NMT #include "lednmt.h" @@ -87,8 +85,6 @@ Control* control; VDR* vdr; Video* video; Audio* audio; -Wol* wol; -Sleeptimer* sleeptimer; // Temporary, will move to Config system std::string argvServer; @@ -144,10 +140,8 @@ int main(int argc, char** argv) video = new Video_TYPE(); control = new Control(); - wol = new Wol(); - sleeptimer = new Sleeptimer(); - if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !control || !wol || !sleeptimer) + if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !control) { printf("Could not create objects. Memory problems?\n"); shutdown(1); @@ -318,8 +312,8 @@ int main(int argc, char** argv) - success = control->init(crashed); - if (success) + bool bsuccess = control->init(crashed); + if (bsuccess) { logger->log("Core", Log::INFO, "Control module initialised"); } @@ -430,17 +424,7 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "InputMan module shut down"); } - if (wol) - { - delete wol; - logger->log("Core", Log::NOTICE, "WOL module shut down"); - } - if (sleeptimer) - { - delete sleeptimer; - logger->log("Core", Log::NOTICE, "Sleeptimer module shut down"); - } #ifdef HANDLE_VT_SWITCHING ioctl(fdtty, VT_UNLOCKSWITCH, 1); diff --git a/winmain.cc b/winmain.cc index dd5587f..a755c4a 100644 --- a/winmain.cc +++ b/winmain.cc @@ -46,8 +46,6 @@ #include "osdwinvector.h" #endif #include "control.h" -#include "wol.h" -#include "vsleeptimer.h" #include "messagequeue.h" void sighandler(int signalReceived); @@ -65,8 +63,6 @@ Control* control; VDR* vdr; Video* video; Audio* audio; -Wol* wol; -Sleeptimer* sleeptimer; std::string commandLineServer; bool wnd_fullscreen=false; @@ -92,9 +88,7 @@ MessageQueue* messageQueue; void MILLISLEEP(ULONG a) { - Sleep(a); - } int getClockRealTime(struct timespec *tp){ @@ -169,10 +163,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd video = new VideoWin(); audio = new AudioWin(); control = new Control(); - wol = new Wol(); - sleeptimer = new Sleeptimer(); - if (!logger || !remote || !led || !osd || !video || !audio || !control || !sleeptimer) + if (!logger || !remote || !led || !osd || !video || !audio || !control) { ERROR_MSG("Could not create objects. Memory problems?\n"); shutdown(1); @@ -870,11 +862,6 @@ void shutdown(int code) delete remote; logger->log("Core", Log::NOTICE, "Remote module shut down"); } - if (wol) - { - delete wol; - logger->log("Core", Log::NOTICE, "WOL module shut down"); - } if (logger) { @@ -882,13 +869,8 @@ void shutdown(int code) logger->shutdown(); delete logger; } - if (sleeptimer) - { - delete sleeptimer; - logger->log("Core", Log::NOTICE, "Sleeptimer module shut down"); - } - ExitProcess(0); + ExitProcess(0); } // ------------------------------------------------------------------------------------------------------------------- -- 2.39.2