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
48 void sighandler(int signalReceived);
49 void shutdown(int code);
51 // Global variables --------------------------------------------------------------------------------------------------
65 int main(int argc, char** argv)
67 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
70 // Init global vars ------------------------------------------------------------------------------------------------
73 remote = new Remote();
76 timers = new Timers();
80 audio = new AudioMVP();
81 video = new VideoMVP();
84 audio = new AudioWin();
85 video = new VideoWin();
87 viewman = new ViewMan();
88 command = new Command();
90 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
92 printf("Could not create objects. Memory problems?\n");
96 // Get logging module started --------------------------------------------------------------------------------------
98 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
100 printf("Could not initialise log object. Aborting.\n");
104 logger->log("Core", Log::INFO, "Starting up...");
106 // Daemonize if not -d
111 pid_t forkTest = fork();
113 { printf("Cannot fork (1).\n"); exit(1); }
114 if (forkTest != 0) _exit(0); // PID returned, I am the parent
115 // otherwise, I am the child
119 { printf("Cannot fork (2).\n"); exit(1); }
120 if (forkTest != 0) _exit(0); // PID returned, I am the parent
121 // otherwise, I am the child
127 // Set up signal handling ------------------------------------------------------------------------------------------
129 sighandler_t sigtest;
131 sigtest = signal(SIGPIPE, SIG_IGN);
132 if (sigtest == SIG_ERR)
134 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
137 sigtest = signal(SIGINT, sighandler);
138 if (sigtest == SIG_ERR)
140 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
143 sigtest = signal(SIGTERM, sighandler);
144 if (sigtest == SIG_ERR)
146 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
149 sigtest = signal(SIGUSR1, sighandler);
150 if (sigtest == SIG_ERR)
152 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
156 sigtest = signal(SIGUSR2, sighandler);
157 if (sigtest == SIG_ERR)
159 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
163 sigtest = signal(SIGURG, sighandler);
164 if (sigtest == SIG_ERR)
166 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
170 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
173 // Init modules ----------------------------------------------------------------------------------------------------
176 success = remote->init("/dev/rawir");
179 logger->log("Core", Log::INFO, "Remote module initialised");
183 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
187 success = led->init(remote->getDevice());
190 logger->log("Core", Log::INFO, "LED module initialised");
194 logger->log("Core", Log::EMERG, "LED module failed to initialise");
198 success = mtd->init("/dev/mtd1");
201 logger->log("Core", Log::INFO, "Mtd module initialised");
205 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
209 success = timers->init();
212 logger->log("Core", Log::INFO, "Timers module initialised");
216 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
220 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
221 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
222 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
223 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
225 success = video->init(videoFormat);
228 logger->log("Core", Log::INFO, "Video module initialised");
232 logger->log("Core", Log::EMERG, "Video module failed to initialise");
236 success = osd->init("/dev/stbgfx");
239 logger->log("Core", Log::INFO, "OSD module initialised");
243 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
247 success = audio->init(Audio::MPEG2_PES);
250 logger->log("Core", Log::INFO, "Audio module initialised");
254 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
258 success = vdr->init(3024);
261 logger->log("Core", Log::INFO, "VDR module initialised");
265 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
269 success = viewman->init();
272 logger->log("Core", Log::INFO, "ViewMan module initialised");
276 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
280 success = command->init();
283 logger->log("Core", Log::INFO, "Command module initialised");
287 logger->log("Core", Log::EMERG, "Command module failed to initialise");
291 // Other init ------------------------------------------------------------------------------------------------------
293 logger->log("Core", Log::NOTICE, "Startup successful");
295 // Run main loop ---------------------------------------------------------------------------------------------------
297 // Ok, all major device components and other bits are loaded and ready
300 // When that returns quit ------------------------------------------------------------------------------------------
306 // -------------------------------------------------------------------------------------------------------------------
308 void shutdown(int code)
314 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
317 if (command) // shut down command here in case views have posted messages
321 logger->log("Core", Log::NOTICE, "Command module shut down");
328 logger->log("Core", Log::NOTICE, "VDR module shut down");
335 logger->log("Core", Log::NOTICE, "OSD module shut down");
342 logger->log("Core", Log::NOTICE, "Audio module shut down");
349 logger->log("Core", Log::NOTICE, "Video module shut down");
356 logger->log("Core", Log::NOTICE, "Timers module shut down");
363 logger->log("Core", Log::NOTICE, "MTD module shut down");
370 logger->log("Core", Log::NOTICE, "LED module shut down");
377 logger->log("Core", Log::NOTICE, "Remote module shut down");
382 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
390 // -------------------------------------------------------------------------------------------------------------------
392 void sighandler(int signalReceived)
394 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
396 switch (signalReceived)
400 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
401 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
406 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
407 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
418 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
419 logger->upLogLevel();
424 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
425 logger->downLogLevel();
431 logger->log("Core", Log::DEBUG, "SIGURG caught");
437 // -------------------------------------------------------------------------------------------------------------------
439 ULLONG ntohll(ULLONG a)
444 ULLONG htonll(ULLONG a)
446 #if BYTE_ORDER == BIG_ENDIAN
451 b = ((a << 56) & 0xFF00000000000000ULL)
452 | ((a << 40) & 0x00FF000000000000ULL)
453 | ((a << 24) & 0x0000FF0000000000ULL)
454 | ((a << 8) & 0x000000FF00000000ULL)
455 | ((a >> 8) & 0x00000000FF000000ULL)
456 | ((a >> 24) & 0x0000000000FF0000ULL)
457 | ((a >> 40) & 0x000000000000FF00ULL)
458 | ((a >> 56) & 0x00000000000000FFULL) ;