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 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
175 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
176 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
177 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
179 success = video->init(videoFormat);
182 logger->log("Core", Log::INFO, "Video module initialised");
186 logger->log("Core", Log::EMERG, "Video module failed to initialise");
190 success = osd->init("/dev/stbgfx", 1);
193 logger->log("Core", Log::INFO, "OSD module initialised");
197 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
201 success = audio->init(Audio::MPEG2_PES);
204 logger->log("Core", Log::INFO, "Audio module initialised");
208 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
212 success = vdr->init(3024);
215 logger->log("Core", Log::INFO, "VDR module initialised");
219 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
223 success = viewman->init();
226 logger->log("Core", Log::INFO, "ViewMan module initialised");
230 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
234 success = command->init();
237 logger->log("Core", Log::INFO, "Command module initialised");
241 logger->log("Core", Log::EMERG, "Command module failed to initialise");
245 // Other init ------------------------------------------------------------------------------------------------------
247 logger->log("Core", Log::NOTICE, "Startup successful");
249 // Run main loop ---------------------------------------------------------------------------------------------------
251 // Ok, all major device components and other bits are loaded and ready
254 // When that returns quit ------------------------------------------------------------------------------------------
260 // -------------------------------------------------------------------------------------------------------------------
262 void shutdown(int code)
268 logger->log("Core", Log::NOTICE, "Command module shut down");
273 printf("here st 3\n");
277 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
284 logger->log("Core", Log::NOTICE, "VDR module shut down");
291 logger->log("Core", Log::NOTICE, "OSD module shut down");
298 logger->log("Core", Log::NOTICE, "Audio module shut down");
305 logger->log("Core", Log::NOTICE, "Video module shut down");
312 logger->log("Core", Log::NOTICE, "MTD module shut down");
319 logger->log("Core", Log::NOTICE, "LED module shut down");
326 logger->log("Core", Log::NOTICE, "Remote module shut down");
331 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
339 // -------------------------------------------------------------------------------------------------------------------
341 void sighandler(int signal)
343 Log* logger = Log::getInstance();
345 logger->log("Core", Log::NOTICE, "Signal %i received", signal);
351 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
352 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
357 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
358 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
363 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
364 logger->upLogLevel();
369 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
370 logger->downLogLevel();
375 logger->log("Core", Log::DEBUG, "SIGURG caught");
381 // -------------------------------------------------------------------------------------------------------------------
383 ULLONG ntohll(ULLONG a)
388 ULLONG htonll(ULLONG a)
390 #if BYTE_ORDER == BIG_ENDIAN
395 b = ((a << 56) & 0xFF00000000000000ULL)
396 | ((a << 40) & 0x00FF000000000000ULL)
397 | ((a << 24) & 0x0000FF0000000000ULL)
398 | ((a << 8) & 0x000000FF00000000ULL)
399 | ((a >> 8) & 0x00000000FF000000ULL)
400 | ((a >> 24) & 0x0000000000FF0000ULL)
401 | ((a >> 40) & 0x000000000000FF00ULL)
402 | ((a >> 56) & 0x00000000000000FFULL) ;