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
46 void sighandler(int signalReceived);
47 void shutdown(int code);
49 // Global variables --------------------------------------------------------------------------------------------------
63 int main(int argc, char** argv)
65 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
68 // Init global vars ------------------------------------------------------------------------------------------------
71 remote = new Remote();
74 timers = new Timers();
79 audio = new AudioMVP();
81 audio = new AudioWin();
83 viewman = new ViewMan();
84 command = new Command();
86 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
88 printf("Could not create objects. Memory problems?\n");
92 // Get logging module started --------------------------------------------------------------------------------------
94 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
96 printf("Could not initialise log object. Aborting.\n");
100 logger->log("Core", Log::INFO, "Starting up...");
102 // Daemonize if not -d
107 pid_t forkTest = fork();
109 { printf("Cannot fork (1).\n"); exit(1); }
110 if (forkTest != 0) _exit(0); // PID returned, I am the parent
111 // otherwise, I am the child
115 { printf("Cannot fork (2).\n"); exit(1); }
116 if (forkTest != 0) _exit(0); // PID returned, I am the parent
117 // otherwise, I am the child
123 // Set up signal handling ------------------------------------------------------------------------------------------
125 sighandler_t sigtest;
127 sigtest = signal(SIGPIPE, SIG_IGN);
128 if (sigtest == SIG_ERR)
130 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
133 sigtest = signal(SIGINT, sighandler);
134 if (sigtest == SIG_ERR)
136 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
139 sigtest = signal(SIGTERM, sighandler);
140 if (sigtest == SIG_ERR)
142 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
145 sigtest = signal(SIGUSR1, sighandler);
146 if (sigtest == SIG_ERR)
148 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
152 sigtest = signal(SIGUSR2, sighandler);
153 if (sigtest == SIG_ERR)
155 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
159 sigtest = signal(SIGURG, sighandler);
160 if (sigtest == SIG_ERR)
162 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
166 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
169 // Init modules ----------------------------------------------------------------------------------------------------
172 success = remote->init("/dev/rawir");
175 logger->log("Core", Log::INFO, "Remote module initialised");
179 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
183 success = led->init(remote->getDevice());
186 logger->log("Core", Log::INFO, "LED module initialised");
190 logger->log("Core", Log::EMERG, "LED module failed to initialise");
194 success = mtd->init("/dev/mtd1");
197 logger->log("Core", Log::INFO, "Mtd module initialised");
201 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
205 success = timers->init();
208 logger->log("Core", Log::INFO, "Timers module initialised");
212 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
216 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
217 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
218 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
219 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
221 success = video->init(videoFormat);
224 logger->log("Core", Log::INFO, "Video module initialised");
228 logger->log("Core", Log::EMERG, "Video module failed to initialise");
232 success = osd->init("/dev/stbgfx");
235 logger->log("Core", Log::INFO, "OSD module initialised");
239 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
243 success = audio->init(Audio::MPEG2_PES);
246 logger->log("Core", Log::INFO, "Audio module initialised");
250 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
254 success = vdr->init(3024);
257 logger->log("Core", Log::INFO, "VDR module initialised");
261 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
265 success = viewman->init();
268 logger->log("Core", Log::INFO, "ViewMan module initialised");
272 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
276 success = command->init();
279 logger->log("Core", Log::INFO, "Command module initialised");
283 logger->log("Core", Log::EMERG, "Command module failed to initialise");
287 // Other init ------------------------------------------------------------------------------------------------------
289 logger->log("Core", Log::NOTICE, "Startup successful");
291 // Run main loop ---------------------------------------------------------------------------------------------------
293 // Ok, all major device components and other bits are loaded and ready
296 // When that returns quit ------------------------------------------------------------------------------------------
302 // -------------------------------------------------------------------------------------------------------------------
304 void shutdown(int code)
310 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
313 if (command) // shut down command here in case views have posted messages
317 logger->log("Core", Log::NOTICE, "Command module shut down");
324 logger->log("Core", Log::NOTICE, "VDR module shut down");
331 logger->log("Core", Log::NOTICE, "OSD module shut down");
338 logger->log("Core", Log::NOTICE, "Audio module shut down");
345 logger->log("Core", Log::NOTICE, "Video module shut down");
352 logger->log("Core", Log::NOTICE, "Timers module shut down");
359 logger->log("Core", Log::NOTICE, "MTD module shut down");
366 logger->log("Core", Log::NOTICE, "LED module shut down");
373 logger->log("Core", Log::NOTICE, "Remote module shut down");
378 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
386 // -------------------------------------------------------------------------------------------------------------------
388 void sighandler(int signalReceived)
390 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
392 switch (signalReceived)
396 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
397 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
402 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
403 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
414 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
415 logger->upLogLevel();
420 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
421 logger->downLogLevel();
427 logger->log("Core", Log::DEBUG, "SIGURG caught");
433 // -------------------------------------------------------------------------------------------------------------------
435 ULLONG ntohll(ULLONG a)
440 ULLONG htonll(ULLONG a)
442 #if BYTE_ORDER == BIG_ENDIAN
447 b = ((a << 56) & 0xFF00000000000000ULL)
448 | ((a << 40) & 0x00FF000000000000ULL)
449 | ((a << 24) & 0x0000FF0000000000ULL)
450 | ((a << 8) & 0x000000FF00000000ULL)
451 | ((a >> 8) & 0x00000000FF000000ULL)
452 | ((a >> 24) & 0x0000000000FF0000ULL)
453 | ((a >> 40) & 0x000000000000FF00ULL)
454 | ((a >> 56) & 0x00000000000000FFULL) ;