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

index b60cf7cb58fb4ccb8834081eb41260ceae4b0022..b19993e2bdfb94f9aa7d61db7d6ff1f2dd0b1c34 100644 (file)
@@ -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
index 70e4e1c077e02117c80de04263f62cce8cce9916..e5e1942612e5e164b41b1275bac6f670b9dc3057 100644 (file)
--- 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{};
index d705965dae5155b7f01f0d1b1e09e58caf9a5eaf..d48034430e7d916904a32820bf495b437a803294 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -40,9 +40,6 @@ void MILLISLEEP(ULONG a);
 long long getTimeMS();
 
 #include <string>
-#include <chrono>
-#include <iomanip>
-std::string tp2str(const std::chrono::time_point<std::chrono::system_clock>& tp);
 
 
 int getClockRealTime(struct timespec *tp);
diff --git a/main.cc b/main.cc
index 4a0e42ffd2a4a7226f30a8a1ac15bc94d7086f50..c405bbcd51d19512a851c446ae5142fb04754c0f 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -29,8 +29,7 @@
 
 #include <thread>
 #include <string>
-#include <chrono>
-#include <iomanip>
+
 
 #ifndef WIN32
   #include <unistd.h>
@@ -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<std::chrono::system_clock>& tp)
-{
-  auto tms = std::chrono::time_point_cast<std::chrono::milliseconds>(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;
index a755c4a12968ccf50f191af0439a085b8e8d9539..1c910101d5a57c3c7c23d39b1ff3de5107c40494 100644 (file)
@@ -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<std::chrono::system_clock>& tp)
-{
-  auto tms = std::chrono::time_point_cast<std::chrono::milliseconds>(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;