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 success = video->init(videoFormat);
215 logger->log("Core", Log::INFO, "Video module initialised");
219 logger->log("Core", Log::EMERG, "Video module failed to initialise");
223 success = osd->init("/dev/stbgfx");
226 logger->log("Core", Log::INFO, "OSD module initialised");
230 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
234 success = audio->init(Audio::MPEG2_PES);
237 logger->log("Core", Log::INFO, "Audio module initialised");
241 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
245 success = vdr->init(3024);
248 logger->log("Core", Log::INFO, "VDR module initialised");
252 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
256 success = viewman->init();
259 logger->log("Core", Log::INFO, "ViewMan module initialised");
263 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
267 success = command->init();
270 logger->log("Core", Log::INFO, "Command module initialised");
274 logger->log("Core", Log::EMERG, "Command module failed to initialise");
278 // Other init ------------------------------------------------------------------------------------------------------
280 logger->log("Core", Log::NOTICE, "Startup successful");
282 // Run main loop ---------------------------------------------------------------------------------------------------
284 // Ok, all major device components and other bits are loaded and ready
287 // When that returns quit ------------------------------------------------------------------------------------------
293 // -------------------------------------------------------------------------------------------------------------------
295 void shutdown(int code)
301 logger->log("Core", Log::NOTICE, "Command module shut down");
308 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
315 logger->log("Core", Log::NOTICE, "VDR module shut down");
322 logger->log("Core", Log::NOTICE, "OSD module shut down");
329 logger->log("Core", Log::NOTICE, "Audio module shut down");
336 logger->log("Core", Log::NOTICE, "Video module shut down");
343 logger->log("Core", Log::NOTICE, "Timers module shut down");
350 logger->log("Core", Log::NOTICE, "MTD module shut down");
357 logger->log("Core", Log::NOTICE, "LED module shut down");
364 logger->log("Core", Log::NOTICE, "Remote module shut down");
369 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
377 // -------------------------------------------------------------------------------------------------------------------
379 void sighandler(int signalReceived)
381 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
383 switch (signalReceived)
387 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
388 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
393 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
394 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
405 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
406 logger->upLogLevel();
411 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
412 logger->downLogLevel();
418 logger->log("Core", Log::DEBUG, "SIGURG caught");
424 // -------------------------------------------------------------------------------------------------------------------
426 ULLONG ntohll(ULLONG a)
431 ULLONG htonll(ULLONG a)
433 #if BYTE_ORDER == BIG_ENDIAN
438 b = ((a << 56) & 0xFF00000000000000ULL)
439 | ((a << 40) & 0x00FF000000000000ULL)
440 | ((a << 24) & 0x0000FF0000000000ULL)
441 | ((a << 8) & 0x000000FF00000000ULL)
442 | ((a >> 8) & 0x00000000FF000000ULL)
443 | ((a >> 24) & 0x0000000000FF0000ULL)
444 | ((a >> 40) & 0x000000000000FF00ULL)
445 | ((a >> 56) & 0x00000000000000FFULL) ;