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"
43 #include "remotemvp.h"
50 void sighandler(int signalReceived);
51 void shutdown(int code);
53 // Global variables --------------------------------------------------------------------------------------------------
67 int main(int argc, char** argv)
69 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
72 // Init global vars ------------------------------------------------------------------------------------------------
76 timers = new Timers();
79 remote = new RemoteWin();
82 audio = new AudioWin();
83 video = new VideoWin();
85 remote = new RemoteMVP();
88 audio = new AudioMVP();
89 video = new VideoMVP();
91 viewman = new ViewMan();
92 command = new Command();
94 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
96 printf("Could not create objects. Memory problems?\n");
100 // Get logging module started --------------------------------------------------------------------------------------
102 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
104 printf("Could not initialise log object. Aborting.\n");
108 logger->log("Core", Log::INFO, "Starting up...");
110 // Daemonize if not -d
115 pid_t forkTest = fork();
117 { printf("Cannot fork (1).\n"); exit(1); }
118 if (forkTest != 0) _exit(0); // PID returned, I am the parent
119 // otherwise, I am the child
123 { printf("Cannot fork (2).\n"); exit(1); }
124 if (forkTest != 0) _exit(0); // PID returned, I am the parent
125 // otherwise, I am the child
131 // Set up signal handling ------------------------------------------------------------------------------------------
133 sighandler_t sigtest;
135 sigtest = signal(SIGPIPE, SIG_IGN);
136 if (sigtest == SIG_ERR)
138 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
141 sigtest = signal(SIGINT, sighandler);
142 if (sigtest == SIG_ERR)
144 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
147 sigtest = signal(SIGTERM, sighandler);
148 if (sigtest == SIG_ERR)
150 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
153 sigtest = signal(SIGUSR1, sighandler);
154 if (sigtest == SIG_ERR)
156 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
160 sigtest = signal(SIGUSR2, sighandler);
161 if (sigtest == SIG_ERR)
163 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
167 sigtest = signal(SIGURG, sighandler);
168 if (sigtest == SIG_ERR)
170 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
174 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
177 // Init modules ----------------------------------------------------------------------------------------------------
180 success = remote->init("/dev/rawir");
183 logger->log("Core", Log::INFO, "Remote module initialised");
187 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
192 success = led->init();
194 success = led->init(((RemoteMVP*)remote)->getDevice());
198 logger->log("Core", Log::INFO, "LED module initialised");
202 logger->log("Core", Log::EMERG, "LED module failed to initialise");
206 success = mtd->init("/dev/mtd1");
209 logger->log("Core", Log::INFO, "Mtd module initialised");
213 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
217 success = timers->init();
220 logger->log("Core", Log::INFO, "Timers module initialised");
224 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
228 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
229 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
230 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
231 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
233 success = video->init(videoFormat);
236 logger->log("Core", Log::INFO, "Video module initialised");
240 logger->log("Core", Log::EMERG, "Video module failed to initialise");
244 success = osd->init("/dev/stbgfx");
247 logger->log("Core", Log::INFO, "OSD module initialised");
251 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
255 success = audio->init(Audio::MPEG2_PES);
258 logger->log("Core", Log::INFO, "Audio module initialised");
262 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
266 success = vdr->init(3024);
269 logger->log("Core", Log::INFO, "VDR module initialised");
273 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
277 success = viewman->init();
280 logger->log("Core", Log::INFO, "ViewMan module initialised");
284 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
288 success = command->init();
291 logger->log("Core", Log::INFO, "Command module initialised");
295 logger->log("Core", Log::EMERG, "Command module failed to initialise");
299 // Other init ------------------------------------------------------------------------------------------------------
301 logger->log("Core", Log::NOTICE, "Startup successful");
303 // Run main loop ---------------------------------------------------------------------------------------------------
305 // Ok, all major device components and other bits are loaded and ready
308 // When that returns quit ------------------------------------------------------------------------------------------
314 // -------------------------------------------------------------------------------------------------------------------
316 void shutdown(int code)
322 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
325 if (command) // shut down command here in case views have posted messages
329 logger->log("Core", Log::NOTICE, "Command module shut down");
336 logger->log("Core", Log::NOTICE, "VDR module shut down");
343 logger->log("Core", Log::NOTICE, "OSD module shut down");
350 logger->log("Core", Log::NOTICE, "Audio module shut down");
357 logger->log("Core", Log::NOTICE, "Video module shut down");
364 logger->log("Core", Log::NOTICE, "Timers module shut down");
371 logger->log("Core", Log::NOTICE, "MTD module shut down");
378 logger->log("Core", Log::NOTICE, "LED module shut down");
385 logger->log("Core", Log::NOTICE, "Remote module shut down");
390 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
398 // -------------------------------------------------------------------------------------------------------------------
400 void sighandler(int signalReceived)
402 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
404 switch (signalReceived)
408 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
409 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
414 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
415 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
426 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
427 logger->upLogLevel();
432 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
433 logger->downLogLevel();
439 logger->log("Core", Log::DEBUG, "SIGURG caught");
445 // -------------------------------------------------------------------------------------------------------------------
447 ULLONG ntohll(ULLONG a)
452 ULLONG htonll(ULLONG a)
454 #if BYTE_ORDER == BIG_ENDIAN
459 b = ((a << 56) & 0xFF00000000000000ULL)
460 | ((a << 40) & 0x00FF000000000000ULL)
461 | ((a << 24) & 0x0000FF0000000000ULL)
462 | ((a << 8) & 0x000000FF00000000ULL)
463 | ((a >> 8) & 0x00000000FF000000ULL)
464 | ((a >> 24) & 0x0000000000FF0000ULL)
465 | ((a >> 40) & 0x000000000000FF00ULL)
466 | ((a >> 56) & 0x00000000000000FFULL) ;
472 void MILLISLEEP(ULONG a)
475 struct timespec delayTime;
476 delayTime.tv_sec = a / 1000;
477 delayTime.tv_nsec = (a % 1000) * 1000000;
478 nanosleep(&delayTime, NULL);