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

index e4802a4253f0e55195ce1090ff49d15f5fe1dc6c..f0ba3175be3b614075f80c8c446bce3536fca207 100644 (file)
 
 // FIXME rename to Control and move stuff from main to here
 
+#ifndef WIN32
+#include <unistd.h> // for reboot
+#include <linux/reboot.h>
+#include <sys/reboot.h>
+#endif
 
-#include "control.h"
+#include <time.h>
 
 #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;
index 6ed82bea2fa281e8c9b634943f8e5f46c485a529..c424a8c611becf8e2cac8a445286d0aa5afce81b 100644 (file)
--- a/control.h
+++ b/control.h
 #ifndef COMMAND_H
 #define COMMAND_H
 
-#ifndef WIN32
-#include <unistd.h> // for reboot
-#include <linux/reboot.h>
-#include <sys/reboot.h>
-#endif
-
-#include <time.h>
-#ifndef WIN32
-#include <pthread.h>   // why?
-#endif
-
 #include <string>
 #include <vector>
 
@@ -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 34531007f1361de779f06ca2c946f497aeaf1cee..a333c46949dfb4aee70f7dafabdeb8aece1e780a 100644 (file)
--- a/main.cc
+++ b/main.cc
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
+// 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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");
index 726eb25a88313beabb5b00a6dec39fa4d4d766c7..dd5587ff0eb5add34562b337caa824561110a27b 100644 (file)
@@ -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();