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
37 #include "remotewin.h"
44 #include "remotemvp.h"
51 void sighandler(int signalReceived);
52 void shutdown(int code);
54 // Global variables --------------------------------------------------------------------------------------------------
68 int main(int argc, char** argv)
70 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
73 // Init global vars ------------------------------------------------------------------------------------------------
76 timers = new Timers();
80 remote = new RemoteWin();
83 audio = new AudioWin();
84 video = new VideoWin();
87 remote = new RemoteMVP();
90 audio = new AudioMVP();
91 video = new VideoMVP();
93 viewman = new ViewMan();
94 command = new Command();
96 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
98 printf("Could not create objects. Memory problems?\n");
102 // Get logging module started --------------------------------------------------------------------------------------
104 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
106 printf("Could not initialise log object. Aborting.\n");
110 logger->log("Core", Log::INFO, "Starting up...");
112 // Daemonize if not -d
117 pid_t forkTest = fork();
119 { printf("Cannot fork (1).\n"); exit(1); }
120 if (forkTest != 0) _exit(0); // PID returned, I am the parent
121 // otherwise, I am the child
125 { printf("Cannot fork (2).\n"); exit(1); }
126 if (forkTest != 0) _exit(0); // PID returned, I am the parent
127 // otherwise, I am the child
133 // Set up signal handling ------------------------------------------------------------------------------------------
135 sighandler_t sigtest;
137 sigtest = signal(SIGPIPE, SIG_IGN);
138 if (sigtest == SIG_ERR)
140 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
143 sigtest = signal(SIGINT, sighandler);
144 if (sigtest == SIG_ERR)
146 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
149 sigtest = signal(SIGTERM, sighandler);
150 if (sigtest == SIG_ERR)
152 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
155 sigtest = signal(SIGUSR1, sighandler);
156 if (sigtest == SIG_ERR)
158 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
162 sigtest = signal(SIGUSR2, sighandler);
163 if (sigtest == SIG_ERR)
165 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
169 sigtest = signal(SIGURG, sighandler);
170 if (sigtest == SIG_ERR)
172 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
176 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
179 // Init modules ----------------------------------------------------------------------------------------------------
182 success = remote->init("/dev/rawir");
185 logger->log("Core", Log::INFO, "Remote module initialised");
189 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
194 success = led->init();
196 success = led->init(((RemoteMVP*)remote)->getDevice());
200 logger->log("Core", Log::INFO, "LED module initialised");
204 logger->log("Core", Log::EMERG, "LED module failed to initialise");
208 success = mtd->init("/dev/mtd1");
211 logger->log("Core", Log::INFO, "Mtd module initialised");
215 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
219 success = timers->init();
222 logger->log("Core", Log::INFO, "Timers module initialised");
226 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
230 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
231 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
232 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
233 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
235 success = video->init(videoFormat);
238 logger->log("Core", Log::INFO, "Video module initialised");
242 logger->log("Core", Log::EMERG, "Video module failed to initialise");
246 success = osd->init("/dev/stbgfx");
249 logger->log("Core", Log::INFO, "OSD module initialised");
253 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
257 success = audio->init(Audio::MPEG2_PES);
260 logger->log("Core", Log::INFO, "Audio module initialised");
264 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
268 success = vdr->init(3024);
271 logger->log("Core", Log::INFO, "VDR module initialised");
275 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
279 success = viewman->init();
282 logger->log("Core", Log::INFO, "ViewMan module initialised");
286 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
290 success = command->init();
293 logger->log("Core", Log::INFO, "Command module initialised");
297 logger->log("Core", Log::EMERG, "Command module failed to initialise");
301 // Other init ------------------------------------------------------------------------------------------------------
303 logger->log("Core", Log::NOTICE, "Startup successful");
305 // Run main loop ---------------------------------------------------------------------------------------------------
307 // Ok, all major device components and other bits are loaded and ready
310 // When that returns quit ------------------------------------------------------------------------------------------
316 // -------------------------------------------------------------------------------------------------------------------
318 void shutdown(int code)
324 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
327 if (command) // shut down command here in case views have posted messages
331 logger->log("Core", Log::NOTICE, "Command module shut down");
338 logger->log("Core", Log::NOTICE, "VDR module shut down");
345 logger->log("Core", Log::NOTICE, "OSD module shut down");
352 logger->log("Core", Log::NOTICE, "Audio module shut down");
359 logger->log("Core", Log::NOTICE, "Video module shut down");
366 logger->log("Core", Log::NOTICE, "Timers module shut down");
373 logger->log("Core", Log::NOTICE, "MTD module shut down");
380 logger->log("Core", Log::NOTICE, "LED module shut down");
387 logger->log("Core", Log::NOTICE, "Remote module shut down");
392 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
400 // -------------------------------------------------------------------------------------------------------------------
402 void sighandler(int signalReceived)
404 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
406 switch (signalReceived)
410 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
411 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
416 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
417 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
428 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
429 logger->upLogLevel();
434 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
435 logger->downLogLevel();
441 logger->log("Core", Log::DEBUG, "SIGURG caught");
447 // -------------------------------------------------------------------------------------------------------------------
449 ULLONG ntohll(ULLONG a)
454 ULLONG htonll(ULLONG a)
456 #if BYTE_ORDER == BIG_ENDIAN
461 b = ((a << 56) & 0xFF00000000000000ULL)
462 | ((a << 40) & 0x00FF000000000000ULL)
463 | ((a << 24) & 0x0000FF0000000000ULL)
464 | ((a << 8) & 0x000000FF00000000ULL)
465 | ((a >> 8) & 0x00000000FF000000ULL)
466 | ((a >> 24) & 0x0000000000FF0000ULL)
467 | ((a >> 40) & 0x000000000000FF00ULL)
468 | ((a >> 56) & 0x00000000000000FFULL) ;
474 void MILLISLEEP(ULONG a)
477 struct timespec delayTime;
478 delayTime.tv_sec = a / 1000;
479 delayTime.tv_nsec = (a % 1000) * 1000000;
480 nanosleep(&delayTime, NULL);