From 1efe950a88a03794cd6ad429b7a505007bcb4116 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 16 Apr 2020 18:44:00 +0100 Subject: [PATCH] Control/main/winmain/util reorg --- control.cc | 21 +++++++++++++++++++-- control.h | 2 ++ defines.h | 3 --- main.cc | 38 ++------------------------------------ winmain.cc | 43 +++++++------------------------------------ 5 files changed, 30 insertions(+), 77 deletions(-) diff --git a/control.cc b/control.cc index b60cf7c..b19993e 100644 --- a/control.cc +++ b/control.cc @@ -94,6 +94,9 @@ bool Control::init(bool tcrashed) try { + vdr = new VDR(); if (!boxstack) throw 1; + if (!vdr->init()) throw 2; + boxstack = new BoxStack(); if (!boxstack) throw 10; if (!boxstack->init()) throw 20; @@ -104,7 +107,9 @@ bool Control::init(bool tcrashed) } catch (int e) { - if (e == 10) logger->log("Control", Log::EMERG, "BoxStack module failed to create"); + if (e == 1 ) logger->log("Control", Log::EMERG, "VDR module failed to create"); + else if (e == 2 ) logger->log("Control", Log::EMERG, "VDR module failed to initialise"); + else 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"); @@ -121,6 +126,12 @@ bool Control::init(bool tcrashed) FALLTHROUGH case 10: FALLTHROUGH + case 2: + delete vdr; + vdr = NULL; + FALLTHROUGH + case 1: + FALLTHROUGH } return false; @@ -167,6 +178,13 @@ void Control::shutdown() logger->log("Control", Log::NOTICE, "BoxStack module shut down"); } + if (vdr) + { + vdr->shutdown(); + delete vdr; + vdr = NULL; + logger->log("Control", Log::NOTICE, "VDR module shut down"); + } } void Control::stop() @@ -726,7 +744,6 @@ void Control::doJustConnected(VConnect* vconnect) // FIXME make config system - VDR* vdr = VDR::getInstance(); char* config; // See if we're supposed to do network logging diff --git a/control.h b/control.h index 70e4e1c..e5e1942 100644 --- a/control.h +++ b/control.h @@ -26,6 +26,7 @@ #include "defines.h" #include "messagequeue.h" +class VDR; class VConnect; class Message; class InputMan; @@ -69,6 +70,7 @@ class Control : public MessageQueue private: // I own: + VDR* vdr{}; BoxStack* boxstack{}; Sleeptimer* sleeptimer{}; Wol* wol{}; diff --git a/defines.h b/defines.h index d705965..d480344 100644 --- a/defines.h +++ b/defines.h @@ -40,9 +40,6 @@ void MILLISLEEP(ULONG a); long long getTimeMS(); #include -#include -#include -std::string tp2str(const std::chrono::time_point& tp); int getClockRealTime(struct timespec *tp); diff --git a/main.cc b/main.cc index 4a0e42f..c405bbc 100644 --- a/main.cc +++ b/main.cc @@ -29,8 +29,7 @@ #include #include -#include -#include + #ifndef WIN32 #include @@ -46,7 +45,6 @@ #include "log.h" #include "timers.h" -#include "vdr.h" #include "control.h" #include "inputman.h" @@ -82,7 +80,6 @@ Led* led; Osd* osd; Timers* timers; Control* control; -VDR* vdr; Video* video; Audio* audio; @@ -131,7 +128,6 @@ int main(int argc, char** argv) // Init global vars ------------------------------------------------------------------------------------------------ logger = new Log(); timers = new Timers(); - vdr = new VDR(); inputMan = new InputMan(); led = new Led_TYPE(); @@ -149,7 +145,7 @@ int main(int argc, char** argv) // Get logging module started -------------------------------------------------------------------------------------- - if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0)) + if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0)) // NCONFIG x2 { printf("Could not initialise log object. Aborting.\n"); shutdown(1); @@ -297,16 +293,6 @@ int main(int argc, char** argv) shutdown(1); } - success = vdr->init(); - if (success) - { - logger->log("Core", Log::INFO, "VDR module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "VDR module failed to initialise"); - shutdown(1); - } @@ -375,13 +361,6 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "Control module shut down"); } - if (vdr) - { - vdr->shutdown(); - delete vdr; - logger->log("Core", Log::NOTICE, "VDR module shut down"); - } - if (osd) { osd->shutdown(); @@ -504,19 +483,6 @@ int max(int a, int b) else return b; } -std::string tp2str(const std::chrono::time_point& tp) -{ - auto tms = std::chrono::time_point_cast(tp); - std::chrono::milliseconds e = tms.time_since_epoch(); - long long c = e.count(); - time_t tt = c / 1000; - int ttm = c % 1000; - auto stm = std::localtime(&tt); - std::stringstream ss; - ss << std::put_time(stm, "%T") << "." << std::setfill('0') << std::setw(3) << ttm; - return ss.str(); -} - const std::string& getCommandLineServer() { return argvServer; diff --git a/winmain.cc b/winmain.cc index a755c4a..1c91010 100644 --- a/winmain.cc +++ b/winmain.cc @@ -38,7 +38,6 @@ #include "timers.h" #include "videowin.h" #include "audiowin.h" -#include "vdr.h" #include "windowsosd.h" #ifdef WINDOWS_LEGACY #include "osdwinpixel.h" @@ -60,10 +59,9 @@ Led* led; Osd* osd; Timers* timers; Control* control; -VDR* vdr; Video* video; Audio* audio; -std::string commandLineServer; +std::string commandLineServer; // NCONFIG bool wnd_fullscreen=false; bool wnd_topmost=false; @@ -159,7 +157,6 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd led = new LedWin(); timers = new Timers(); osd = new Osd_TYPE(); - vdr = new VDR(); video = new VideoWin(); audio = new AudioWin(); control = new Control(); @@ -257,8 +254,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "OSD module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } video->setDefaultAspect(); @@ -271,21 +268,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Audio module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; - } - - success = vdr->init(); - if (success) - { - logger->log("Core", Log::INFO, "VDR module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "VDR module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } success = control->init(); @@ -297,8 +281,8 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd { logger->log("Core", Log::EMERG, "Control module failed to initialise"); shutdown(1); - WSACleanup(); - return 0; + WSACleanup(); + return 0; } // Other init ------------------------------------------------------------------------------------------------------ @@ -886,19 +870,6 @@ ULLONG ntohll(ULLONG a) return htonll(a); } -std::string tp2str(const std::chrono::time_point& tp) -{ - auto tms = std::chrono::time_point_cast(tp); - std::chrono::milliseconds e = tms.time_since_epoch(); - long long c = e.count(); - time_t tt = c / 1000; - int ttm = c % 1000; - auto stm = std::localtime(&tt); - std::stringstream ss; - ss << std::put_time(stm, "%T") << "." << std::setfill('0') << std::setw(3) << ttm; - return ss.str(); -} - const std::string& getCommandLineServer() { return commandLineServer; -- 2.39.2