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
39 #include "remotewin.h"
46 #include "remotemvp.h"
53 void sighandler(int signalReceived);
54 void shutdown(int code);
56 // Global variables --------------------------------------------------------------------------------------------------
70 int main(int argc, char** argv)
72 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
75 // Init global vars ------------------------------------------------------------------------------------------------
78 timers = new Timers();
82 remote = new RemoteWin();
85 audio = new AudioWin();
86 video = new VideoWin();
89 remote = new RemoteMVP();
92 audio = new AudioMVP();
93 video = new VideoMVP();
95 viewman = new ViewMan();
96 command = new Command();
98 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
100 printf("Could not create objects. Memory problems?\n");
104 // Get logging module started --------------------------------------------------------------------------------------
106 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
108 printf("Could not initialise log object. Aborting.\n");
112 logger->log("Core", Log::INFO, "Starting up...");
114 // Daemonize if not -d
119 pid_t forkTest = fork();
121 { printf("Cannot fork (1).\n"); exit(1); }
122 if (forkTest != 0) _exit(0); // PID returned, I am the parent
123 // otherwise, I am the child
127 { printf("Cannot fork (2).\n"); exit(1); }
128 if (forkTest != 0) _exit(0); // PID returned, I am the parent
129 // otherwise, I am the child
135 // Set up signal handling ------------------------------------------------------------------------------------------
137 sighandler_t sigtest;
139 sigtest = signal(SIGPIPE, SIG_IGN);
140 if (sigtest == SIG_ERR)
142 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
145 sigtest = signal(SIGINT, sighandler);
146 if (sigtest == SIG_ERR)
148 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
151 sigtest = signal(SIGTERM, sighandler);
152 if (sigtest == SIG_ERR)
154 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
157 sigtest = signal(SIGUSR1, sighandler);
158 if (sigtest == SIG_ERR)
160 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
164 sigtest = signal(SIGUSR2, sighandler);
165 if (sigtest == SIG_ERR)
167 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
171 sigtest = signal(SIGURG, sighandler);
172 if (sigtest == SIG_ERR)
174 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
178 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
181 // Init modules ----------------------------------------------------------------------------------------------------
184 success = remote->init("/dev/rawir");
187 logger->log("Core", Log::INFO, "Remote module initialised");
191 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
196 success = led->init();
198 success = led->init(((RemoteMVP*)remote)->getDevice());
202 logger->log("Core", Log::INFO, "LED module initialised");
206 logger->log("Core", Log::EMERG, "LED module failed to initialise");
210 success = mtd->init("/dev/mtd1");
213 logger->log("Core", Log::INFO, "Mtd module initialised");
217 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
221 success = timers->init();
224 logger->log("Core", Log::INFO, "Timers module initialised");
228 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
232 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
233 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
234 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
235 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
237 success = video->init(videoFormat);
240 logger->log("Core", Log::INFO, "Video module initialised");
244 logger->log("Core", Log::EMERG, "Video module failed to initialise");
248 success = osd->init("/dev/stbgfx");
251 logger->log("Core", Log::INFO, "OSD module initialised");
255 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
259 success = audio->init(Audio::MPEG2_PES);
262 logger->log("Core", Log::INFO, "Audio module initialised");
266 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
270 success = vdr->init(3024);
273 logger->log("Core", Log::INFO, "VDR module initialised");
277 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
281 success = viewman->init();
284 logger->log("Core", Log::INFO, "ViewMan module initialised");
288 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
292 success = command->init();
295 logger->log("Core", Log::INFO, "Command module initialised");
299 logger->log("Core", Log::EMERG, "Command module failed to initialise");
303 // Other init ------------------------------------------------------------------------------------------------------
305 logger->log("Core", Log::NOTICE, "Startup successful");
307 // Run main loop ---------------------------------------------------------------------------------------------------
309 // Ok, all major device components and other bits are loaded and ready
312 // When that returns quit ------------------------------------------------------------------------------------------
318 // -------------------------------------------------------------------------------------------------------------------
320 void shutdown(int code)
326 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
329 if (command) // shut down command here in case views have posted messages
333 logger->log("Core", Log::NOTICE, "Command module shut down");
340 logger->log("Core", Log::NOTICE, "VDR module shut down");
347 logger->log("Core", Log::NOTICE, "OSD module shut down");
354 logger->log("Core", Log::NOTICE, "Audio module shut down");
361 logger->log("Core", Log::NOTICE, "Video module shut down");
368 logger->log("Core", Log::NOTICE, "Timers module shut down");
375 logger->log("Core", Log::NOTICE, "MTD module shut down");
382 logger->log("Core", Log::NOTICE, "LED module shut down");
389 logger->log("Core", Log::NOTICE, "Remote module shut down");
394 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
402 // -------------------------------------------------------------------------------------------------------------------
404 void sighandler(int signalReceived)
406 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
408 switch (signalReceived)
412 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
413 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
418 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
419 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
430 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
431 logger->upLogLevel();
436 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
437 logger->downLogLevel();
443 logger->log("Core", Log::DEBUG, "SIGURG caught");
449 // -------------------------------------------------------------------------------------------------------------------
451 ULLONG ntohll(ULLONG a)
456 ULLONG htonll(ULLONG a)
458 #if BYTE_ORDER == BIG_ENDIAN
463 b = ((a << 56) & 0xFF00000000000000ULL)
464 | ((a << 40) & 0x00FF000000000000ULL)
465 | ((a << 24) & 0x0000FF0000000000ULL)
466 | ((a << 8) & 0x000000FF00000000ULL)
467 | ((a >> 8) & 0x00000000FF000000ULL)
468 | ((a >> 24) & 0x0000000000FF0000ULL)
469 | ((a >> 40) & 0x000000000000FF00ULL)
470 | ((a >> 56) & 0x00000000000000FFULL) ;
476 void MILLISLEEP(ULONG a)
479 struct timespec delayTime;
480 delayTime.tv_sec = a / 1000;
481 delayTime.tv_nsec = (a % 1000) * 1000000;
482 nanosleep(&delayTime, NULL);