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
38 #include "remotemvp.h"
46 void sighandler(int signalReceived);
49 void shutdown(int code);
53 int ticonfig_main(int, char**);
56 // Global variables --------------------------------------------------------------------------------------------------
71 // Linux MVP main function and sighandler
73 int main(int argc, char** argv)
75 if (strstr(argv[0], "ticonfig")) return ticonfig_main(argc, argv);
77 if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
80 // Init global vars ------------------------------------------------------------------------------------------------
83 timers = new Timers();
86 remote = new RemoteMVP();
89 audio = new AudioMVP();
90 video = new VideoMVP();
91 boxstack = new BoxStack();
92 command = new Command();
95 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !boxstack || !command || !wol)
97 printf("Could not create objects. Memory problems?\n");
101 // Get logging module started --------------------------------------------------------------------------------------
103 if (!logger->init(Log::DEBUG, "dummy", debugEnabled))
105 printf("Could not initialise log object. Aborting.\n");
109 logger->log("Core", Log::INFO, "Starting up...");
111 // Daemonize if not -d
116 pid_t forkTest = fork();
118 { printf("Cannot fork (1).\n"); exit(1); }
119 if (forkTest != 0) _exit(0); // PID returned, I am the parent
120 // otherwise, I am the child
124 { printf("Cannot fork (2).\n"); exit(1); }
125 if (forkTest != 0) _exit(0); // PID returned, I am the parent
126 // otherwise, I am the child
132 // Set up signal handling ------------------------------------------------------------------------------------------
134 sighandler_t sigtest;
136 sigtest = signal(SIGPIPE, SIG_IGN);
137 if (sigtest == SIG_ERR)
139 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGPIPE. Aborting.");
142 sigtest = signal(SIGINT, sighandler);
143 if (sigtest == SIG_ERR)
145 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGINT. Aborting.");
148 sigtest = signal(SIGTERM, sighandler);
149 if (sigtest == SIG_ERR)
151 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGTERM. Aborting.");
154 sigtest = signal(SIGUSR1, sighandler);
155 if (sigtest == SIG_ERR)
157 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR1. Aborting.");
161 sigtest = signal(SIGUSR2, sighandler);
162 if (sigtest == SIG_ERR)
164 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGUSR2. Aborting.");
168 sigtest = signal(SIGURG, sighandler);
169 if (sigtest == SIG_ERR)
171 logger->log("Core", Log::EMERG, "Could not set up signal handler for SIGURG. Aborting.");
175 logger->log("Core", Log::INFO, "Signal handlers set up successfully");
178 // Init modules ----------------------------------------------------------------------------------------------------
181 success = remote->init("/dev/rawir");
184 logger->log("Core", Log::INFO, "Remote module initialised");
188 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
192 success = led->init(((RemoteMVP*)remote)->getDevice());
195 logger->log("Core", Log::INFO, "LED module initialised");
199 logger->log("Core", Log::EMERG, "LED module failed to initialise");
203 success = mtd->init();
206 logger->log("Core", Log::INFO, "Mtd module initialised");
210 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
214 success = timers->init();
217 logger->log("Core", Log::INFO, "Timers module initialised");
221 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
225 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
226 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
227 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
228 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
230 success = video->init(videoFormat);
233 logger->log("Core", Log::INFO, "Video module initialised");
237 logger->log("Core", Log::EMERG, "Video module failed to initialise");
241 success = osd->init((void*)("/dev/stbgfx"));
244 logger->log("Core", Log::INFO, "OSD module initialised");
248 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
252 success = audio->init(Audio::MPEG2_PES);
255 logger->log("Core", Log::INFO, "Audio module initialised");
259 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
263 success = vdr->init(3024);
266 logger->log("Core", Log::INFO, "VDR module initialised");
270 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
274 success = boxstack->init();
277 logger->log("Core", Log::INFO, "BoxStack module initialised");
281 logger->log("Core", Log::EMERG, "BoxStack module failed to initialise");
285 success = command->init();
288 logger->log("Core", Log::INFO, "Command module initialised");
292 logger->log("Core", Log::EMERG, "Command module failed to initialise");
296 // Other init ------------------------------------------------------------------------------------------------------
298 logger->log("Core", Log::NOTICE, "Startup successful");
300 // Run main loop ---------------------------------------------------------------------------------------------------
302 // Ok, all major device components and other bits are loaded and ready
305 // When that returns quit ------------------------------------------------------------------------------------------
311 // -------------------------------------------------------------------------------------------------------------------
313 void sighandler(int signalReceived)
315 logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
317 switch (signalReceived)
321 logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
322 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
327 logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
328 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
339 logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
340 logger->upLogLevel();
345 logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
346 logger->downLogLevel();
352 logger->log("Core", Log::DEBUG, "SIGURG caught");
359 // -------------------------------------------------------------------------------------------------------------------
361 void shutdown(int code)
365 boxstack->shutdown();
367 logger->log("Core", Log::NOTICE, "BoxStack module shut down");
370 // FIXME, send a del all to boxstack first, then get rid of it after command?
371 if (command) // shut down command here in case views have posted messages
375 logger->log("Core", Log::NOTICE, "Command module shut down");
382 logger->log("Core", Log::NOTICE, "VDR module shut down");
389 logger->log("Core", Log::NOTICE, "OSD module shut down");
396 logger->log("Core", Log::NOTICE, "Audio module shut down");
403 logger->log("Core", Log::NOTICE, "Video module shut down");
410 logger->log("Core", Log::NOTICE, "Timers module shut down");
417 logger->log("Core", Log::NOTICE, "MTD module shut down");
424 logger->log("Core", Log::NOTICE, "LED module shut down");
431 logger->log("Core", Log::NOTICE, "Remote module shut down");
437 logger->log("Core", Log::NOTICE, "WOL module shut down");
442 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
450 // -------------------------------------------------------------------------------------------------------------------
452 ULLONG ntohll(ULLONG a)
457 ULLONG htonll(ULLONG a)
459 #if BYTE_ORDER == BIG_ENDIAN
464 b = ((a << 56) & 0xFF00000000000000ULL)
465 | ((a << 40) & 0x00FF000000000000ULL)
466 | ((a << 24) & 0x0000FF0000000000ULL)
467 | ((a << 8) & 0x000000FF00000000ULL)
468 | ((a >> 8) & 0x00000000FF000000ULL)
469 | ((a >> 24) & 0x0000000000FF0000ULL)
470 | ((a >> 40) & 0x000000000000FF00ULL)
471 | ((a >> 56) & 0x00000000000000FFULL) ;
477 void MILLISLEEP(ULONG a)
480 struct timespec delayTime;
481 delayTime.tv_sec = a / 1000;
482 delayTime.tv_nsec = (a % 1000) * 1000000;
483 nanosleep(&delayTime, NULL);
489 int max(int a, int b)