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
44 void sighandler(int signal);
45 void shutdown(int code);
47 // Global variables --------------------------------------------------------------------------------------------------
60 int main(int argc, char** argv)
62 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
65 // Init global vars ------------------------------------------------------------------------------------------------
68 remote = new Remote();
75 viewman = new ViewMan();
76 command = new Command();
78 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
80 printf("Could not create objects. Memory problems?\n");
84 // Get logging module started --------------------------------------------------------------------------------------
86 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
88 printf("Could not initialise log object. Aborting.\n");
92 logger->log("Core", Log::INFO, "Starting up...");
94 // Set up signal handling ------------------------------------------------------------------------------------------
98 sigtest = signal(SIGPIPE, SIG_IGN);
99 if (sigtest == SIG_ERR)
101 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
104 sigtest = signal(SIGINT, sighandler);
105 if (sigtest == SIG_ERR)
107 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
110 sigtest = signal(SIGTERM, sighandler);
111 if (sigtest == SIG_ERR)
113 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
116 sigtest = signal(SIGUSR1, sighandler);
117 if (sigtest == SIG_ERR)
119 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
122 sigtest = signal(SIGUSR2, sighandler);
123 if (sigtest == SIG_ERR)
125 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
128 sigtest = signal(SIGURG, sighandler);
129 if (sigtest == SIG_ERR)
131 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
135 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
138 // Init modules ----------------------------------------------------------------------------------------------------
141 success = remote->init("/dev/rawir");
144 logger->log("Core", Log::INFO, "Remote module initialised");
148 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
152 success = led->init(remote->getDevice());
155 logger->log("Core", Log::INFO, "LED module initialised");
159 logger->log("Core", Log::EMERG, "LED module failed to initialise");
163 success = mtd->init("/dev/mtd1");
166 logger->log("Core", Log::INFO, "Mtd module initialised");
170 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
174 success = osd->init("/dev/stbgfx", SCREENHEIGHT, SCREENWIDTH, 1);
177 logger->log("Core", Log::INFO, "OSD module initialised");
181 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
185 success = vdr->init(3024);
188 logger->log("Core", Log::INFO, "VDR module initialised");
192 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
196 success = video->init(Video::PAL, Video::SCART, Video::ASPECT4X3, Video::NORMAL);
199 logger->log("Core", Log::INFO, "Video module initialised");
203 logger->log("Core", Log::EMERG, "Video module failed to initialise");
207 success = audio->init(Audio::MPEG2_PES);
210 logger->log("Core", Log::INFO, "Audio module initialised");
214 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
218 success = viewman->init();
221 logger->log("Core", Log::INFO, "ViewMan module initialised");
225 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
229 success = command->init();
232 logger->log("Core", Log::INFO, "Command module initialised");
236 logger->log("Core", Log::EMERG, "Command module failed to initialise");
240 // Other init ------------------------------------------------------------------------------------------------------
242 logger->log("Core", Log::NOTICE, "Startup successful");
244 // Run main loop ---------------------------------------------------------------------------------------------------
246 // Ok, all major device components and other bits are loaded and ready
249 // When that returns quit ------------------------------------------------------------------------------------------
255 // -------------------------------------------------------------------------------------------------------------------
257 void shutdown(int code)
263 logger->log("Core", Log::NOTICE, "Command module shut down");
270 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
277 logger->log("Core", Log::NOTICE, "Audio module shut down");
284 logger->log("Core", Log::NOTICE, "Video module shut down");
291 logger->log("Core", Log::NOTICE, "VDR module shut down");
298 logger->log("Core", Log::NOTICE, "OSD module shut down");
305 logger->log("Core", Log::NOTICE, "MTD module shut down");
312 logger->log("Core", Log::NOTICE, "LED module shut down");
319 logger->log("Core", Log::NOTICE, "Remote module shut down");
324 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
332 // -------------------------------------------------------------------------------------------------------------------
334 void sighandler(int signal)
336 Log* logger = Log::getInstance();
338 logger->log("Core", Log::NOTICE, "Signal %i received", signal);
344 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
345 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
350 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
351 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
356 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
357 logger->upLogLevel();
362 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
363 logger->downLogLevel();
368 logger->log("Core", Log::DEBUG, "SIGURG caught");
374 // -------------------------------------------------------------------------------------------------------------------
376 ULLONG ntohll(ULLONG a)
381 ULLONG htonll(ULLONG a)
383 #if BYTE_ORDER == BIG_ENDIAN
388 b = ((a << 56) & 0xFF00000000000000ULL)
389 | ((a << 40) & 0x00FF000000000000ULL)
390 | ((a << 24) & 0x0000FF0000000000ULL)
391 | ((a << 8) & 0x000000FF00000000ULL)
392 | ((a >> 8) & 0x00000000FF000000ULL)
393 | ((a >> 24) & 0x0000000000FF0000ULL)
394 | ((a >> 40) & 0x000000000000FF00ULL)
395 | ((a >> 56) & 0x00000000000000FFULL) ;