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 --------------------------------------------------------------------------------------------------
63 int main(int argc, char** argv)
65 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
68 // Init global vars ------------------------------------------------------------------------------------------------
71 remote = new Remote();
78 viewman = new ViewMan();
79 command = new Command();
81 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
83 printf("Could not create objects. Memory problems?\n");
87 // Get logging module started --------------------------------------------------------------------------------------
89 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
91 printf("Could not initialise log object. Aborting.\n");
95 logger->log("Core", Log::INFO, "Starting up...");
97 // Set up signal handling ------------------------------------------------------------------------------------------
101 sigtest = signal(SIGPIPE, SIG_IGN);
102 if (sigtest == SIG_ERR)
104 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
107 sigtest = signal(SIGINT, sighandler);
108 if (sigtest == SIG_ERR)
110 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
113 sigtest = signal(SIGTERM, sighandler);
114 if (sigtest == SIG_ERR)
116 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
119 sigtest = signal(SIGUSR1, sighandler);
120 if (sigtest == SIG_ERR)
122 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
125 sigtest = signal(SIGUSR2, sighandler);
126 if (sigtest == SIG_ERR)
128 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
131 sigtest = signal(SIGURG, sighandler);
132 if (sigtest == SIG_ERR)
134 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
138 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
141 // Init modules ----------------------------------------------------------------------------------------------------
144 success = remote->init("/dev/rawir");
147 logger->log("Core", Log::INFO, "Remote module initialised");
151 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
155 success = led->init(remote->getDevice());
158 logger->log("Core", Log::INFO, "LED module initialised");
162 logger->log("Core", Log::EMERG, "LED module failed to initialise");
166 success = mtd->init("/dev/mtd1");
169 logger->log("Core", Log::INFO, "Mtd module initialised");
173 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
177 // Need to init SCREENWIDTH, SCREENHEIGHT and ready the pal/ntsc connection stuff immediately
178 UCHAR videoFormat = 0;
179 UCHAR videoConnection = 0;
181 short mtdVideoMode = mtd->getVideoMode();
182 if (mtdVideoMode == 0)
186 videoFormat = Video::NTSC;
187 videoConnection = Video::COMPOSITE;
188 logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480 composite");
190 else if (mtdVideoMode == 1)
194 videoFormat = Video::PAL;
195 videoConnection = Video::SCART;
196 logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576 RGB");
198 else if (mtdVideoMode == 2)
202 videoFormat = Video::PAL;
203 videoConnection = Video::COMPOSITE;
204 logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576 composite");
212 videoFormat = Video::NTSC;
213 videoConnection = Video::COMPOSITE;
214 logger->log("Core", Log::INFO, "MTD gave us no help. Guessing NTSC.");
218 success = osd->init("/dev/stbgfx", SCREENHEIGHT, SCREENWIDTH, 1);
221 logger->log("Core", Log::INFO, "OSD module initialised");
225 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
229 success = vdr->init(3024);
232 logger->log("Core", Log::INFO, "VDR module initialised");
236 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
240 success = video->init(videoFormat, videoConnection, Video::ASPECT4X3, Video::NORMAL);
243 logger->log("Core", Log::INFO, "Video module initialised");
247 logger->log("Core", Log::EMERG, "Video module failed to initialise");
251 success = audio->init(Audio::MPEG2_PES);
254 logger->log("Core", Log::INFO, "Audio module initialised");
258 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
262 success = viewman->init();
265 logger->log("Core", Log::INFO, "ViewMan module initialised");
269 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
273 success = command->init();
276 logger->log("Core", Log::INFO, "Command module initialised");
280 logger->log("Core", Log::EMERG, "Command module failed to initialise");
284 // Other init ------------------------------------------------------------------------------------------------------
286 logger->log("Core", Log::NOTICE, "Startup successful");
288 // Run main loop ---------------------------------------------------------------------------------------------------
290 // Ok, all major device components and other bits are loaded and ready
293 // When that returns quit ------------------------------------------------------------------------------------------
299 // -------------------------------------------------------------------------------------------------------------------
301 void shutdown(int code)
307 logger->log("Core", Log::NOTICE, "Command module shut down");
314 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
321 logger->log("Core", Log::NOTICE, "Audio module shut down");
328 logger->log("Core", Log::NOTICE, "Video module shut down");
335 logger->log("Core", Log::NOTICE, "VDR module shut down");
342 logger->log("Core", Log::NOTICE, "OSD module shut down");
349 logger->log("Core", Log::NOTICE, "MTD module shut down");
356 logger->log("Core", Log::NOTICE, "LED module shut down");
363 logger->log("Core", Log::NOTICE, "Remote module shut down");
368 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
376 // -------------------------------------------------------------------------------------------------------------------
378 void sighandler(int signal)
380 Log* logger = Log::getInstance();
382 logger->log("Core", Log::NOTICE, "Signal %i received", signal);
388 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
389 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
394 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
395 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
400 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
401 logger->upLogLevel();
406 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
407 logger->downLogLevel();
412 logger->log("Core", Log::DEBUG, "SIGURG caught");
418 // -------------------------------------------------------------------------------------------------------------------
420 ULLONG ntohll(ULLONG a)
425 ULLONG htonll(ULLONG a)
427 #if BYTE_ORDER == BIG_ENDIAN
432 b = ((a << 56) & 0xFF00000000000000ULL)
433 | ((a << 40) & 0x00FF000000000000ULL)
434 | ((a << 24) & 0x0000FF0000000000ULL)
435 | ((a << 8) & 0x000000FF00000000ULL)
436 | ((a >> 8) & 0x00000000FF000000ULL)
437 | ((a >> 24) & 0x0000000000FF0000ULL)
438 | ((a >> 40) & 0x000000000000FF00ULL)
439 | ((a >> 56) & 0x00000000000000FFULL) ;