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
49 void sighandler(int signalReceived);
50 void shutdown(int code);
52 // Global variables --------------------------------------------------------------------------------------------------
66 int main(int argc, char** argv)
68 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
71 // Init global vars ------------------------------------------------------------------------------------------------
74 remote = new Remote();
76 timers = new Timers();
81 audio = new AudioWin();
82 video = new VideoWin();
86 audio = new AudioMVP();
87 video = new VideoMVP();
89 viewman = new ViewMan();
90 command = new Command();
92 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
94 printf("Could not create objects. Memory problems?\n");
98 // Get logging module started --------------------------------------------------------------------------------------
100 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
102 printf("Could not initialise log object. Aborting.\n");
106 logger->log("Core", Log::INFO, "Starting up...");
108 // Daemonize if not -d
113 pid_t forkTest = fork();
115 { printf("Cannot fork (1).\n"); exit(1); }
116 if (forkTest != 0) _exit(0); // PID returned, I am the parent
117 // otherwise, I am the child
121 { printf("Cannot fork (2).\n"); exit(1); }
122 if (forkTest != 0) _exit(0); // PID returned, I am the parent
123 // otherwise, I am the child
129 // Set up signal handling ------------------------------------------------------------------------------------------
131 sighandler_t sigtest;
133 sigtest = signal(SIGPIPE, SIG_IGN);
134 if (sigtest == SIG_ERR)
136 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
139 sigtest = signal(SIGINT, sighandler);
140 if (sigtest == SIG_ERR)
142 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
145 sigtest = signal(SIGTERM, sighandler);
146 if (sigtest == SIG_ERR)
148 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
151 sigtest = signal(SIGUSR1, sighandler);
152 if (sigtest == SIG_ERR)
154 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
158 sigtest = signal(SIGUSR2, sighandler);
159 if (sigtest == SIG_ERR)
161 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
165 sigtest = signal(SIGURG, sighandler);
166 if (sigtest == SIG_ERR)
168 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
172 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
175 // Init modules ----------------------------------------------------------------------------------------------------
178 success = remote->init("/dev/rawir");
181 logger->log("Core", Log::INFO, "Remote module initialised");
185 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
189 success = led->init(remote->getDevice());
192 logger->log("Core", Log::INFO, "LED module initialised");
196 logger->log("Core", Log::EMERG, "LED module failed to initialise");
200 success = mtd->init("/dev/mtd1");
203 logger->log("Core", Log::INFO, "Mtd module initialised");
207 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
211 success = timers->init();
214 logger->log("Core", Log::INFO, "Timers module initialised");
218 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
222 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
223 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
224 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
225 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
227 success = video->init(videoFormat);
230 logger->log("Core", Log::INFO, "Video module initialised");
234 logger->log("Core", Log::EMERG, "Video module failed to initialise");
238 success = osd->init("/dev/stbgfx");
241 logger->log("Core", Log::INFO, "OSD module initialised");
245 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
249 success = audio->init(Audio::MPEG2_PES);
252 logger->log("Core", Log::INFO, "Audio module initialised");
256 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
260 success = vdr->init(3024);
263 logger->log("Core", Log::INFO, "VDR module initialised");
267 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
271 success = viewman->init();
274 logger->log("Core", Log::INFO, "ViewMan module initialised");
278 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
282 success = command->init();
285 logger->log("Core", Log::INFO, "Command module initialised");
289 logger->log("Core", Log::EMERG, "Command module failed to initialise");
293 // Other init ------------------------------------------------------------------------------------------------------
295 logger->log("Core", Log::NOTICE, "Startup successful");
297 // Run main loop ---------------------------------------------------------------------------------------------------
299 // Ok, all major device components and other bits are loaded and ready
302 // When that returns quit ------------------------------------------------------------------------------------------
308 // -------------------------------------------------------------------------------------------------------------------
310 void shutdown(int code)
316 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
319 if (command) // shut down command here in case views have posted messages
323 logger->log("Core", Log::NOTICE, "Command module shut down");
330 logger->log("Core", Log::NOTICE, "VDR module shut down");
337 logger->log("Core", Log::NOTICE, "OSD module shut down");
344 logger->log("Core", Log::NOTICE, "Audio module shut down");
351 logger->log("Core", Log::NOTICE, "Video module shut down");
358 logger->log("Core", Log::NOTICE, "Timers module shut down");
365 logger->log("Core", Log::NOTICE, "MTD module shut down");
372 logger->log("Core", Log::NOTICE, "LED module shut down");
379 logger->log("Core", Log::NOTICE, "Remote module shut down");
384 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
392 // -------------------------------------------------------------------------------------------------------------------
394 void sighandler(int signalReceived)
396 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
398 switch (signalReceived)
402 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
403 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
408 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
409 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
420 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
421 logger->upLogLevel();
426 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
427 logger->downLogLevel();
433 logger->log("Core", Log::DEBUG, "SIGURG caught");
439 // -------------------------------------------------------------------------------------------------------------------
441 ULLONG ntohll(ULLONG a)
446 ULLONG htonll(ULLONG a)
448 #if BYTE_ORDER == BIG_ENDIAN
453 b = ((a << 56) & 0xFF00000000000000ULL)
454 | ((a << 40) & 0x00FF000000000000ULL)
455 | ((a << 24) & 0x0000FF0000000000ULL)
456 | ((a << 8) & 0x000000FF00000000ULL)
457 | ((a >> 8) & 0x00000000FF000000ULL)
458 | ((a >> 24) & 0x0000000000FF0000ULL)
459 | ((a >> 40) & 0x000000000000FF00ULL)
460 | ((a >> 56) & 0x00000000000000FFULL) ;
466 void MILLISLEEP(ULONG a)
469 struct timespec delayTime;
470 delayTime.tv_sec = a / 1000;
471 delayTime.tv_nsec = (a % 1000) * 1000000;
472 nanosleep(&delayTime, NULL);