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
40 void sighandler(int signalReceived);
41 void shutdown(int code);
43 // Global variables --------------------------------------------------------------------------------------------------
56 int main(int argc, char** argv)
58 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
61 // Init global vars ------------------------------------------------------------------------------------------------
64 remote = new Remote();
71 viewman = new ViewMan();
72 command = new Command();
74 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
76 printf("Could not create objects. Memory problems?\n");
80 // Get logging module started --------------------------------------------------------------------------------------
82 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
84 printf("Could not initialise log object. Aborting.\n");
88 logger->log("Core", Log::INFO, "Starting up...");
90 // Daemonize if not -d
95 pid_t forkTest = fork();
97 { printf("Cannot fork (1).\n"); exit(1); }
98 if (forkTest != 0) _exit(0); // PID returned, I am the parent
99 // otherwise, I am the child
103 { printf("Cannot fork (2).\n"); exit(1); }
104 if (forkTest != 0) _exit(0); // PID returned, I am the parent
105 // otherwise, I am the child
111 // Set up signal handling ------------------------------------------------------------------------------------------
113 sighandler_t sigtest;
115 sigtest = signal(SIGPIPE, SIG_IGN);
116 if (sigtest == SIG_ERR)
118 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
121 sigtest = signal(SIGINT, sighandler);
122 if (sigtest == SIG_ERR)
124 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
127 sigtest = signal(SIGTERM, sighandler);
128 if (sigtest == SIG_ERR)
130 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
133 sigtest = signal(SIGUSR1, sighandler);
134 if (sigtest == SIG_ERR)
136 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
139 sigtest = signal(SIGUSR2, sighandler);
140 if (sigtest == SIG_ERR)
142 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
145 sigtest = signal(SIGURG, sighandler);
146 if (sigtest == SIG_ERR)
148 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
152 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
155 // Init modules ----------------------------------------------------------------------------------------------------
158 success = remote->init("/dev/rawir");
161 logger->log("Core", Log::INFO, "Remote module initialised");
165 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
169 success = led->init(remote->getDevice());
172 logger->log("Core", Log::INFO, "LED module initialised");
176 logger->log("Core", Log::EMERG, "LED module failed to initialise");
180 success = mtd->init("/dev/mtd1");
183 logger->log("Core", Log::INFO, "Mtd module initialised");
187 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
191 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
192 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
193 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
194 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
196 //videoFormat = Video::NTSC; // enable this line to test NTSC in PAL land
198 success = video->init(videoFormat);
201 logger->log("Core", Log::INFO, "Video module initialised");
205 logger->log("Core", Log::EMERG, "Video module failed to initialise");
209 success = osd->init("/dev/stbgfx", 1);
212 logger->log("Core", Log::INFO, "OSD module initialised");
216 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
220 success = audio->init(Audio::MPEG2_PES);
223 logger->log("Core", Log::INFO, "Audio module initialised");
227 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
231 success = vdr->init(3024);
234 logger->log("Core", Log::INFO, "VDR module initialised");
238 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
242 success = viewman->init();
245 logger->log("Core", Log::INFO, "ViewMan module initialised");
249 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
253 success = command->init();
256 logger->log("Core", Log::INFO, "Command module initialised");
260 logger->log("Core", Log::EMERG, "Command module failed to initialise");
264 // Other init ------------------------------------------------------------------------------------------------------
266 logger->log("Core", Log::NOTICE, "Startup successful");
268 // Run main loop ---------------------------------------------------------------------------------------------------
270 // Ok, all major device components and other bits are loaded and ready
273 // When that returns quit ------------------------------------------------------------------------------------------
279 // -------------------------------------------------------------------------------------------------------------------
281 void shutdown(int code)
287 logger->log("Core", Log::NOTICE, "Command module shut down");
294 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
301 logger->log("Core", Log::NOTICE, "VDR module shut down");
308 logger->log("Core", Log::NOTICE, "OSD module shut down");
315 logger->log("Core", Log::NOTICE, "Audio module shut down");
322 logger->log("Core", Log::NOTICE, "Video module shut down");
329 logger->log("Core", Log::NOTICE, "MTD module shut down");
336 logger->log("Core", Log::NOTICE, "LED module shut down");
343 logger->log("Core", Log::NOTICE, "Remote module shut down");
348 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
356 // -------------------------------------------------------------------------------------------------------------------
358 void sighandler(int signalReceived)
360 logger->log("Core", Log::NOTICE, "Signal %i received", signal);
362 switch (signalReceived)
366 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
367 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
372 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
373 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
378 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
379 logger->upLogLevel();
384 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
385 logger->downLogLevel();
390 logger->log("Core", Log::DEBUG, "SIGURG caught");
396 // -------------------------------------------------------------------------------------------------------------------
398 ULLONG ntohll(ULLONG a)
403 ULLONG htonll(ULLONG a)
405 #if BYTE_ORDER == BIG_ENDIAN
410 b = ((a << 56) & 0xFF00000000000000ULL)
411 | ((a << 40) & 0x00FF000000000000ULL)
412 | ((a << 24) & 0x0000FF0000000000ULL)
413 | ((a << 8) & 0x000000FF00000000ULL)
414 | ((a >> 8) & 0x00000000FF000000ULL)
415 | ((a >> 24) & 0x0000000000FF0000ULL)
416 | ((a >> 40) & 0x000000000000FF00ULL)
417 | ((a >> 56) & 0x00000000000000FFULL) ;