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
41 void sighandler(int signalReceived);
42 void shutdown(int code);
44 // Global variables --------------------------------------------------------------------------------------------------
58 int main(int argc, char** argv)
60 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
63 // Init global vars ------------------------------------------------------------------------------------------------
66 remote = new Remote();
69 timers = new Timers();
74 viewman = new ViewMan();
75 command = new Command();
77 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
79 printf("Could not create objects. Memory problems?\n");
83 // Get logging module started --------------------------------------------------------------------------------------
85 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
87 printf("Could not initialise log object. Aborting.\n");
91 logger->log("Core", Log::INFO, "Starting up...");
93 // Daemonize if not -d
98 pid_t forkTest = fork();
100 { printf("Cannot fork (1).\n"); exit(1); }
101 if (forkTest != 0) _exit(0); // PID returned, I am the parent
102 // otherwise, I am the child
106 { printf("Cannot fork (2).\n"); exit(1); }
107 if (forkTest != 0) _exit(0); // PID returned, I am the parent
108 // otherwise, I am the child
114 // Set up signal handling ------------------------------------------------------------------------------------------
116 sighandler_t sigtest;
118 sigtest = signal(SIGPIPE, SIG_IGN);
119 if (sigtest == SIG_ERR)
121 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
124 sigtest = signal(SIGINT, sighandler);
125 if (sigtest == SIG_ERR)
127 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
130 sigtest = signal(SIGTERM, sighandler);
131 if (sigtest == SIG_ERR)
133 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
136 sigtest = signal(SIGUSR1, sighandler);
137 if (sigtest == SIG_ERR)
139 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
143 sigtest = signal(SIGUSR2, sighandler);
144 if (sigtest == SIG_ERR)
146 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
150 sigtest = signal(SIGURG, sighandler);
151 if (sigtest == SIG_ERR)
153 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
157 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
160 // Init modules ----------------------------------------------------------------------------------------------------
163 success = remote->init("/dev/rawir");
166 logger->log("Core", Log::INFO, "Remote module initialised");
170 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
174 success = led->init(remote->getDevice());
177 logger->log("Core", Log::INFO, "LED module initialised");
181 logger->log("Core", Log::EMERG, "LED module failed to initialise");
185 success = mtd->init("/dev/mtd1");
188 logger->log("Core", Log::INFO, "Mtd module initialised");
192 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
196 success = timers->init();
199 logger->log("Core", Log::INFO, "Timers module initialised");
203 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
207 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
208 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
209 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
210 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
212 //videoFormat = Video::NTSC; // enable this line to test NTSC in PAL land
214 success = video->init(videoFormat);
217 logger->log("Core", Log::INFO, "Video module initialised");
221 logger->log("Core", Log::EMERG, "Video module failed to initialise");
225 success = osd->init("/dev/stbgfx");
228 logger->log("Core", Log::INFO, "OSD module initialised");
232 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
236 success = audio->init(Audio::MPEG2_PES);
239 logger->log("Core", Log::INFO, "Audio module initialised");
243 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
247 success = vdr->init(3024);
250 logger->log("Core", Log::INFO, "VDR module initialised");
254 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
258 success = viewman->init();
261 logger->log("Core", Log::INFO, "ViewMan module initialised");
265 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
269 success = command->init();
272 logger->log("Core", Log::INFO, "Command module initialised");
276 logger->log("Core", Log::EMERG, "Command module failed to initialise");
280 // Other init ------------------------------------------------------------------------------------------------------
282 logger->log("Core", Log::NOTICE, "Startup successful");
284 // Run main loop ---------------------------------------------------------------------------------------------------
286 // Ok, all major device components and other bits are loaded and ready
289 // When that returns quit ------------------------------------------------------------------------------------------
295 // -------------------------------------------------------------------------------------------------------------------
297 void shutdown(int code)
303 logger->log("Core", Log::NOTICE, "Command module shut down");
310 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
317 logger->log("Core", Log::NOTICE, "VDR module shut down");
324 logger->log("Core", Log::NOTICE, "OSD module shut down");
331 logger->log("Core", Log::NOTICE, "Audio module shut down");
338 logger->log("Core", Log::NOTICE, "Video module shut down");
345 logger->log("Core", Log::NOTICE, "Timers module shut down");
352 logger->log("Core", Log::NOTICE, "MTD module shut down");
359 logger->log("Core", Log::NOTICE, "LED module shut down");
366 logger->log("Core", Log::NOTICE, "Remote module shut down");
371 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
379 // -------------------------------------------------------------------------------------------------------------------
381 void sighandler(int signalReceived)
383 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
385 switch (signalReceived)
389 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
390 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
395 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
396 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
407 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
408 logger->upLogLevel();
413 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
414 logger->downLogLevel();
420 logger->log("Core", Log::DEBUG, "SIGURG caught");
426 // -------------------------------------------------------------------------------------------------------------------
428 ULLONG ntohll(ULLONG a)
433 ULLONG htonll(ULLONG a)
435 #if BYTE_ORDER == BIG_ENDIAN
440 b = ((a << 56) & 0xFF00000000000000ULL)
441 | ((a << 40) & 0x00FF000000000000ULL)
442 | ((a << 24) & 0x0000FF0000000000ULL)
443 | ((a << 8) & 0x000000FF00000000ULL)
444 | ((a >> 8) & 0x00000000FF000000ULL)
445 | ((a >> 24) & 0x0000000000FF0000ULL)
446 | ((a >> 40) & 0x000000000000FF00ULL)
447 | ((a >> 56) & 0x00000000000000FFULL) ;