00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <cstring>
00034 extern "C" {
00035 #include <libxml/parser.h>
00036 }
00037 #include "mmscore/mmsinit.h"
00038 #include "mms.h"
00039
00040 #ifdef __ENABLE_ACTMON__
00041 #include "mmscore/mmsperf.h"
00042 #include "mmscore/mmsperfinterface.h"
00043
00044 static MMSPerf *mmsperf = NULL;
00045 #endif
00046
00047 static MMSPluginManager *pluginmanager = NULL;
00048 static MMSEventDispatcher *eventdispatcher = NULL;
00049 static MMSEventSignupManager *eventsignupmanager = NULL;
00050 static MMSConfigData *config = NULL;
00051 static MMSEvent *masterevent = NULL;
00052 static MMSEventSignup *mastereventsignup = NULL;
00053
00054 static MMSInputManager *inputs = NULL;
00055 static MMSThemeManager *themeManager = NULL;
00056 static MMSWindowManager *windowmanager = NULL;
00057
00058 void (*pluginRegisterCallback)(MMSPluginManager*) = NULL;
00059
00060 static void on_exit() {
00061 if(pluginmanager) delete pluginmanager;
00062
00063
00064 xmlCleanupParser();
00065 }
00066
00067
00068 bool mmsInit(MMSINIT_FLAGS flags, int argc, char *argv[], string configfile,
00069 string appl_name, string appl_icon_name,
00070 MMSConfigDataGlobal *global, MMSConfigDataDB *configdb, MMSConfigDataDB *datadb,
00071 MMSConfigDataGraphics *graphics, MMSConfigDataLanguage *language) {
00072
00073 try {
00074
00075 int args_pos;
00076 string args;
00077 if ((args_pos = (int)configfile.find("--disko:")) >= 0) {
00078 args = configfile.substr(args_pos);
00079 if (args_pos > 1)
00080 configfile = configfile.substr(0, args_pos-1);
00081 else
00082 configfile = "";
00083 }
00084
00085
00086 for (int i = 1; i < argc; i++) {
00087 if (memcmp(argv[i], "--disko:config=", 15)==0) {
00088
00089 configfile = &(argv[i][15]);
00090 }
00091 }
00092
00093
00094 xmlInitParser();
00095
00096 MMSRcParser rcparser;
00097 MMSConfigDataGlobal *rcGlobal = NULL;
00098 MMSConfigDataDB *rcConfigDB = NULL;
00099 MMSConfigDataDB *rcDataDB = NULL;
00100 MMSConfigDataGraphics *rcGraphics = NULL;
00101 MMSConfigDataLanguage *rcLanguage = NULL;
00102
00103 bool config_avail = false;
00104
00105 if(!configfile.empty()) {
00106
00107 DEBUGOUT("set configfile: %s\n", configfile.c_str());
00108 try {
00109 rcparser.parseFile(configfile);
00110 rcparser.getMMSRc(&rcGlobal, &rcConfigDB, &rcDataDB, &rcGraphics, &rcLanguage);
00111 config_avail = true;
00112 } catch (MMSRcParserError &ex) {
00113
00114 DEBUGMSG_OUTSTR("Core", "could not read config, try --disko:config=./etc/diskorc.xml");
00115 }
00116 } else {
00117
00118 try {
00119 rcparser.parseFile("./etc/diskorc.xml");
00120 rcparser.getMMSRc(&rcGlobal, &rcConfigDB, &rcDataDB, &rcGraphics, &rcLanguage);
00121 config_avail = true;
00122 } catch (MMSRcParserError &ex) {
00123
00124 try {
00125 rcparser.parseFile("/etc/diskorc.xml");
00126 rcparser.getMMSRc(&rcGlobal, &rcConfigDB, &rcDataDB, &rcGraphics, &rcLanguage);
00127 } catch (MMSRcParserError &ex) {
00128
00129 DEBUGMSG_OUTSTR("Core", "could not read config, try --disko:config=./etc/diskorc.xml");
00130 }
00131 }
00132 }
00133
00134 if (!config_avail) {
00135
00136 return false;
00137 }
00138
00139
00140 if (!rcGlobal) {
00141
00142 MMSRcParser rcparser;
00143 rcparser.getMMSRc(&rcGlobal, &rcConfigDB, &rcDataDB, &rcGraphics, &rcLanguage);
00144 config = new MMSConfigData((global)?*global:*rcGlobal, (configdb)?*configdb:*rcConfigDB, (datadb)?*datadb:*rcDataDB,
00145 (graphics)?*graphics:*rcGraphics, (language)?*language:*rcLanguage);
00146 } else {
00147 config = new MMSConfigData(*rcGlobal, *rcConfigDB, *rcDataDB, *rcGraphics, *rcLanguage);
00148 }
00149
00150
00151 rcparser.updateConfig(config, args, argc, argv);
00152
00153 if(!(flags & MMSINIT_SILENT)) {
00154 printf("\n");
00155 printf("**** * *** * * ***\n");
00156 printf(" * * * * * * * *\n");
00157 printf(" * * * *** ** * *\n");
00158 printf(" * * * * * * * *\n");
00159 printf("**** * *** * * *** V%s\n",DISKO_VERSION_STR);
00160 printf("----------------------------------------------------------------------\n");
00161 printf("The Linux application framework for embedded devices.\n");
00162 printf("\n");
00163 printf(" Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,\n");
00164 printf(" Matthias Hardt, Guido Madaus\n");
00165 printf(" Copyright (C) 2007-2008 BerLinux Solutions GbR\n");
00166 printf(" Stefan Schwarzer & Guido Madaus\n");
00167 printf(" Copyright (C) 2009-2013 BerLinux Solutions GmbH\n");
00168 printf("----------------------------------------------------------------------\n");
00169
00170 int pcv = 1;
00171 if (*((char *)&pcv) == 1) {
00172 DEBUGMSG_OUTSTR("Core", "Platform type................: little-endian");
00173 } else {
00174 DEBUGMSG_OUTSTR("Core", "Platform type................: big-endian");
00175 }
00176
00177 MMSConfigDataLayer videolayer = config->getVideoLayer();
00178 MMSConfigDataLayer graphicslayer = config->getGraphicsLayer();
00179
00180 DEBUGMSG_OUTSTR("Core", "ConfigDB.....................: " + config->getConfigDBDatabase() + " (" + config->getConfigDBAddress() + ")");
00181 DEBUGMSG_OUTSTR("Core", "DataDB.......................: " + config->getDataDBDatabase() + " (" + config->getDataDBAddress() + ")");
00182 DEBUGMSG_OUTSTR("Core", "Logfile......................: " + config->getLogfile());
00183 DEBUGMSG_OUTSTR("Core", "First plugin.................: " + config->getFirstPlugin());
00184 DEBUGMSG_OUTSTR("Core", "Input map....................: " + config->getInputMap());
00185 DEBUGMSG_OUTSTR("Core", "Prefix.......................: " + config->getPrefix());
00186 DEBUGMSG_OUTSTR("Core", "Theme........................: " + config->getTheme());
00187 DEBUGMSG_OUTSTR("Core", "Backend......................: " + getMMSFBBackendString(config->getBackend()));
00188 DEBUGMSG_OUTSTR("Core", "Graphics layer id............: " + iToStr(graphicslayer.id));
00189 DEBUGMSG_OUTSTR("Core", "Output type..................: " + getMMSFBOutputTypeString(config->getGraphicsLayer().outputtype));
00190 DEBUGMSG_OUTSTR("Core", "Graphics layer resolution....: " + iToStr(graphicslayer.rect.w) + "x" + iToStr(graphicslayer.rect.h));
00191 DEBUGMSG_OUTSTR("Core", "Graphics layer position......: " + iToStr(graphicslayer.rect.x) + "," + iToStr(graphicslayer.rect.y));
00192 DEBUGMSG_OUTSTR("Core", "Graphics layer pixelformat...: " + getMMSFBPixelFormatString(graphicslayer.pixelformat));
00193 DEBUGMSG_OUTSTR("Core", "Graphics layer options.......: " + graphicslayer.options);
00194 DEBUGMSG_OUTSTR("Core", "Graphics layer buffermode....: " + graphicslayer.buffermode);
00195 DEBUGMSG_OUTSTR("Core", "Video layer id...............: " + iToStr(videolayer.id));
00196 DEBUGMSG_OUTSTR("Core", "Output type..................: " + getMMSFBOutputTypeString(config->getVideoLayer().outputtype));
00197 DEBUGMSG_OUTSTR("Core", "Video layer resolution.......: " + iToStr(videolayer.rect.w) + "x" + iToStr(videolayer.rect.h));
00198 DEBUGMSG_OUTSTR("Core", "Video layer position.........: " + iToStr(videolayer.rect.x) + "," + iToStr(videolayer.rect.y));
00199 DEBUGMSG_OUTSTR("Core", "Video layer pixelformat......: " + getMMSFBPixelFormatString(videolayer.pixelformat));
00200 DEBUGMSG_OUTSTR("Core", "Video layer options..........: " + videolayer.options);
00201 DEBUGMSG_OUTSTR("Core", "Video layer buffermode.......: " + videolayer.buffermode);
00202 DEBUGMSG_OUTSTR("Core", "Visible screen area..........: " + iToStr(config->getVRect().x) + "," + iToStr(config->getVRect().y) + "," + iToStr(config->getVRect().w) + "," + iToStr(config->getVRect().h));
00203
00204 if (config->getStdout()) {
00205 DEBUGMSG_OUTSTR("Core", "Log to stdout................: yes");
00206 } else {
00207 DEBUGMSG_OUTSTR("Core", "Log to stdout................: no");
00208 }
00209
00210 DEBUGMSG_OUTSTR("Core", "Input Interval...............: " + iToStr(config->getInputInterval()) + " ms");
00211 DEBUGMSG_OUTSTR("Core", "Input Mode...................: " + config->getInputMode());
00212
00213 if (config->getShutdown()) {
00214 DEBUGMSG_OUTSTR("Core", "Call shutdown command........: yes");
00215 } else {
00216 DEBUGMSG_OUTSTR("Core", "Call shutdown command........: no");
00217 }
00218
00219 DEBUGMSG_OUTSTR("Core", "Shutdown command.............: " + config->getShutdownCmd());
00220
00221 DEBUGMSG_OUTSTR("Core", "Touch pad/screen area........: " + iToStr(config->getTouchRect().x) + "," + iToStr(config->getTouchRect().y) + "," + iToStr(config->getTouchRect().w) + "," + iToStr(config->getTouchRect().h));
00222
00223 DEBUGMSG_OUTSTR("Core", "Show mouse pointer...........: " + getMMSFBPointerModeString(config->getPointer()));
00224
00225 DEBUGMSG_OUTSTR("Core", "Graphics window pixelformat..: " + getMMSFBPixelFormatString(config->getGraphicsWindowPixelformat()));
00226 DEBUGMSG_OUTSTR("Core", "Graphics surface pixelformat.: " + getMMSFBPixelFormatString(config->getGraphicsSurfacePixelformat()));
00227
00228 if (config->getExtendedAccel()) {
00229 DEBUGMSG_OUTSTR("Core", "Extended acceleration........: yes");
00230 } else {
00231 DEBUGMSG_OUTSTR("Core", "Extended acceleration........: no");
00232 }
00233
00234 DEBUGMSG_OUTSTR("Core", "Alloc Method.................: " + config->getAllocMethod());
00235
00236 DEBUGMSG_OUTSTR("Core", "Fullscreen...................: " + getMMSFBFullScreenModeString(config->getFullScreen()));
00237 DEBUGMSG_OUTSTR("Core", "Rotate screen................: " + iToStr(config->getRotateScreen()) + "°");
00238
00239 if (config->getHideApplication()) {
00240 DEBUGMSG_OUTSTR("Core", "Hide application.............: yes");
00241 } else {
00242 DEBUGMSG_OUTSTR("Core", "Hide application.............: no");
00243 }
00244
00245 if (config->getInitialLoad()) {
00246 DEBUGMSG_OUTSTR("Core", "Initial load.................: yes");
00247 } else {
00248 DEBUGMSG_OUTSTR("Core", "Initial load.................: no");
00249 }
00250
00251 if (config->getDebugFrames()) {
00252 DEBUGMSG_OUTSTR("Core", "Draw debug frames............: yes");
00253 } else {
00254 DEBUGMSG_OUTSTR("Core", "Draw debug frames............: no");
00255 }
00256
00257 DEBUGMSG_OUTSTR("Core", "Sourcelanguage...............: " + getMMSLanguageString(config->getSourceLang()));
00258 DEBUGMSG_OUTSTR("Core", "Targetlanguage...............: " + getMMSLanguageString(config->getDefaultTargetLang()));
00259 DEBUGMSG_OUTSTR("Core", "Add missing translations.....: " + (config->getAddTranslations() ? string("yes") : string("no")));
00260 DEBUGMSG_OUTSTR("Core", "Language file directory......: " + config->getLanguagefileDir());
00261
00262 DEBUGMSG_OUTSTR("Core", "Activity monitor address.....: " + config->getActMonAddress());
00263 DEBUGMSG_OUTSTR("Core", "Activity monitor port........: " + iToStr(config->getActMonPort()));
00264
00265 printf("----------------------------------------------------------------------\n");
00266
00267 if (!appl_name.empty()) {
00268 DEBUGMSG_OUTSTR("Core", "Starting " + appl_name + "...");
00269 }
00270 }
00271
00272 if((flags & MMSINIT_WINDOWMANAGER)||(flags & MMSINIT_GRAPHICS)) {
00273 DEBUGMSG("Core", "initialize frame buffer");
00274
00275 #ifdef __ENABLE_ACTMON__
00276
00277 mmsperf = new MMSPerf();
00278
00279
00280 MMSTCPServer *server = new MMSTCPServer(new MMSPerfInterface(mmsperf),
00281 config->getActMonAddress(), config->getActMonPort(),
00282 "MMSTCPServer4Perfmon");
00283 server->start();
00284 #endif
00285
00286
00287 MMSWidget_inputmode = config->getInputMode();
00288
00289
00290 globalTheme = new MMSTheme(config->getInitialLoad(), config->getDebugFrames());
00291
00292
00293 mmsfbmanager.init(argc, argv, appl_name, appl_icon_name,
00294 (!(flags & MMSINIT_NO_CONSOLE)), (flags & MMSINIT_FLIP_FLUSH));
00295 mmsfbmanager.applySettings();
00296
00297 if (flags & MMSINIT_THEMEMANAGER) {
00298 DEBUGMSG("Core", "starting theme manager");
00299 themeManager = new MMSThemeManager(config->getData(),config->getTheme());
00300 }
00301
00302 if(flags & MMSINIT_WINDOWMANAGER) {
00303 DEBUGMSG("Core", "starting window manager");
00304
00305 windowmanager = new MMSWindowManager(config->getVRect());
00306 if(!windowmanager) {
00307 DEBUGMSG("Core", "couldn't create windowmanager.");
00308 return false;
00309 }
00310
00311
00312
00313
00314
00315
00316 DEBUGMSG("Core", "creating background window");
00317 MMSRootWindow *rootwin = new MMSRootWindow("background_rootwindow","","",
00318 MMSALIGNMENT_NOTSET,
00319 (MMSWINDOW_FLAGS)(MMSW_VIDEO | MMSW_USEGRAPHICSLAYER));
00320 if(!rootwin) {
00321 DEBUGMSG("Core", "couldn't create background window.");
00322 return false;
00323 }
00324
00325 DEBUGMSG("Core", "setting windowmanager for background window");
00326 rootwin->setWindowManager((IMMSWindowManager*)windowmanager);
00327
00328 DEBUGMSG("Core", "setting window as background window");
00329 windowmanager->setBackgroundWindow(rootwin);
00330
00331 DEBUGMSG("Core", "windowmanager initialization done");
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 }
00346
00347 if(flags & MMSINIT_PLUGINMANAGER) {
00348 if(!pluginmanager) {
00349 DEBUGMSG("Core", "creating PluginManager");
00350 pluginmanager = new MMSPluginManager();
00351 }
00352
00353 if(pluginRegisterCallback)
00354 pluginRegisterCallback(pluginmanager);
00355
00356 DEBUGMSG("Core", "loading Backend Plugins...");
00357 pluginmanager->loadBackendPlugins();
00358
00359 DEBUGMSG("Core", "loading OSD Plugins...");
00360 pluginmanager->loadOSDPlugins();
00361
00362 DEBUGMSG("Core", "loading Central Plugins...");
00363 pluginmanager->loadCentralPlugins();
00364
00365 DEBUGMSG("Core", "loading Import Plugins...");
00366 pluginmanager->loadImportPlugins();
00367
00368 DEBUGMSG("Core", "initialize Import Plugins...");
00369 pluginmanager->initializeImportPlugins();
00370 }
00371
00372 if(flags & MMSINIT_EVENTS) {
00373
00374 DEBUGMSG("Core", "creating EventSignupManager");
00375 eventsignupmanager = new MMSEventSignupManager();
00376
00377 DEBUGMSG("Core", "creating EventDispatcher");
00378 eventdispatcher = new MMSEventDispatcher(pluginmanager,eventsignupmanager);
00379
00380 masterevent = new MMSEvent();
00381 masterevent->setDispatcher(eventdispatcher);
00382
00383 MMSPluginData data;
00384 mastereventsignup = new MMSEventSignup(data);
00385 mastereventsignup->setManager(eventsignupmanager);
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 if((flags & MMSINIT_INPUTS) && (flags & MMSINIT_GRAPHICS)) {
00397
00398 DEBUGMSG("Core", "creating input manager");
00399 inputs = new MMSInputManager(config->getSysConfig() + "/inputmap.xml", config->getInputMap());
00400 inputs->setWindowManager((IMMSWindowManager*)windowmanager);
00401
00402 DEBUGMSG("Core", "add input device");
00403 inputs->addDevice(MMS_INPUT_KEYBOARD, config->getInputInterval());
00404
00405 DEBUGMSG("Core", "creating master subscription");
00406 MMSInputSubscription sub1(inputs);
00407
00408 DEBUGMSG("Core", "wait for inputs");
00409 inputs->startListen();
00410 }
00411
00412 atexit(on_exit);
00413
00414 } catch(MMSError &error) {
00415 DEBUGMSG("Core", "Abort due to: " + error.getMessage());
00416 fprintf(stderr, "Error initializing disko: %s\n", error.getMessage().c_str());
00417 return false;
00418 }
00419
00420 return true;
00421 }
00422
00423 bool mmsRelease() {
00424
00425 return true;
00426 }
00427
00428 bool registerSwitcher(IMMSSwitcher *switcher) {
00429 DEBUGMSG("Core", "registering switcher");
00430 switcher->setInputManager(inputs);
00431 switcher->setWindowManager((IMMSWindowManager*)windowmanager);
00432 if(pluginmanager) {
00433 switcher->setPluginManager(pluginmanager);
00434 pluginmanager->setSwitcher(switcher);
00435
00436 DEBUGMSG("Core", "initialize Backend Plugins...");
00437 pluginmanager->initializeBackendPlugins();
00438
00439 DEBUGMSG("Core", "initialize OSD Plugins...");
00440 pluginmanager->initializeOSDPlugins();
00441
00442 DEBUGMSG("Core", "initialize Central Plugins...");
00443 pluginmanager->initializeCentralPlugins();
00444 }
00445
00446
00447 if(masterevent) {
00448 MMSEvent *initializedEvent = new MMSEvent("MMSINIT.initialized");
00449 initializedEvent->send();
00450 }
00451
00452 return true;
00453 }
00454
00455 void setPluginRegisterCallback(void(*cb)(MMSPluginManager*)) {
00456 pluginRegisterCallback = cb;
00457 }
00458
00459 IMMSWindowManager *getWindowManager() {
00460 return windowmanager;
00461 }
00462
00463 void setPluginManager(MMSPluginManager *pm) {
00464 if(pluginmanager) {
00465 DEBUGMSG("CORE", "Error: You cannot set a pluginmanager after calling mmsinit()");
00466 return;
00467 }
00468 pluginmanager = pm;
00469 }
00470
00471 MMSPluginManager *getPluginManager() {
00472 return pluginmanager;
00473 }
00474
00475 MMSFBLayer *getVideoLayer() {
00476 return mmsfbmanager.getVideoLayer();
00477 }
00478
00479 MMSFBLayer *getGraphicsLayer() {
00480 return mmsfbmanager.getGraphicsLayer();
00481 }
00482
00483 void showBackgroundWindow() {
00484
00485 IMMSWindowManager *wm = getWindowManager();
00486 if (wm) {
00487 MMSWindow *win = wm->getBackgroundWindow();
00488 if (win) {
00489 win->show();
00490 win->waitUntilShown();
00491 }
00492 }
00493 }