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 // Set up signal handling ------------------------------------------------------------------------------------------
94 sigtest = signal(SIGPIPE, SIG_IGN);
95 if (sigtest == SIG_ERR)
97 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
100 sigtest = signal(SIGINT, sighandler);
101 if (sigtest == SIG_ERR)
103 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
106 sigtest = signal(SIGTERM, sighandler);
107 if (sigtest == SIG_ERR)
109 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
112 sigtest = signal(SIGUSR1, sighandler);
113 if (sigtest == SIG_ERR)
115 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
118 sigtest = signal(SIGUSR2, sighandler);
119 if (sigtest == SIG_ERR)
121 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
124 sigtest = signal(SIGURG, sighandler);
125 if (sigtest == SIG_ERR)
127 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
131 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
134 // Init modules ----------------------------------------------------------------------------------------------------
137 success = remote->init("/dev/rawir");
140 logger->log("Core", Log::INFO, "Remote module initialised");
144 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
148 success = led->init(remote->getDevice());
151 logger->log("Core", Log::INFO, "LED module initialised");
155 logger->log("Core", Log::EMERG, "LED module failed to initialise");
159 success = mtd->init("/dev/mtd1");
162 logger->log("Core", Log::INFO, "Mtd module initialised");
166 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
170 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
171 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
172 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
173 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
175 success = video->init(videoFormat);
178 logger->log("Core", Log::INFO, "Video module initialised");
182 logger->log("Core", Log::EMERG, "Video module failed to initialise");
186 success = osd->init("/dev/stbgfx", 1);
189 logger->log("Core", Log::INFO, "OSD module initialised");
193 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
197 success = audio->init(Audio::MPEG2_PES);
200 logger->log("Core", Log::INFO, "Audio module initialised");
204 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
208 success = vdr->init(3024);
211 logger->log("Core", Log::INFO, "VDR module initialised");
215 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
219 success = viewman->init();
222 logger->log("Core", Log::INFO, "ViewMan module initialised");
226 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
230 success = command->init();
233 logger->log("Core", Log::INFO, "Command module initialised");
237 logger->log("Core", Log::EMERG, "Command module failed to initialise");
241 // Other init ------------------------------------------------------------------------------------------------------
243 logger->log("Core", Log::NOTICE, "Startup successful");
245 // Run main loop ---------------------------------------------------------------------------------------------------
247 // Ok, all major device components and other bits are loaded and ready
250 // When that returns quit ------------------------------------------------------------------------------------------
256 // -------------------------------------------------------------------------------------------------------------------
258 void shutdown(int code)
264 logger->log("Core", Log::NOTICE, "Command module shut down");
271 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
278 logger->log("Core", Log::NOTICE, "VDR module shut down");
285 logger->log("Core", Log::NOTICE, "OSD module shut down");
292 logger->log("Core", Log::NOTICE, "Audio module shut down");
299 logger->log("Core", Log::NOTICE, "Video module shut down");
306 logger->log("Core", Log::NOTICE, "MTD module shut down");
313 logger->log("Core", Log::NOTICE, "LED module shut down");
320 logger->log("Core", Log::NOTICE, "Remote module shut down");
325 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
333 // -------------------------------------------------------------------------------------------------------------------
335 void sighandler(int signalReceived)
337 logger->log("Core", Log::NOTICE, "Signal %i received", signal);
339 switch (signalReceived)
343 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
344 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
349 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
350 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
355 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
356 logger->upLogLevel();
361 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
362 logger->downLogLevel();
367 logger->log("Core", Log::DEBUG, "SIGURG caught");
373 // -------------------------------------------------------------------------------------------------------------------
375 ULLONG ntohll(ULLONG a)
380 ULLONG htonll(ULLONG a)
382 #if BYTE_ORDER == BIG_ENDIAN
387 b = ((a << 56) & 0xFF00000000000000ULL)
388 | ((a << 40) & 0x00FF000000000000ULL)
389 | ((a << 24) & 0x0000FF0000000000ULL)
390 | ((a << 8) & 0x000000FF00000000ULL)
391 | ((a >> 8) & 0x00000000FF000000ULL)
392 | ((a >> 24) & 0x0000000000FF0000ULL)
393 | ((a >> 40) & 0x000000000000FF00ULL)
394 | ((a >> 56) & 0x00000000000000FFULL) ;