]> git.vomp.tv Git - vompclient.git/commitdiff
Control/main/winmain reorg
authorChris Tallon <chris@vomp.tv>
Thu, 16 Apr 2020 17:16:12 +0000 (18:16 +0100)
committerChris Tallon <chris@vomp.tv>
Thu, 16 Apr 2020 17:16:12 +0000 (18:16 +0100)
control.cc
control.h
main.cc
winmain.cc

index f0ba3175be3b614075f80c8c446bce3536fca207..b60cf7cb58fb4ccb8834081eb41260ceae4b0022 100644 (file)
@@ -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()
index c424a8c611becf8e2cac8a445286d0aa5afce81b..70e4e1c077e02117c80de04263f62cce8cce9916 100644 (file)
--- 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 a333c46949dfb4aee70f7dafabdeb8aece1e780a..4a0e42ffd2a4a7226f30a8a1ac15bc94d7086f50 100644 (file)
--- 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);
index dd5587ff0eb5add34562b337caa824561110a27b..a755c4a12968ccf50f191af0439a085b8e8d9539 100644 (file)
@@ -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);
 }
 
 // -------------------------------------------------------------------------------------------------------------------