From fcfaebf4db5945a6200ba39aab8737335c5d7d10 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 20 Apr 2020 17:41:46 +0100 Subject: [PATCH] Control/main/winmain/util reorganisation Move all common module startup/shutdown code from main/winmain to control Move common global functions from main/winmain to util --- afeed.cc | 1 + audioomx.cc | 8 +- control.cc | 205 +++++++++++++++++++++++++++++-------- control.h | 12 ++- defines.h | 5 +- imageomx.cc | 7 +- main.cc | 250 ++++++---------------------------------------- objects.mk | 2 +- playervideorec.cc | 1 + tfeed.cc | 1 + threadp.cc | 2 + vconnect.cc | 1 + vfeed.cc | 1 + videoomx.cc | 1 + vscreensaver.cc | 1 + vsleeptimer.cc | 4 +- winmain.cc | 176 ++------------------------------ 17 files changed, 241 insertions(+), 437 deletions(-) diff --git a/afeed.cc b/afeed.cc index 2541718..546df45 100644 --- a/afeed.cc +++ b/afeed.cc @@ -20,6 +20,7 @@ #include "log.h" #include "demuxer.h" #include "callback.h" +#include "util.h" #include "afeed.h" diff --git a/audioomx.cc b/audioomx.cc index e522d2d..22ade65 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -17,20 +17,22 @@ along with VOMP. If not, see . */ -#include "audioomx.h" +#include + #include "videoomx.h" #include "log.h" #include "vdr.h" #include "woptionpane.h" - #include "osdopenvg.h" -#include +#include "util.h" extern "C" { #include "libavutil/channel_layout.h" #include "libavutil/opt.h" } +#include "audioomx.h" + AudioOMX::AudioOMX() { initted = 0; diff --git a/control.cc b/control.cc index 76fc49f..998a426 100644 --- a/control.cc +++ b/control.cc @@ -60,6 +60,27 @@ #include "wjpeg.h" #include "osdvector.h" + +#ifdef VOMP_PLATFORM_RASPBERRY + #include "ledraspberry.h" + #include "osdopenvg.h" + #include "videoomx.h" + #include "audioomx.h" +#endif + +#ifdef WIN32 + #include "windowsosd.h" + #ifdef WINDOWS_LEGACY + #include "osdwinpixel.h" + #else + #include "osdwinvector.h" + #endif + + #include "ledwin.h" + #include "videowin.h" + #include "audiowin.h" +#endif + #include "control.h" Control* Control::instance = NULL; @@ -85,70 +106,133 @@ bool Control::init(bool tcrashed) { if (initted) return false; crashed = tcrashed; - - - SkinFactory::InitSkin(0); - logger = Log::getInstance(); + SkinFactory::InitSkin(0); try { - vdr = new VDR(); if (!boxstack) throw 1; - if (!vdr->init()) throw 2; + led = new Led_TYPE(); if (!led) throw 10; + if (!led->init(-1)) throw 11; // FIXME init(0) on Win32 + + timers = new Timers(); if (!timers) throw 20; + if (!timers->init()) throw 21; + + video = new Video_TYPE(); if (!video) throw 30; + if (!video->init(Video::PAL)) throw 31; + + audio = new Audio_TYPE(); if (!audio) throw 40; + if (!audio->init(Audio::MPEG2_PES)) throw 41; + + osd = new Osd_TYPE(); if (!osd) throw 50; + if (!osd->init()) throw 51; + + vdr = new VDR(); if (!vdr) throw 60; + if (!vdr->init()) throw 61; - boxstack = new BoxStack(); if (!boxstack) throw 10; - if (!boxstack->init()) throw 20; + boxstack = new BoxStack(); if (!boxstack) throw 70; + if (!boxstack->init()) throw 71; - sleeptimer = new Sleeptimer(); if (!sleeptimer) throw 30; + sleeptimer = new Sleeptimer(); if (!sleeptimer) throw 80; - wol = new Wol(); if (!wol) throw 40; + wol = new Wol(); if (!wol) throw 90; + + inputMan = new InputMan(); if (!inputMan) throw 100; + if (!inputMan->init()) throw 101; } catch (int e) { - 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"); + if (e == 10) logger->log("Control", Log::EMERG, "LED module failed to create"); + else if (e == 11) logger->log("Control", Log::EMERG, "LED module failed to initialise"); + else if (e == 20) logger->log("Control", Log::EMERG, "Timers module failed to create"); + else if (e == 21) logger->log("Control", Log::EMERG, "Timers module failed to initialise"); + else if (e == 30) logger->log("Control", Log::EMERG, "Video module failed to create"); + else if (e == 31) logger->log("Control", Log::EMERG, "Video module failed to initialise"); + else if (e == 40) logger->log("Control", Log::EMERG, "Audio module failed to create"); + else if (e == 41) logger->log("Control", Log::EMERG, "Audio module failed to initialise"); + else if (e == 50) logger->log("Control", Log::EMERG, "OSD module failed to create"); + else if (e == 51) logger->log("Control", Log::EMERG, "OSD module failed to initialise"); + else if (e == 60) logger->log("Control", Log::EMERG, "VDR module failed to create"); + else if (e == 61) logger->log("Control", Log::EMERG, "VDR module failed to initialise"); + else if (e == 70) logger->log("Control", Log::EMERG, "BoxStack module failed to create"); + else if (e == 71) logger->log("Control", Log::EMERG, "BoxStack module failed to initialise"); + else if (e == 80) logger->log("Control", Log::EMERG, "SleepTimer module failed to create"); + else if (e == 90) logger->log("Control", Log::EMERG, "WOL module failed to create"); + else if (e == 100) logger->log("Control", Log::EMERG, "InputMan module failed to create"); + else if (e == 101) logger->log("Control", Log::EMERG, "InputMan module failed to initialise"); switch(e) { - case 40: + case 101: + delete inputMan; + inputMan = NULL; FALLTHROUGH - case 30: + case 100: + delete wol; + wol = NULL; FALLTHROUGH - case 20: + case 90: + delete sleeptimer; + sleeptimer = NULL; + FALLTHROUGH + case 80: + boxstack->shutdown(); + FALLTHROUGH + case 71: delete boxstack; boxstack = NULL; FALLTHROUGH - case 10: + case 70: + vdr->shutdown(); FALLTHROUGH - case 2: + case 61: delete vdr; vdr = NULL; FALLTHROUGH - case 1: + case 60: + osd->shutdown(); + FALLTHROUGH + case 51: + delete osd; + osd = NULL; + FALLTHROUGH + case 50: + audio->shutdown(); + FALLTHROUGH + case 41: + delete audio; + audio = NULL; + FALLTHROUGH + case 40: + video->shutdown(); + FALLTHROUGH + case 31: + delete video; + video = NULL; + FALLTHROUGH + case 30: + timers->shutdown(); + FALLTHROUGH + case 21: + delete timers; + timers = NULL; FALLTHROUGH - ; + case 20: + led->shutdown(); + FALLTHROUGH + case 11: + delete led; + led = NULL; + FALLTHROUGH + case 10: + FALLTHROUGH + ; } return false; } - - inputMan = InputMan::getInstance(); - - if (!inputMan) - { - initted = false; - return 0; - } - - - initted = true; return true; } @@ -158,6 +242,14 @@ void Control::shutdown() if (!initted) return; initted = false; + if (inputMan) + { + inputMan->shutdown(); + delete inputMan; + inputMan = NULL; + logger->log("Control", Log::NOTICE, "InputMan module shut down"); + } + if (wol) { delete wol; @@ -186,6 +278,46 @@ void Control::shutdown() vdr = NULL; logger->log("Control", Log::NOTICE, "VDR module shut down"); } + + if (osd) + { + osd->shutdown(); + delete osd; + osd = NULL; + logger->log("Control", Log::NOTICE, "OSD module shut down"); + } + + if (audio) + { + audio->shutdown(); + delete audio; + audio = NULL; + logger->log("Control", Log::NOTICE, "Audio module shut down"); + } + + if (video) + { + video->shutdown(); + delete video; + video = NULL; + logger->log("Control", Log::NOTICE, "Video module shut down"); + } + + if (timers) + { + timers->shutdown(); + delete timers; + timers = NULL; + logger->log("Control", Log::NOTICE, "Timers module shut down"); + } + + if (led) + { + led->shutdown(); + delete led; + led = NULL; + logger->log("Control", Log::NOTICE, "LED module shut down"); + } } void Control::stop() @@ -200,8 +332,6 @@ void Control::stop() void Control::doWallpaper() { - Video* video = Video::getInstance(); - // Blue background Boxx* bbg = new Boxx(); bbg->setSize(video->getScreenWidth(), video->getScreenHeight()); @@ -727,8 +857,6 @@ void Control::doJustConnected(VConnect* vconnect) if (!VDR::getInstance()->isConnected()) { connectionLost(); return; } logger->log("Control", Log::INFO, "Entering doJustConnected"); - Video* video = Video::getInstance(); - Audio* audio = Audio::getInstance(); boxstack->remove(vconnect); VInfo* vi = new VInfo(); @@ -810,7 +938,6 @@ void Control::doJustConnected(VConnect* vconnect) boxstack->remove(wallpaper); delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; - Osd* osd = Osd::getInstance(); #ifndef __ANDROID__ osd->shutdown(); #endif diff --git a/control.h b/control.h index e5e1942..0271d0f 100644 --- a/control.h +++ b/control.h @@ -37,6 +37,11 @@ class VInfo; class WJpeg; class Sleeptimer; class Wol; +class Audio; +class Video; +class Osd; +class Timers; +class Led; struct ASLPref { @@ -70,10 +75,16 @@ class Control : public MessageQueue private: // I own: + Led* led{}; + Timers* timers{}; + Osd* osd{}; + Video* video{}; + Audio* audio{}; VDR* vdr{}; BoxStack* boxstack{}; Sleeptimer* sleeptimer{}; Wol* wol{}; + InputMan* inputMan{}; @@ -91,7 +102,6 @@ class Control : public MessageQueue static Control* instance; Log* logger; - InputMan* inputMan; bool initted{}; bool irun{}; diff --git a/defines.h b/defines.h index d480344..eca1dac 100644 --- a/defines.h +++ b/defines.h @@ -34,9 +34,6 @@ typedef unsigned long long ULLONG; // Global useful functions -//ULLONG htonll(ULLONG a); -//ULLONG ntohll(ULLONG a); -void MILLISLEEP(ULONG a); long long getTimeMS(); #include @@ -50,6 +47,8 @@ const std::string& getCommandLineServer(); #ifdef WIN32 + #define Led_TYPE LedWin + #define Video_TYPE VideoWin #define Thread_TYPE ThreadWin #define ThreadID_TYPE unsigned int diff --git a/imageomx.cc b/imageomx.cc index f3a25e2..be7d954 100644 --- a/imageomx.cc +++ b/imageomx.cc @@ -17,14 +17,15 @@ along with VOMP. If not, see . */ -#include "imageomx.h" +#include #include "videoomx.h" #include "log.h" #include "vdr.h" #include "woptionpane.h" - +#include "util.h" #include "osdopenvg.h" -#include + +#include "imageomx.h" ImageOMX::ImageOMX(OsdVector::PictureReader * treader):OsdVector::PictureDecoder(treader) { diff --git a/main.cc b/main.cc index c405bbc..de56e17 100644 --- a/main.cc +++ b/main.cc @@ -17,16 +17,16 @@ along with VOMP. If not, see . */ -// 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 #include #include #include +// For open +#include +#include +#include + #include #include @@ -44,9 +44,8 @@ #endif #include "log.h" -#include "timers.h" +#include "util.h" #include "control.h" -#include "inputman.h" #ifdef VOMP_PLATTFORM_NMT #include "lednmt.h" @@ -55,35 +54,18 @@ #include "videonmt.h" #endif -#ifdef VOMP_PLATFORM_RASPBERRY - #include "ledraspberry.h" - #include "osdopenvg.h" - #include "audioomx.h" - #include "videoomx.h" -#endif - - #ifndef WIN32 // FIXME do we need any if WIN32 stuff in here? windows has own winmain file void threadSignalReceiverFunction(); #endif -ULLONG htonll(ULLONG); -ULLONG ntohll(ULLONG); void shutdown(int code); const std::string& getCommandLineServer(); -// Global variables -------------------------------------------------------------------------------------------------- Log* logger; -InputMan* inputMan; -Led* led; -Osd* osd; -Timers* timers; Control* control; -Video* video; -Audio* audio; -// Temporary, will move to Config system +// Temporary, will move to Config system NCONFIG std::string argvServer; #ifdef HANDLE_VT_SWITCHING @@ -125,35 +107,23 @@ int main(int argc, char** argv) } } - // Init global vars ------------------------------------------------------------------------------------------------ - logger = new Log(); - timers = new Timers(); - inputMan = new InputMan(); - - led = new Led_TYPE(); - osd = new Osd_TYPE(); - audio = new Audio_TYPE(); - video = new Video_TYPE(); - - control = new Control(); - - if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !control) + // Start Log -------------------------------------------------------------------------------------------------- + logger = new Log(); + if (!logger) { - printf("Could not create objects. Memory problems?\n"); + printf("Failed to create Log object\n"); shutdown(1); } - // Get logging module started -------------------------------------------------------------------------------------- - if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0)) // NCONFIG x2 { printf("Could not initialise log object. Aborting.\n"); shutdown(1); } - logger->log("Core", Log::INFO, "Starting up..."); + logger->log("Main", Log::INFO, "Starting up..."); - // Daemonize if not -d + // Daemonize -------------------------------------------------------------------------------------------------- if (daemonize) { @@ -182,7 +152,7 @@ int main(int argc, char** argv) int sigBlockResult = pthread_sigmask(SIG_SETMASK, &set, NULL); if (sigBlockResult) { - logger->log("Core", Log::EMERG, "Could not block signals: %i", sigBlockResult); + logger->log("Main", Log::EMERG, "Could not block signals: %i", sigBlockResult); shutdown(1); } @@ -190,7 +160,7 @@ int main(int argc, char** argv) std::thread threadSignalReceiver(threadSignalReceiverFunction); threadSignalReceiver.detach(); - logger->log("Core", Log::INFO, "Signal handlers set up successfully"); + logger->log("Main", Log::INFO, "Signal handlers set up successfully"); // VT Switching ----------------------------------------------------------------------------------------------- @@ -203,14 +173,14 @@ int main(int argc, char** argv) ) { - logger->log("Core", Log::EMERG, "Could not open /dev/tty. Please change permissions"); + logger->log("Main", Log::EMERG, "Could not open /dev/tty. Please change permissions"); } else { int free_vt; if (ioctl(fdtty, VT_OPENQRY, &free_vt) == -1 || free_vt == -1) { - logger->log("Core", Log::EMERG, "Could not retrieve free virtual console, please change permissions"); + logger->log("Main", Log::EMERG, "Could not retrieve free virtual console, please change permissions"); } else { @@ -221,105 +191,24 @@ int main(int argc, char** argv) } #endif - // Init modules ---------------------------------------------------------------------------------------------------- - int success; - - success = inputMan->init(); - - if (success) - { - logger->log("Core", Log::INFO, "InputMan module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "InputMan module failed to initialise"); - shutdown(1); - } - - success = led->init(-1); - if (success) - { - logger->log("Core", Log::INFO, "LED module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "LED module failed to initialise"); - shutdown(1); - } - - success = timers->init(); - if (success) - { - logger->log("Core", Log::INFO, "Timers module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Timers module failed to initialise"); - shutdown(1); - } - - UCHAR videoFormat = Video::PAL; // PALNTSC FIXME - - success = video->init(videoFormat); - if (success) - { - logger->log("Core", Log::INFO, "Video module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Video module failed to initialise"); - shutdown(1); - } + // Run control ---------------------------------------------------------------------------------------------------- - success = osd->init(); - if (success) - { - logger->log("Core", Log::INFO, "OSD module initialised"); - } - else + control = new Control(); + if (!control) { - logger->log("Core", Log::EMERG, "OSD module failed to initialise"); + logger->log("Main", Log::EMERG, "Control module failed to create"); shutdown(1); } - success = audio->init(Audio::MPEG2_PES); - if (success) + if (!control->init(crashed)) { - logger->log("Core", Log::INFO, "Audio module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Audio module failed to initialise"); - shutdown(1); - } - - - - - - - bool bsuccess = control->init(crashed); - if (bsuccess) - { - logger->log("Core", Log::INFO, "Control module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Control module failed to initialise"); + logger->log("Main", Log::EMERG, "Control module failed to initialise"); + delete control; + control = NULL; shutdown(1); } - // Other init ------------------------------------------------------------------------------------------------------ - - logger->log("Core", Log::NOTICE, "Startup successful"); - - // Run main loop --------------------------------------------------------------------------------------------------- - - // Ok, all major device components and other bits are loaded and ready control->run(); - - // When that returns quit ------------------------------------------------------------------------------------------ - control->shutdown(); shutdown(0); @@ -337,11 +226,11 @@ void threadSignalReceiverFunction() { if(sigwait(&set, &sig)) { - logger->log("Core", Log::CRIT, "Sigwait returned fail - signal handler exiting"); + logger->log("Main", Log::CRIT, "Sigwait returned fail - signal handler exiting"); return; } - logger->log("Core", Log::NOTICE, "Signal received: %i", sig); + logger->log("Main", Log::NOTICE, "Signal received: %i", sig); if ((sig == SIGINT) || (sig == SIGTERM)) control->stop(); } @@ -358,53 +247,9 @@ void shutdown(int code) { delete control; control = NULL; - logger->log("Core", Log::NOTICE, "Control module shut down"); - } - - if (osd) - { - osd->shutdown(); - delete osd; - logger->log("Core", Log::NOTICE, "OSD module shut down"); - } - - if (audio) - { - audio->shutdown(); - delete audio; - logger->log("Core", Log::NOTICE, "Audio module shut down"); + logger->log("Main", Log::NOTICE, "Control module shut down"); } - if (video) - { - video->shutdown(); - delete video; - logger->log("Core", Log::NOTICE, "Video module shut down"); - } - - if (timers) - { - timers->shutdown(); - delete timers; - logger->log("Core", Log::NOTICE, "Timers module shut down"); - } - - if (led) - { - led->shutdown(); - delete led; - logger->log("Core", Log::NOTICE, "LED module shut down"); - } - - if (inputMan) - { - inputMan->shutdown(); - delete inputMan; - logger->log("Core", Log::NOTICE, "InputMan module shut down"); - } - - - #ifdef HANDLE_VT_SWITCHING ioctl(fdtty, VT_UNLOCKSWITCH, 1); close(fdtty); @@ -412,7 +257,7 @@ void shutdown(int code) if (logger) { - logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n"); + logger->log("Main", Log::NOTICE, "Log module shutting down... bye!\n\n"); logger->shutdown(); delete logger; } @@ -422,43 +267,6 @@ void shutdown(int code) // ------------------------------------------------------------------------------------------------------------------- -ULLONG htonll(ULLONG a) -{ - #if BYTE_ORDER == BIG_ENDIAN - return a; - #else - ULLONG b = 0; - - b = ((a << 56) & 0xFF00000000000000ULL) - | ((a << 40) & 0x00FF000000000000ULL) - | ((a << 24) & 0x0000FF0000000000ULL) - | ((a << 8) & 0x000000FF00000000ULL) - | ((a >> 8) & 0x00000000FF000000ULL) - | ((a >> 24) & 0x0000000000FF0000ULL) - | ((a >> 40) & 0x000000000000FF00ULL) - | ((a >> 56) & 0x00000000000000FFULL) ; - - return b; - #endif -} - -ULLONG ntohll(ULLONG a) -{ - return htonll(a); -} - -void MILLISLEEP(ULONG a) -{ -#ifndef WIN32 - struct timespec delayTime; - delayTime.tv_sec = a / 1000; - delayTime.tv_nsec = (a % 1000) * 1000000; - nanosleep(&delayTime, NULL); -#else - Sleep(a); -#endif -} - long long getTimeMS() { struct timespec ts; diff --git a/objects.mk b/objects.mk index 88aedcf..635fb0a 100644 --- a/objects.mk +++ b/objects.mk @@ -1,4 +1,4 @@ -OBJ_COMMON = control.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o \ +OBJ_COMMON = util.o control.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o \ message.o messagequeue.o wol.o audio.o video.o log.o \ vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o \ directory.o mark.o option.o vfeed.o afeed.o \ diff --git a/playervideorec.cc b/playervideorec.cc index 96b7d78..03a4060 100644 --- a/playervideorec.cc +++ b/playervideorec.cc @@ -29,6 +29,7 @@ #include "dvbsubtitles.h" #include "osdreceiver.h" #include "buffer.h" +#include "util.h" #include "playervideorec.h" diff --git a/tfeed.cc b/tfeed.cc index 97e5284..063b5fa 100644 --- a/tfeed.cc +++ b/tfeed.cc @@ -19,6 +19,7 @@ #include "log.h" #include "demuxer.h" #include "callback.h" +#include "util.h" #include "tfeed.h" diff --git a/threadp.cc b/threadp.cc index e57cfdd..5ae5fe9 100644 --- a/threadp.cc +++ b/threadp.cc @@ -18,6 +18,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "util.h" + #include "threadp.h" // Undeclared functions, only for use in this file to start the thread diff --git a/vconnect.cc b/vconnect.cc index 2874e02..b9fe4d8 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -29,6 +29,7 @@ #include "wol.h" #include "vserverselect.h" #include "messagequeue.h" +#include "util.h" #include "vconnect.h" diff --git a/vfeed.cc b/vfeed.cc index 0bc69dd..00e129c 100644 --- a/vfeed.cc +++ b/vfeed.cc @@ -20,6 +20,7 @@ #include "log.h" #include "demuxer.h" #include "callback.h" +#include "util.h" #include "vfeed.h" diff --git a/videoomx.cc b/videoomx.cc index 2d2ce08..9a90e4d 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -30,6 +30,7 @@ #include "osdopenvg.h" #include "boxstack.h" #include "inputman.h" +#include "util.h" #include "videoomx.h" diff --git a/vscreensaver.cc b/vscreensaver.cc index 3d1a83a..154a368 100644 --- a/vscreensaver.cc +++ b/vscreensaver.cc @@ -27,6 +27,7 @@ #include "colour.h" #include "video.h" #include "surface.h" +#include "util.h" #include "vscreensaver.h" diff --git a/vsleeptimer.cc b/vsleeptimer.cc index 9651396..8db2d3c 100644 --- a/vsleeptimer.cc +++ b/vsleeptimer.cc @@ -17,7 +17,6 @@ along with VOMP. If not, see . */ -#include "vsleeptimer.h" #include "input.h" #include "wsymbol.h" @@ -26,6 +25,9 @@ #include "boxstack.h" #include "message.h" #include "messagequeue.h" +#include "util.h" + +#include "vsleeptimer.h" Sleeptimer* Sleeptimer::instance = NULL; diff --git a/winmain.cc b/winmain.cc index e8f692f..17b9b4a 100644 --- a/winmain.cc +++ b/winmain.cc @@ -34,16 +34,10 @@ #include "log.h" #include "inputman.h" #include "inputwin.h" -#include "ledwin.h" -#include "timers.h" -#include "videowin.h" -#include "audiowin.h" +#include "util.h" + #include "windowsosd.h" -#ifdef WINDOWS_LEGACY -#include "osdwinpixel.h" -#else -#include "osdwinvector.h" -#endif + #include "control.h" #include "message.h" #include "messagequeue.h" @@ -54,14 +48,8 @@ void shutdown(int code); // Global variables -------------------------------------------------------------------------------------------------- int debugEnabled = 0; Log* logger; -InputMan* remote; InputWin* inputWin; -Led* led; -Osd* osd; -Timers* timers; Control* control; -Video* video; -Audio* audio; std::string commandLineServer; // NCONFIG bool wnd_fullscreen=false; @@ -84,12 +72,6 @@ DWORD lastmousemove; MessageQueue* messageQueue; - -void MILLISLEEP(ULONG a) -{ - Sleep(a); -} - int getClockRealTime(struct timespec *tp){ SYSTEMTIME systime; __int64 filetime; @@ -154,15 +136,9 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd // Init global vars ------------------------------------------------------------------------------------------------ logger = new Log(); - remote = new InputMan(); - led = new LedWin(); - timers = new Timers(); - osd = new Osd_TYPE(); - video = new VideoWin(); - audio = new AudioWin(); control = new Control(); - if (!logger || !remote || !led || !osd || !video || !audio || !control) + if (!logger || !control) { ERROR_MSG("Could not create objects. Memory problems?\n"); shutdown(1); @@ -185,93 +161,10 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd logger->log("Core", Log::INFO, "Starting up..."); - // Init modules ---------------------------------------------------------------------------------------------------- int success; - success = remote->init(); - if (success) - { - logger->log("Core", Log::INFO, "Remote module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Remote module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - inputWin = remote->getInputWin(); - - success = led->init(0); - if (success) - { - logger->log("Core", Log::INFO, "LED module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "LED module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = timers->init(); - if (success) - { - logger->log("Core", Log::INFO, "Timers module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Timers module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - UCHAR videoFormat = Video::PAL; // PALNTSC FIXME. - - success = video->init(videoFormat); - if (success) - { - logger->log("Core", Log::INFO, "Video module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Video module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - dynamic_cast(osd)->setWindow(win); - success = osd->init(); - if (success) - { - logger->log("Core", Log::INFO, "OSD module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "OSD module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - video->setDefaultAspect(); - - success = audio->init(Audio::MPEG2_PES); - if (success) - { - logger->log("Core", Log::INFO, "Audio module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Audio module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } success = control->init(); if (success) @@ -281,11 +174,16 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd else { logger->log("Core", Log::EMERG, "Control module failed to initialise"); + delete control; + control = NULL; shutdown(1); WSACleanup(); return 0; } + inputWin = InputMan::getInstance()->getInputWin(); + Video::getInstance()->setDefaultAspect(); + // Other init ------------------------------------------------------------------------------------------------------ logger->log("Core", Log::NOTICE, "Startup successful"); @@ -313,7 +211,7 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd } } else { //Render, moved to OSD ! - Sleep(20); + MILLISLEEP(20); //((OsdWin*)osd)->Render(); } } @@ -361,6 +259,7 @@ void CalculateWindowSize(RECT * size,ULONG size_mode) { UCHAR mode=Video::PAL; UCHAR aspect=Video::ASPECT4X3; UCHAR tvsize=Video::ASPECT4X3; + Video* video = Video::getInstance(); if (video) { mode=video->getMode(); aspect=((VideoWin*)video)->getAspectRatio(); @@ -799,48 +698,6 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "Control module shut down"); } - if (osd) - { - osd->shutdown(); - delete osd; - logger->log("Core", Log::NOTICE, "OSD module shut down"); - } - - if (audio) - { - audio->shutdown(); - delete audio; - logger->log("Core", Log::NOTICE, "Audio module shut down"); - } - - if (video) - { - video->shutdown(); - delete video; - logger->log("Core", Log::NOTICE, "Video module shut down"); - } - - if (timers) - { - timers->shutdown(); - delete timers; - logger->log("Core", Log::NOTICE, "Timers module shut down"); - } - - if (led) - { - led->shutdown(); - delete led; - logger->log("Core", Log::NOTICE, "LED module shut down"); - } - - if (remote) - { - remote->shutdown(); - delete remote; - logger->log("Core", Log::NOTICE, "Remote module shut down"); - } - if (logger) { logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n"); @@ -853,17 +710,6 @@ void shutdown(int code) // ------------------------------------------------------------------------------------------------------------------- -ULLONG htonll(ULLONG a) -{ - return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) - |(ULONG)htonl(((ULONG) (a >> 32)))); -} - -ULLONG ntohll(ULLONG a) -{ - return htonll(a); -} - const std::string& getCommandLineServer() { return commandLineServer; -- 2.39.5