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
38 #include "remotemvp.h"
45 void sighandler(int signalReceived);
48 void shutdown(int code);
50 // Global variables --------------------------------------------------------------------------------------------------
64 // Linux MVP main function and sighandler
66 int main(int argc, char** argv)
68 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
71 // Init global vars ------------------------------------------------------------------------------------------------
74 timers = new Timers();
77 remote = new RemoteMVP();
80 audio = new AudioMVP();
81 video = new VideoMVP();
82 viewman = new ViewMan();
83 command = new Command();
85 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
87 printf("Could not create objects. Memory problems?\n");
91 // Get logging module started --------------------------------------------------------------------------------------
93 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
95 printf("Could not initialise log object. Aborting.\n");
99 logger->log("Core", Log::INFO, "Starting up...");
101 // Daemonize if not -d
106 pid_t forkTest = fork();
108 { printf("Cannot fork (1).\n"); exit(1); }
109 if (forkTest != 0) _exit(0); // PID returned, I am the parent
110 // otherwise, I am the child
114 { printf("Cannot fork (2).\n"); exit(1); }
115 if (forkTest != 0) _exit(0); // PID returned, I am the parent
116 // otherwise, I am the child
122 // Set up signal handling ------------------------------------------------------------------------------------------
124 sighandler_t sigtest;
126 sigtest = signal(SIGPIPE, SIG_IGN);
127 if (sigtest == SIG_ERR)
129 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
132 sigtest = signal(SIGINT, sighandler);
133 if (sigtest == SIG_ERR)
135 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
138 sigtest = signal(SIGTERM, sighandler);
139 if (sigtest == SIG_ERR)
141 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
144 sigtest = signal(SIGUSR1, sighandler);
145 if (sigtest == SIG_ERR)
147 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
151 sigtest = signal(SIGUSR2, sighandler);
152 if (sigtest == SIG_ERR)
154 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
158 sigtest = signal(SIGURG, sighandler);
159 if (sigtest == SIG_ERR)
161 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
165 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
168 // Init modules ----------------------------------------------------------------------------------------------------
171 success = remote->init("/dev/rawir");
174 logger->log("Core", Log::INFO, "Remote module initialised");
178 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
182 success = led->init(((RemoteMVP*)remote)->getDevice());
185 logger->log("Core", Log::INFO, "LED module initialised");
189 logger->log("Core", Log::EMERG, "LED module failed to initialise");
193 success = mtd->init("/dev/mtd1");
196 logger->log("Core", Log::INFO, "Mtd module initialised");
200 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
204 success = timers->init();
207 logger->log("Core", Log::INFO, "Timers module initialised");
211 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
215 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
216 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
217 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
218 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
220 success = video->init(videoFormat);
223 logger->log("Core", Log::INFO, "Video module initialised");
227 logger->log("Core", Log::EMERG, "Video module failed to initialise");
231 success = osd->init((void*)("/dev/stbgfx"));
234 logger->log("Core", Log::INFO, "OSD module initialised");
238 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
242 success = audio->init(Audio::MPEG2_PES);
245 logger->log("Core", Log::INFO, "Audio module initialised");
249 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
253 success = vdr->init(3024);
256 logger->log("Core", Log::INFO, "VDR module initialised");
260 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
264 success = viewman->init();
267 logger->log("Core", Log::INFO, "ViewMan module initialised");
271 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
275 success = command->init();
278 logger->log("Core", Log::INFO, "Command module initialised");
282 logger->log("Core", Log::EMERG, "Command module failed to initialise");
286 // Other init ------------------------------------------------------------------------------------------------------
288 logger->log("Core", Log::NOTICE, "Startup successful");
290 // Run main loop ---------------------------------------------------------------------------------------------------
292 // Ok, all major device components and other bits are loaded and ready
295 // When that returns quit ------------------------------------------------------------------------------------------
301 // -------------------------------------------------------------------------------------------------------------------
303 void sighandler(int signalReceived)
305 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
307 switch (signalReceived)
311 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
312 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
317 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
318 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
329 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
330 logger->upLogLevel();
335 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
336 logger->downLogLevel();
342 logger->log("Core", Log::DEBUG, "SIGURG caught");
349 // -------------------------------------------------------------------------------------------------------------------
351 void shutdown(int code)
357 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
360 if (command) // shut down command here in case views have posted messages
364 logger->log("Core", Log::NOTICE, "Command module shut down");
371 logger->log("Core", Log::NOTICE, "VDR module shut down");
378 logger->log("Core", Log::NOTICE, "OSD module shut down");
385 logger->log("Core", Log::NOTICE, "Audio module shut down");
392 logger->log("Core", Log::NOTICE, "Video module shut down");
399 logger->log("Core", Log::NOTICE, "Timers module shut down");
406 logger->log("Core", Log::NOTICE, "MTD module shut down");
413 logger->log("Core", Log::NOTICE, "LED module shut down");
420 logger->log("Core", Log::NOTICE, "Remote module shut down");
425 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
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) ;
460 void MILLISLEEP(ULONG a)
463 struct timespec delayTime;
464 delayTime.tv_sec = a / 1000;
465 delayTime.tv_nsec = (a % 1000) * 1000000;
466 nanosleep(&delayTime, NULL);