2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
30 #include "defines.h"
\r
34 #include "boxstack.h"
\r
35 #include "command.h"
\r
38 #ifdef VOMP_PLATTFORM_MVP
\r
42 #include "remotemvp.h"
\r
45 #include "audiomvp.h"
\r
46 #include "videomvp.h"
\r
50 int ticonfig_main(int, char**);
\r
55 #ifdef VOMP_PLATTFORM_NMT
\r
58 #include "remotelirc.h"
\r
60 #include "osddirectfb.h"
\r
61 #include "audionmt.h"
\r
62 #include "videonmt.h"
\r
66 #ifdef VOMP_PLATTFORM_RASPBERRY
\r
68 #include "mtdraspberry.h"
\r
69 #include "remotelinux.h"
\r
70 #include "ledraspberry.h"
\r
71 #include "osdopengl.h"
\r
72 #include "audiovpe.h"
\r
73 #include "videovpeogl.h"
\r
81 #include "vsleeptimer.h"
\r
85 void sighandler(int signalReceived);
\r
88 void shutdown(int code);
\r
92 // Global variables --------------------------------------------------------------------------------------------------
\r
105 Sleeptimer* sleeptimer;
\r
107 // Linux MVP main function and sighandler
\r
109 int main(int argc, char** argv)
\r
111 #ifdef VOMP_PLATTFORM_MVP
\r
112 if (strstr(argv[0], "ticonfig")) return ticonfig_main(argc, argv);
\r
115 bool daemonize = true;
\r
116 bool debugEnabled = false;
\r
117 bool crashed = false;
\r
118 char* setServer = NULL;
\r
121 while ((c = getopt(argc, argv, "cdns:")) != -1)
\r
129 debugEnabled = true; // and...
\r
134 setServer = optarg;
\r
137 printf("Unknown option\n");
\r
140 printf("Option error\n");
\r
145 // Init global vars ------------------------------------------------------------------------------------------------
\r
146 logger = new Log();
\r
147 timers = new Timers();
\r
150 mtd = new Mtd_TYPE();
\r
151 remote = new Remote_TYPE();
\r
152 led = new Led_TYPE();
\r
153 osd = new Osd_TYPE();
\r
154 audio = new Audio_TYPE();
\r
155 video = new Video_TYPE();
\r
159 boxstack = new BoxStack();
\r
160 command = new Command();
\r
162 sleeptimer = new Sleeptimer();
\r
164 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !boxstack || !command || !wol || !sleeptimer)
\r
166 printf("Could not create objects. Memory problems?\n");
\r
170 // Get logging module started --------------------------------------------------------------------------------------
\r
172 if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0))
\r
174 printf("Could not initialise log object. Aborting.\n");
\r
178 logger->log("Core", Log::INFO, "Starting up...");
\r
180 // Daemonize if not -d
\r
185 pid_t forkTest = fork();
\r
186 if (forkTest == -1)
\r
187 { printf("Cannot fork (1).\n"); exit(1); }
\r
188 if (forkTest != 0) _exit(0); // PID returned, I am the parent
\r
189 // otherwise, I am the child
\r
192 if (forkTest == -1)
\r
193 { printf("Cannot fork (2).\n"); exit(1); }
\r
194 if (forkTest != 0) _exit(0); // PID returned, I am the parent
\r
195 // otherwise, I am the child
\r
201 // Set up signal handling ------------------------------------------------------------------------------------------
\r
203 sighandler_t sigtest;
\r
205 sigtest = signal(SIGPIPE, SIG_IGN);
\r
206 if (sigtest == SIG_ERR)
\r
208 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
\r
211 sigtest = signal(SIGINT, sighandler);
\r
212 if (sigtest == SIG_ERR)
\r
214 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
\r
217 sigtest = signal(SIGTERM, sighandler);
\r
218 if (sigtest == SIG_ERR)
\r
220 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
\r
223 sigtest = signal(SIGUSR1, sighandler);
\r
224 if (sigtest == SIG_ERR)
\r
226 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
\r
230 sigtest = signal(SIGUSR2, sighandler);
\r
231 if (sigtest == SIG_ERR)
\r
233 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
\r
237 sigtest = signal(SIGURG, sighandler);
\r
238 if (sigtest == SIG_ERR)
\r
240 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
\r
244 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
\r
247 // Init modules ----------------------------------------------------------------------------------------------------
\r
250 success = remote->init(RemoteStartDev);
\r
254 logger->log("Core", Log::INFO, "Remote module initialised");
\r
258 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
\r
261 #ifdef VOMP_PLATTFORM_MVP
\r
262 success = led->init(((RemoteMVP*)remote)->getDevice());
\r
264 success = led->init(-1);
\r
268 logger->log("Core", Log::INFO, "LED module initialised");
\r
272 logger->log("Core", Log::EMERG, "LED module failed to initialise");
\r
276 success = mtd->init();
\r
279 logger->log("Core", Log::INFO, "Mtd module initialised");
\r
283 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
\r
287 success = timers->init();
\r
290 logger->log("Core", Log::INFO, "Timers module initialised");
\r
294 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
\r
298 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
\r
299 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
\r
300 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
\r
301 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
\r
303 success = video->init(videoFormat);
\r
306 logger->log("Core", Log::INFO, "Video module initialised");
\r
310 logger->log("Core", Log::EMERG, "Video module failed to initialise");
\r
314 success = osd->init((void*)OsdStartDev);
\r
317 logger->log("Core", Log::INFO, "OSD module initialised");
\r
321 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
\r
325 success = audio->init(Audio::MPEG2_PES);
\r
328 logger->log("Core", Log::INFO, "Audio module initialised");
\r
332 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
\r
336 success = vdr->init(3024);
\r
339 logger->log("Core", Log::INFO, "VDR module initialised");
\r
343 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
\r
347 success = boxstack->init();
\r
350 logger->log("Core", Log::INFO, "BoxStack module initialised");
\r
354 logger->log("Core", Log::EMERG, "BoxStack module failed to initialise");
\r
358 success = command->init(crashed, setServer);
\r
361 logger->log("Core", Log::INFO, "Command module initialised");
\r
365 logger->log("Core", Log::EMERG, "Command module failed to initialise");
\r
369 // Other init ------------------------------------------------------------------------------------------------------
\r
371 logger->log("Core", Log::NOTICE, "Startup successful");
\r
373 // Run main loop ---------------------------------------------------------------------------------------------------
\r
375 // Ok, all major device components and other bits are loaded and ready
\r
378 // When that returns quit ------------------------------------------------------------------------------------------
\r
384 // -------------------------------------------------------------------------------------------------------------------
\r
386 void sighandler(int signalReceived)
\r
388 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
\r
390 switch (signalReceived)
\r
394 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
\r
395 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
\r
400 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
\r
401 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
\r
412 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
\r
413 logger->upLogLevel();
\r
418 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
\r
419 logger->downLogLevel();
\r
425 logger->log("Core", Log::DEBUG, "SIGURG caught");
\r
432 // -------------------------------------------------------------------------------------------------------------------
\r
434 void shutdown(int code)
\r
438 boxstack->shutdown();
\r
440 logger->log("Core", Log::NOTICE, "BoxStack module shut down");
\r
443 // FIXME, send a del all to boxstack first, then get rid of it after command?
\r
444 if (command) // shut down command here in case views have posted messages
\r
446 command->shutdown();
\r
448 logger->log("Core", Log::NOTICE, "Command module shut down");
\r
455 logger->log("Core", Log::NOTICE, "VDR module shut down");
\r
462 logger->log("Core", Log::NOTICE, "OSD module shut down");
\r
469 logger->log("Core", Log::NOTICE, "Audio module shut down");
\r
476 logger->log("Core", Log::NOTICE, "Video module shut down");
\r
481 timers->shutdown();
\r
483 logger->log("Core", Log::NOTICE, "Timers module shut down");
\r
490 logger->log("Core", Log::NOTICE, "MTD module shut down");
\r
497 logger->log("Core", Log::NOTICE, "LED module shut down");
\r
502 remote->shutdown();
\r
504 logger->log("Core", Log::NOTICE, "Remote module shut down");
\r
510 logger->log("Core", Log::NOTICE, "WOL module shut down");
\r
516 logger->log("Core", Log::NOTICE, "Sleeptimer module shut down");
\r
521 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
\r
522 logger->shutdown();
\r
529 // -------------------------------------------------------------------------------------------------------------------
\r
531 ULLONG htonll(ULLONG a)
\r
533 #if BYTE_ORDER == BIG_ENDIAN
\r
538 b = ((a << 56) & 0xFF00000000000000ULL)
\r
539 | ((a << 40) & 0x00FF000000000000ULL)
\r
540 | ((a << 24) & 0x0000FF0000000000ULL)
\r
541 | ((a << 8) & 0x000000FF00000000ULL)
\r
542 | ((a >> 8) & 0x00000000FF000000ULL)
\r
543 | ((a >> 24) & 0x0000000000FF0000ULL)
\r
544 | ((a >> 40) & 0x000000000000FF00ULL)
\r
545 | ((a >> 56) & 0x00000000000000FFULL) ;
\r
551 ULLONG ntohll(ULLONG a)
\r
556 void MILLISLEEP(ULONG a)
\r
559 struct timespec delayTime;
\r
560 delayTime.tv_sec = a / 1000;
\r
561 delayTime.tv_nsec = (a % 1000) * 1000000;
\r
562 nanosleep(&delayTime, NULL);
\r
568 long long getTimeMS() {
\r
569 struct timespec ts;
\r
570 clock_gettime(CLOCK_MONOTONIC, &ts);
\r
571 return ts.tv_sec*1000+ts.tv_nsec/1000000LL;
\r
574 int min(UINT a, int b)
\r
576 if (a > b) return b;
\r
580 int max(int a, int b)
\r
582 if (a > b) return a;
\r