2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "remotemvp.h"
46 void sighandler(int signalReceived);
49 void shutdown(int code);
53 int ticonfig_main(int, char**);
56 // Global variables --------------------------------------------------------------------------------------------------
70 // Linux MVP main function and sighandler
72 int main(int argc, char** argv)
74 if (strstr(argv[0], "ticonfig")) return ticonfig_main(argc, argv);
76 bool daemonize = true;
77 bool debugEnabled = false;
81 while ((c = getopt(argc, argv, "cdn")) != -1)
89 debugEnabled = true; // and...
94 printf("Unknown option\n");
97 printf("Option error\n");
102 // Init global vars ------------------------------------------------------------------------------------------------
105 timers = new Timers();
108 remote = new RemoteMVP();
111 audio = new AudioMVP();
112 video = new VideoMVP();
113 boxstack = new BoxStack();
114 command = new Command();
117 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !boxstack || !command || !wol)
119 printf("Could not create objects. Memory problems?\n");
123 // Get logging module started --------------------------------------------------------------------------------------
125 if (!logger->init(Log::DEBUG, "dummy", debugEnabled ? 1 : 0))
127 printf("Could not initialise log object. Aborting.\n");
131 logger->log("Core", Log::INFO, "Starting up...");
133 // Daemonize if not -d
138 pid_t forkTest = fork();
140 { printf("Cannot fork (1).\n"); exit(1); }
141 if (forkTest != 0) _exit(0); // PID returned, I am the parent
142 // otherwise, I am the child
146 { printf("Cannot fork (2).\n"); exit(1); }
147 if (forkTest != 0) _exit(0); // PID returned, I am the parent
148 // otherwise, I am the child
154 // Set up signal handling ------------------------------------------------------------------------------------------
156 sighandler_t sigtest;
158 sigtest = signal(SIGPIPE, SIG_IGN);
159 if (sigtest == SIG_ERR)
161 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
164 sigtest = signal(SIGINT, sighandler);
165 if (sigtest == SIG_ERR)
167 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
170 sigtest = signal(SIGTERM, sighandler);
171 if (sigtest == SIG_ERR)
173 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
176 sigtest = signal(SIGUSR1, sighandler);
177 if (sigtest == SIG_ERR)
179 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
183 sigtest = signal(SIGUSR2, sighandler);
184 if (sigtest == SIG_ERR)
186 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
190 sigtest = signal(SIGURG, sighandler);
191 if (sigtest == SIG_ERR)
193 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
197 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
200 // Init modules ----------------------------------------------------------------------------------------------------
203 success = remote->init("/dev/rawir");
206 logger->log("Core", Log::INFO, "Remote module initialised");
210 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
214 success = led->init(((RemoteMVP*)remote)->getDevice());
217 logger->log("Core", Log::INFO, "LED module initialised");
221 logger->log("Core", Log::EMERG, "LED module failed to initialise");
225 success = mtd->init();
228 logger->log("Core", Log::INFO, "Mtd module initialised");
232 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
236 success = timers->init();
239 logger->log("Core", Log::INFO, "Timers module initialised");
243 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
247 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
248 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
249 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
250 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
252 success = video->init(videoFormat);
255 logger->log("Core", Log::INFO, "Video module initialised");
259 logger->log("Core", Log::EMERG, "Video module failed to initialise");
263 success = osd->init((void*)("/dev/stbgfx"));
266 logger->log("Core", Log::INFO, "OSD module initialised");
270 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
274 success = audio->init(Audio::MPEG2_PES);
277 logger->log("Core", Log::INFO, "Audio module initialised");
281 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
285 success = vdr->init(3024);
288 logger->log("Core", Log::INFO, "VDR module initialised");
292 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
296 success = boxstack->init();
299 logger->log("Core", Log::INFO, "BoxStack module initialised");
303 logger->log("Core", Log::EMERG, "BoxStack module failed to initialise");
307 success = command->init(crashed);
310 logger->log("Core", Log::INFO, "Command module initialised");
314 logger->log("Core", Log::EMERG, "Command module failed to initialise");
318 // Other init ------------------------------------------------------------------------------------------------------
320 logger->log("Core", Log::NOTICE, "Startup successful");
322 // Run main loop ---------------------------------------------------------------------------------------------------
324 // Ok, all major device components and other bits are loaded and ready
327 // When that returns quit ------------------------------------------------------------------------------------------
333 // -------------------------------------------------------------------------------------------------------------------
335 void sighandler(int signalReceived)
337 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
339 switch (signalReceived)
343 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
344 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
349 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
350 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
361 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
362 logger->upLogLevel();
367 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
368 logger->downLogLevel();
374 logger->log("Core", Log::DEBUG, "SIGURG caught");
381 // -------------------------------------------------------------------------------------------------------------------
383 void shutdown(int code)
387 boxstack->shutdown();
389 logger->log("Core", Log::NOTICE, "BoxStack module shut down");
392 // FIXME, send a del all to boxstack first, then get rid of it after command?
393 if (command) // shut down command here in case views have posted messages
397 logger->log("Core", Log::NOTICE, "Command module shut down");
404 logger->log("Core", Log::NOTICE, "VDR module shut down");
411 logger->log("Core", Log::NOTICE, "OSD module shut down");
418 logger->log("Core", Log::NOTICE, "Audio module shut down");
425 logger->log("Core", Log::NOTICE, "Video module shut down");
432 logger->log("Core", Log::NOTICE, "Timers module shut down");
439 logger->log("Core", Log::NOTICE, "MTD module shut down");
446 logger->log("Core", Log::NOTICE, "LED module shut down");
453 logger->log("Core", Log::NOTICE, "Remote module shut down");
459 logger->log("Core", Log::NOTICE, "WOL module shut down");
464 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
472 // -------------------------------------------------------------------------------------------------------------------
474 ULLONG ntohll(ULLONG a)
479 ULLONG htonll(ULLONG a)
481 #if BYTE_ORDER == BIG_ENDIAN
486 b = ((a << 56) & 0xFF00000000000000ULL)
487 | ((a << 40) & 0x00FF000000000000ULL)
488 | ((a << 24) & 0x0000FF0000000000ULL)
489 | ((a << 8) & 0x000000FF00000000ULL)
490 | ((a >> 8) & 0x00000000FF000000ULL)
491 | ((a >> 24) & 0x0000000000FF0000ULL)
492 | ((a >> 40) & 0x000000000000FF00ULL)
493 | ((a >> 56) & 0x00000000000000FFULL) ;
499 void MILLISLEEP(ULONG a)
502 struct timespec delayTime;
503 delayTime.tv_sec = a / 1000;
504 delayTime.tv_nsec = (a % 1000) * 1000000;
505 nanosleep(&delayTime, NULL);
511 int max(int a, int b)