From: Chris Tallon Date: Wed, 15 Apr 2020 17:16:50 +0000 (+0100) Subject: Rename Command class to Control X-Git-Url: https://git.vomp.tv/gitweb/?a=commitdiff_plain;h=486cf4e9d43294648bd46929aa7ab2dae4072378;p=vompclient.git Rename Command class to Control --- diff --git a/channel.cc b/channel.cc index 8cd2f90..99941f8 100644 --- a/channel.cc +++ b/channel.cc @@ -21,7 +21,7 @@ #include "vdr.h" #include "log.h" -#include "command.h" +#include "control.h" Channel::Channel() { @@ -51,7 +51,7 @@ void Channel::loadPids() VDR::getInstance()->getChannelPids(this); // FIXME sort out this system if (!VDR::getInstance()->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } diff --git a/command.cc b/command.cc deleted file mode 100644 index 54dee97..0000000 --- a/command.cc +++ /dev/null @@ -1,1065 +0,0 @@ -/* - Copyright 2004-2020 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP. If not, see . -*/ - -// FIXME rename to Control and move stuff from main to here - - -#include "command.h" - -#ifdef WIN32 -#include "inputwin.h" -#endif - -#ifdef __ANDROID__ -#include "inputandroid.h" -#endif - -#include "led.h" -#include "video.h" -#include "audio.h" -#include "vdr.h" -#include "vvolume.h" -#include "vserverselect.h" -#include "vwelcome.h" -#include "vmute.h" -#include "colour.h" -#include "osd.h" -#include "i18n.h" -#include "timers.h" -#include "wol.h" -#include "vconnect.h" -#include "message.h" -#include "inputman.h" -#include "input.h" -#include "vinfo.h" -#include "boxx.h" -#include "boxstack.h" -#include "log.h" -#include "vsleeptimer.h" -#include "wjpeg.h" -#include "osdvector.h" - - -Command* Command::instance = NULL; - -Command::Command() -{ - if (instance) return; - instance = this; -} - -Command::~Command() -{ - flushMessageQueue(); - instance = NULL; -} - -Command* Command::getInstance() -{ - return instance; -} - -int Command::init(bool tcrashed) -{ - if (initted) return 0; - initted = true; - crashed = tcrashed; - - logger = Log::getInstance(); - boxstack = BoxStack::getInstance(); - inputMan = InputMan::getInstance(); - - if (!logger || !boxstack || !inputMan) - { - initted = false; - return 0; - } - - SkinFactory::InitSkin(0); - - return 1; -} - -int Command::shutdown() -{ - if (!initted) return 0; - initted = false; - return 1; -} - -void Command::stop() -{ - logger->log("Command", Log::NOTICE, "Request stop"); - - Message* m = new Message(); // break master loop - m->message = Message::SHUTDOWN; - m->p_to = Message::CONTROL; - postMessage(m); -} - -void Command::doWallpaper() -{ - Video* video = Video::getInstance(); - - // Blue background - Boxx* bbg = new Boxx(); - bbg->setSize(video->getScreenWidth(), video->getScreenHeight()); - bbg->createBuffer(); - bbg->fillColour(DrawStyle::WALLPAPER); - boxstack->add(bbg); - boxstack->update(bbg); - boxstack->remove(bbg); - - // Wallpaper - wallpaper = new Boxx(); - wallpaper->setSize(video->getScreenWidth(), video->getScreenHeight()); - wallpaper->createBuffer(); - wallpaper->setBackgroundColour(DrawStyle::WALLPAPER); - - wallpaper_pict = new WJpegTYPE(); - wallpaper_pict->setSize(video->getScreenWidth(), video->getScreenHeight()); - - if (video->getFormat() == Video::PAL) - { - logger->log("Command", Log::DEBUG, "PAL wallpaper selected"); -#ifndef _MIPS_ARCH - wallpaper_pict->init("/wallpaperPAL.jpg"); -#else - wallpaper_pict->init("wallpaperPAL.jpg"); -#endif - } - else - { - logger->log("Command", Log::DEBUG, "NTSC wallpaper selected"); - wallpaper_pict->init("/wallpaperNTSC.jpg"); - } - - if (DrawStyle::WALLPAPER.alpha) - wallpaper_pict->setVisible(true); - else - wallpaper_pict->setVisible(false); - - wallpaper->add(wallpaper_pict); - wallpaper->draw(); - - boxstack->add(wallpaper); - boxstack->update(wallpaper); - - OsdVector* osdv = dynamic_cast(Osd::getInstance()); - if (osdv) osdv->updateBackgroundColor(DrawStyle::WALLPAPER); -} - -void Command::run() -{ - if (!initted) return; - irun = true; - - // just in case - Video::getInstance()->signalOn(); - Led::getInstance()->on(); - - doWallpaper(); - - if (crashed) - { - buildCrashedBox(); - } - else - { - VConnect* vconnect = new VConnect(); - boxstack->add(vconnect); - vconnect->run(); - } - - - // FIXME Input::NA_SIGNAL is possibly obsolete now - - std::unique_lock lockWrapper(messageQueueMutex); // locks. unlocks on out-of-scope - - inputMan->start(); - - while(irun) - { - messageQueueCond.wait(lockWrapper, [&] { return !irun || !messages.empty(); }); - logger->log("Command", Log::DEBUG, "woke"); - - if (!irun) break; - - while(!messages.empty()) - { - Message* m = messages.front(); - messages.pop_front(); - - lockWrapper.unlock(); - - processMessage(m); - delete m; - - lockWrapper.lock(); - } - } - - inputMan->stop(); - - boxstack->removeAllExceptWallpaper(); - boxstack->remove(wallpaper); - delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; -} - -void Command::processMessage(Message* m) -{ - // FIXME - a slight modification - how if messagereceivers were to register - // themselves as receivers to avoid the calling-a-deleted-object problem - // then only deliver/register/unregister would have to be protected - - logger->log("Command", Log::DEBUG, "processing message %i", m->message); - - - if ((m->p_to == Message::CONTROL) || (m->to == this)) // Maybe don't check m->to here? Always use predefined? - { - switch(m->message) - { - case Message::SHUTDOWN: - { - irun = false; - break; - } - // << FIXME OBSELETE - case Message::STOP_PLAYBACK: - { - handleCommand(Input::STOP); // an odd way of doing it, but so simple - break; - } - // Also connection_lost comes from player - anywhere else? - // FIXME OBSELETE >> - - - case Message::VDR_CONNECTED: - { - doJustConnected(static_cast(m->from)); - break; - } - case Message::SCREENSHOT: - { - logger->log("Osd", Log::NOTICE, "Screenshot Message arrived"); - Osd::getInstance()->screenShot("out.jpg"); - break; - } - case Message::CONNECTION_LOST: - { - doFromTheTop(true); - break; - } - case Message::INPUT_EVENT: - { - logger->log("Command", Log::NOTICE, "INPUT_EVENT %i", m->parameter); - - handleCommand(m->parameter); - break; - } - case Message::CHANGE_LANGUAGE: - { - boxstack->removeAllExceptWallpaper(); - boxstack->update(wallpaper); - I18n::initialize(); - if (!VDR::getInstance()->isConnected()) { connectionLost(); break; } - VWelcome* vw = new VWelcome(); - vw->draw(); - boxstack->add(vw); - boxstack->update(vw); - break; - } - case Message::LAST_VIEW_CLOSE: - { - // Shouldn't be done like this. Some generic message pass back from vinfo perhaps - if (crashed) - { - crashed = false; - doFromTheTop(false); - } - -// VWelcome* vw = new VWelcome(); -// vw->draw(); -// boxstack->add(vw); -// boxstack->update(vw); - - break; - } - case Message::NEW_PICTURE: - { - //Log::getInstance()->log("Command", Log::DEBUG, "TVMedia NEW_PICTURE"); - OsdVector* osdv = dynamic_cast(Osd::getInstance()); - if (osdv) osdv->informPicture(m->tag, reinterpret_cast(m->data)); - break; - } - case Message::NEW_PICTURE_STATIC: - { - //Log::getInstance()->log("Command", Log::DEBUG, "TVMedia NEW_PICTURE %x %x",m->tag,m->parameter); - OsdVector* osdv = dynamic_cast(Osd::getInstance()); - if (osdv) osdv->informPicture(static_cast(m->tag) << 32LL, reinterpret_cast(m->data)); - break; - } - } - } - else - { - /* FIXME - - Instead of sending through the boxstack, implement a more generic MessageReceiver interface - and have potential receivers register with something - When a message needs to be delivered, check if the receiver is still registered, if so, deliver the message - This could all be done using the existing big command mutex to keep it simple - */ - - logger->log("Command", Log::DEBUG, "Sending message to boxstack"); - boxstack->processMessage(m); - } -} - -void Command::handleCommand(int button) -{ - if (isStandby && (button != Input::POWER) - && (button != Input::POWERON) - && (button != Input::POWEROFF)) return; - - if (!connLost && boxstack->handleCommand(button)) return; // don't send to boxstack if connLost - - // command was not handled - - switch(button) - { - case Input::VOLUMEUP: - case Input::VOLUMEDOWN: - { - if (inputMan->handlesVolume()) // CEC volume handler? - { - if (button == Input::VOLUMEDOWN) - inputMan->volumeDown(); - else - inputMan->volumeUp(); - } - else - { - VVolume* v = new VVolume(); - boxstack->add(v); - v->handleCommand(button); // this will draw+show - } - return; - } - case Input::MUTE: - { - if (inputMan->handlesVolume()) - { - inputMan->volumeMute(); - } - else - { - VMute* v = new VMute(); - v->draw(); - boxstack->add(v); - boxstack->update(v); - } - return; - } - case Input::POWER: - { - doStandby(); - return; - } - case Input::POWERON: - { - doPowerOn(); - return; - } - case Input::POWEROFF: - { - doPowerOff(); - return; - } - case Input::OK: - { - // FIXME - if (!connLost) return; // if connLost, handle Input::OK - doFromTheTop(false); - return; - } - case Input::GO: - { - VSleeptimer* sleep = new VSleeptimer(); - boxstack->add(sleep); - sleep->handleCommand(button); // this will draw+show - return; - } - } -} - -/* -void Command::sig1() -{ -#ifdef DEV - Message* m = new Message(); // break into master mutex - m->message = Message::SCREENSHOT; - m->to = this; - postMessage(m); -#endif -} -*/ - -void Command::doStandby() -{ - if (isStandby) - { - doPowerOn(); - } - else - { - doPowerOff(); - } -} - - -void Command::doPowerOn() -{ - if (isStandby) - { - Video::getInstance()->signalOn(); - Led::getInstance()->on(); - InputMan::getInstance()->changePowerState(true); - isStandby = false; - - VConnect* vconnect = new VConnect(); - boxstack->add(vconnect); - vconnect->run(); - } -} - -void Command::doPowerOff() -{ - if (!isStandby) - { - VDR::getInstance()->shutdownVDR(); - boxstack->removeAllExceptWallpaper(); - Video::getInstance()->signalOff(); - boxstack->update(wallpaper); - - VDR::getInstance()->configSave("General", "Last Power State", "Off"); - logger->unsetExternLogger(); - VDR::getInstance()->disconnect(); - Led::getInstance()->off(); - InputMan::getInstance()->changePowerState(false); - isStandby = true; - Sleeptimer::getInstance()->shutdown(); - } -} - -void Command::doFromTheTop(bool which) -{ - if (isStandby) return; - if (which) - { - if (connLost) - { - logger->log("Command", Log::NOTICE, "Connection lost dialog already present"); - return; - } - - logger->log("Command", Log::NOTICE, "Doing connection lost dialog"); - connLost = new VInfo(); - connLost->setSize(360, 200); - connLost->createBuffer(); - if (Video::getInstance()->getFormat() == Video::PAL) - connLost->setPosition(190, 170); - else - connLost->setPosition(180, 120); - connLost->setOneLiner(tr("Connection lost")); - connLost->setDropThrough(); - connLost->setBorderOn(1); - connLost->setTitleBarColour(DrawStyle::DANGER); - connLost->okButton(); - connLost->draw(); - boxstack->add(connLost); - boxstack->update(connLost); - - clearMQInputEvents(); - } - else - { - logger->unsetExternLogger(); - VDR::getInstance()->disconnect(); - boxstack->removeAllExceptWallpaper(); - boxstack->update(wallpaper); - connLost = NULL; - - flushMessageQueue(); - - // at this point, everything should be reset to first-go - - VConnect* vconnect = new VConnect(); - boxstack->add(vconnect); - vconnect->run(); - } -} - -void Command::clearMQInputEvents() -{ - std::lock_guard lg(messageQueueMutex); // Get the lock - - MQueueI i = messages.begin(); - while(i != messages.end()) - { - Message* m = *i; - if (m->message == Message::INPUT_EVENT) - { - delete m; - i = messages.erase(i); - } - else - { - ++i; - } - } -} - -void Command::doReboot() -{ - - logger->unsetExternLogger(); - VDR::getInstance()->disconnect(); - // just kill it... - logger->log("Command", Log::NOTICE, "Reboot"); -#ifndef WIN32 -#ifndef VOMP_HAS_EXIT - // some plattforms, want a proper deinitialisation of their hardware before reboot - Osd::getInstance()->shutdown(); - Audio::getInstance()->shutdown(); - Video::getInstance()->shutdown(); - InputMan::getInstance()->shutdown(); - - reboot(LINUX_REBOOT_CMD_RESTART); - // if reboot is not allowed -> stop - stop(); - - -#else - stop(); - -#ifdef __ANDROID__ - exit(0); -#endif - -#endif -#endif //Would we support this on windows? -} - -void Command::connectionLost() -{ - logger->unsetExternLogger(); - Message* m = new Message(); // break into master mutex - m->message = Message::CONNECTION_LOST; - m->p_to = Message::CONTROL; - postMessage(m); -} - -void Command::buildCrashedBox() -{ - VInfo* crash = new VInfo(); - crash->setSize(360, 250); - crash->createBuffer(); - if (Video::getInstance()->getFormat() == Video::PAL) - crash->setPosition(190, 146); - else - crash->setPosition(180, 96); - crash->setMainText("Oops, vomp crashed.. :(\nPlease report this crash to the author, with as much detail as possible about what you were doing at the time that might have caused the crash."); - crash->setBorderOn(1); - crash->setTitleBarColour(DrawStyle::DANGER); - crash->okButton(); - crash->setExitable(); - crash->draw(); - boxstack->add(crash); - boxstack->update(crash); -} - -int Command::getLangPref(bool subtitle, const char* langcode) -{ - std::vector::iterator itty=langcodes.begin(); - char templangcode[4]; - templangcode[0] = langcode[0]; - templangcode[1] = langcode[1]; - templangcode[2] = langcode[2]; - templangcode[3] = '\0'; - int langpos = 0; - while (itty != langcodes.end()) - { - size_t pos = (*itty).langcode.find(templangcode); - if (pos != std::string::npos) - { - //vector::iterator itty2=langcodes.begin(); - for (unsigned int i = 0; i < langcodes.size(); i++) - { - int pref = 0; - if (subtitle) - pref = langcodes[i].subtitlepref; - else - pref = langcodes[i].audiopref; - if (pref < 0) break; - - if (subtitle) - { - if (langcodes[i].subtitlepref==langpos) return i; - } - else - { - if (langcodes[i].audiopref==langpos) return i; - } - } - break; - } - itty++; - langpos++; - } - return langcodes.size(); //neutral -} - -void Command::doJustConnected(VConnect* vconnect) -{ - I18n::initialize(); - if (!VDR::getInstance()->isConnected()) { connectionLost(); return; } - logger->log("Command", Log::INFO, "Entering doJustConnected"); - - Video* video = Video::getInstance(); - Audio* audio = Audio::getInstance(); - boxstack->remove(vconnect); - - VInfo* vi = new VInfo(); - vi->setSize(400, 200); - vi->createBuffer(); - if (video->getFormat() == Video::PAL) - vi->setPosition(170, 200); - else - vi->setPosition(160, 150); - vi->setOneLiner(tr("Connected, loading config")); - vi->draw(); - boxstack->add(vi); - boxstack->update(vi); - - // FIXME make config system - - VDR* vdr = VDR::getInstance(); - char* config; - - // See if we're supposed to do network logging - config = vdr->configLoad("Advanced", "Network logging"); - if (config && !STRCASECMP(config, "On")) - { - logger->log("Command", Log::INFO, "Turning on network logging"); - logger->setExternLogger(vdr); - } - else - { - logger->unsetExternLogger(); - logger->log("Command", Log::INFO, "Turned off network logging"); - } - if (config) delete[] config; - - config = vdr->configLoad("Advanced", "Skin Name"); - if (config) - { - const char **skinnames=SkinFactory::getSkinNames(); - for (int i=0;isetVisible(true); - else - wallpaper_pict->setVisible(false); - - wallpaper->draw(); - boxstack->update(wallpaper); - } - } - else - { - SkinFactory::InitSkin(0); - } - - // See if config says to override video format (PAL/NTSC) - config = vdr->configLoad("General", "Override Video Format"); - if (config) - { - logger->log("Command", Log::DEBUG, "Override Video Format is present"); - - if ( (!strcmp(config, "PAL") && (video->getFormat() != Video::PAL)) - || (!strcmp(config, "NTSC") && (video->getFormat() != Video::NTSC)) - || (!strcmp(config, "PAL_M") && (video->getFormat() != Video::PAL_M)) - || (!strcmp(config, "NTSC_J") && (video->getFormat() != Video::NTSC_J)) - ) - { - // Oh sheesh, need to switch format. Bye bye TV... - - // Take everything down - boxstack->removeAllExceptWallpaper(); - boxstack->remove(wallpaper); - delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; - - Osd* osd = Osd::getInstance(); -#ifndef __ANDROID__ - osd->shutdown(); -#endif - video->shutdown(); - - inputMan->shutdown(); // need on raspberry shut not do any harm, hopefully - inputMan->init(); // FIXME this breaks badly now - - // Get video and osd back up with the new mode - if (!strcmp(config, "PAL")) - { - logger->log("Command", Log::DEBUG, "Switching to PAL"); - video->init(Video::PAL); - } - else if (!strcmp(config, "NTSC")) - { - logger->log("Command", Log::DEBUG, "Switching to NTSC"); - video->init(Video::NTSC); - } else if (!strcmp(config, "PAL_M")) - { - logger->log("Command", Log::DEBUG, "Switching to PAL_M"); - video->init(Video::PAL_M); - } else if (!strcmp(config, "NTSC_J")) - { - logger->log("Command", Log::DEBUG, "Switching to NTSC_J"); - video->init(Video::NTSC_J); - } - delete[] config; - -#ifndef __ANDROID__ - //we do not init twice - osd->init(); -#endif - - // Put the wallpaper back - doWallpaper(); - - // Re add the vinfo - vi = new VInfo(); - vi->setSize(400, 200); - vi->createBuffer(); - if (video->getFormat() == Video::PAL) - vi->setPosition(170, 200); - else - vi->setPosition(160, 150); - - vi->setOneLiner(tr("Connected, loading config")); - vi->draw(); - boxstack->add(vi); - boxstack->update(vi); - } - else - { - logger->log("Command", Log::DEBUG, "Already in requested mode, or request was not 'PAL' or 'NTSC'"); - } - } - else - { - logger->log("Command", Log::DEBUG, "Phew, no dangerous on-the-fly mode switching to do!"); - } - - // Power off if first boot and config says so - if (firstBoot) - { - firstBoot = false; - - logger->log("Command", Log::DEBUG, "Load power after boot"); - - config = vdr->configLoad("General", "Power After Boot"); - - if (config) - { - if (!STRCASECMP(config, "On")) - { - logger->log("Command", Log::INFO, "Config says Power After Boot = On"); - } - else if (!STRCASECMP(config, "Off")) - { - logger->log("Command", Log::INFO, "Config says Power After Boot = Off"); - doStandby(); - delete[] config; - return; // quit here - } - else if (!STRCASECMP(config, "Last state")) - { - char* lastPowerState = vdr->configLoad("General", "Last Power State"); - if (lastPowerState) - { - if (!STRCASECMP(lastPowerState, "On")) - { - logger->log("Command", Log::INFO, "Config says Last Power State = On"); - } - else if (!STRCASECMP(lastPowerState, "Off")) - { - logger->log("Command", Log::INFO, "Config says Last Power State = Off"); - doStandby(); - delete[] config; - return; // quit here - } - else - { - logger->log("Command", Log::INFO, "Config General/Last Power State not understood"); - } - } - else - { - logger->log("Command", Log::INFO, "Config General/Last Power State not found"); - } - } - else - { - logger->log("Command", Log::INFO, "Config/Power After Boot not understood"); - } - delete[] config; - } - else - { - logger->log("Command", Log::INFO, "Config General/Power After Boot not found"); - } - } - - - // Go S-Video if config says so - - config = vdr->configLoad("TV", "Connection"); - - if (config) - { - if (!STRCASECMP(config, "S-Video")) - { - logger->log("Command", Log::INFO, "Switching to S-Video as Connection=%s", config); - video->setConnection(Video::SVIDEO); - } else if (!STRCASECMP(config, "HDMI")) - { - logger->log("Command", Log::INFO, "Switching to HDMI as Connection=%s", config); - video->setConnection(Video::HDMI); - } else if (!STRCASECMP(config, "HDMI3D")) - { - logger->log("Command", Log::INFO, "Switching to HDMI3D as Connection=%s", config); - video->setConnection(Video::HDMI3D); - } - else - { - logger->log("Command", Log::INFO, "Switching to RGB/Composite as Connection=%s", config); - video->setConnection(Video::COMPOSITERGB); - } - delete[] config; - } - else - { - logger->log("Command", Log::INFO, "Config TV/S-Video not found"); - } - - // Set to shutdown VDR if config says - - config = vdr->configLoad("General", "VDR shutdown"); - if (config) - { - if (!STRCASECMP(config, "On")) - { - logger->log("Command", Log::INFO, "Shutdown VDR when shutting down vomp"); - vdr->setVDRShutdown(true); - } - else if (!STRCASECMP(config, "Off")) - { - logger->log("Command", Log::INFO, "Shutdown only vomp"); - vdr->setVDRShutdown(false); - } - } - else - { - logger->log("Command", Log::INFO, "Default shutdown only vomp"); - vdr->setVDRShutdown(false); // Default - } - - // Get TV aspect ratio - - config = vdr->configLoad("TV", "Aspect"); - if (config) - { - if (!STRCASECMP(config, "16:9")) - { - logger->log("Command", Log::INFO, "/// Switching to TV aspect 16:9"); - video->setTVsize(Video::ASPECT16X9); - } - else - { - logger->log("Command", Log::INFO, "/// Switching to TV aspect 4:3"); - video->setTVsize(Video::ASPECT4X3); - } - delete[] config; - } - else - { - logger->log("Command", Log::INFO, "Config TV/Aspect type not found, going 4:3"); - video->setTVsize(Video::ASPECT4X3); - } - - config = vdr->configLoad("TV", "Widemode"); - if (config) - { - if (!STRCASECMP(config, "Letterbox")) - { - logger->log("Command", Log::INFO, "Setting letterbox mode"); - video->setMode(Video::LETTERBOX); - } - else - { - logger->log("Command", Log::INFO, "Setting chop-sides mode"); - video->setMode(Video::NORMAL); - } - delete[] config; - } - else - { -#ifdef __ANDROID__ - logger->log("Command", Log::INFO, "Config TV/Widemode not found, Setting letterbox mode"); - video->setMode(Video::LETTERBOX); -#else - logger->log("Command", Log::INFO, "Config TV/Widemode not found, Setting chop-sides mode"); - video->setMode(Video::NORMAL); -#endif - } - - config = vdr->configLoad("Advanced", "TCP receive window"); - if (config) - { - size_t newTCPsize = atoi(config); - delete[] config; - - logger->log("Command", Log::INFO, "Setting TCP window size %i", newTCPsize); - vdr->setReceiveWindow(newTCPsize); - } - else - { - logger->log("Command", Log::INFO, "TCP window size not found, setting 2048"); - if (DEFAULT_TCP_WINDOWSIZE) vdr->setReceiveWindow(2048); // Default - } - - config = vdr->configLoad("Advanced", "Font Name"); - if (config) - { - Osd::getInstance()->setFont(config); - logger->log("Command", Log::INFO, "Setting Font to %s", config); - delete[] config; - - } - - - // Set recording list type - -#ifdef ADVANCED_MENUES - config = vdr->configLoad("Advanced", "Menu type"); - - if (config) - { - if (!STRCASECMP(config, "Advanced")) - { - logger->log("Command", Log::INFO, "Switching to Advanced menu"); - advMenus = true; - } - else - { - logger->log("Command", Log::INFO, "Switching to Classic menu"); - advMenus = false; - } - delete[] config; - } - else - { - logger->log("Command", Log::INFO, "Config General/menu type not found"); - advMenus = true; - } -#endif - - config = vdr->configLoad("Advanced", "Disable WOL"); - if (config) - { - if (!STRCASECMP(config, "Yes")) - { - logger->log("Command", Log::INFO, "Config says disable WOL"); - Wol::getInstance()->setEnabled(false); - } - else - { - logger->log("Command", Log::INFO, "Config says enable WOL"); - Wol::getInstance()->setEnabled(true); - } - - delete[] config; - } - else - { - logger->log("Command", Log::INFO, "By default, enable WOL"); - Wol::getInstance()->setEnabled(true); - } - /* device dependend config */ - audio->loadOptionsFromServer(vdr); - video->loadOptionsFromServer(vdr); - inputMan->loadOptionsFromServer(vdr); - - video->executePendingModeChanges(); - // config done - - // Save power state = on - - vdr->configSave("General", "Last Power State", "On"); - - // Make sure connection didn't die - if (!vdr->isConnected()) - { - Command::getInstance()->connectionLost(); - } - else - { - boxstack->remove(vi); - - VWelcome* vw = new VWelcome(); - vw->draw(); - boxstack->add(vw); - boxstack->update(vw); - - // Enter pre-keys here -// handleCommand(Input::OK); -// handleCommand(Input::THREE); -// handleCommand(Input::SIX); -// handleCommand(Input::OK); -// handleCommand(Input::UP); -// handleCommand(Input::PLAY); -// handleCommand(Input::DOWN); -// handleCommand(Input::DOWN); -// handleCommand(Input::DOWN); -// handleCommand(Input::RIGHT); -// handleCommand(Input::RED); - } -} diff --git a/command.h b/command.h deleted file mode 100644 index 62fb740..0000000 --- a/command.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright 2004-2020 Chris Tallon - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP. If not, see . -*/ - -#ifndef COMMAND_H -#define COMMAND_H - -#ifndef WIN32 -#include // for reboot -#include -#include -#endif - -#include -#ifndef WIN32 -#include // why? -#endif - -#include -#include - -#include "defines.h" -#include "messagequeue.h" - -class VConnect; -class Message; -class InputMan; -class Boxx; -class BoxStack; -class Log; -class VInfo; -class WJpeg; - -struct ASLPref -{ - std::string langcode; - int audiopref; - int subtitlepref; -}; - -typedef std::vector ASLPrefList; - -class Command : public MessageQueue -{ - public: - Command(); - ~Command(); - static Command* getInstance(); - - int init(bool crashed = false); - int shutdown(); - void run(); - void stop(); - void doReboot(); - void connectionLost(); - - void setAdvMenus(bool adv) { advMenus = adv; }; - bool isAdvMenus() { return advMenus; }; - int getLangPref(bool subtitle,const char* langcode); - void setSubDefault(int subon) { subdefault = subon; }; - int getSubDefault() { return subdefault; }; - ASLPrefList &getASLList() { return langcodes; }; - - private: - void handleCommand(int); - void doStandby(); - void doPowerOn(); - void doPowerOff(); - void doJustConnected(VConnect* vconnect); - void doWallpaper(); - void doFromTheTop(bool which); // true - show vinfo,wait. false - del vinfo,restart - void buildCrashedBox(); -// void sig1(); - void clearMQInputEvents(); - - static Command* instance; - - Log* logger; - BoxStack* boxstack; - InputMan* inputMan; - - bool initted{}; - bool irun{}; - bool isStandby{}; - bool firstBoot{true}; - Boxx* wallpaper{}; - WJpeg* wallpaper_pict{}; - VInfo* connLost{}; - bool crashed{}; - - bool advMenus{}; - ASLPrefList langcodes; - int subdefault; - - void processMessage(Message* m); -}; - -#endif diff --git a/control.cc b/control.cc new file mode 100644 index 0000000..e4802a4 --- /dev/null +++ b/control.cc @@ -0,0 +1,1065 @@ +/* + Copyright 2004-2020 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP. If not, see . +*/ + +// FIXME rename to Control and move stuff from main to here + + +#include "control.h" + +#ifdef WIN32 +#include "inputwin.h" +#endif + +#ifdef __ANDROID__ +#include "inputandroid.h" +#endif + +#include "led.h" +#include "video.h" +#include "audio.h" +#include "vdr.h" +#include "vvolume.h" +#include "vserverselect.h" +#include "vwelcome.h" +#include "vmute.h" +#include "colour.h" +#include "osd.h" +#include "i18n.h" +#include "timers.h" +#include "wol.h" +#include "vconnect.h" +#include "message.h" +#include "inputman.h" +#include "input.h" +#include "vinfo.h" +#include "boxx.h" +#include "boxstack.h" +#include "log.h" +#include "vsleeptimer.h" +#include "wjpeg.h" +#include "osdvector.h" + + +Control* Control::instance = NULL; + +Control::Control() +{ + if (instance) return; + instance = this; +} + +Control::~Control() +{ + flushMessageQueue(); + instance = NULL; +} + +Control* Control::getInstance() +{ + return instance; +} + +int Control::init(bool tcrashed) +{ + if (initted) return 0; + initted = true; + crashed = tcrashed; + + logger = Log::getInstance(); + boxstack = BoxStack::getInstance(); + inputMan = InputMan::getInstance(); + + if (!logger || !boxstack || !inputMan) + { + initted = false; + return 0; + } + + SkinFactory::InitSkin(0); + + return 1; +} + +int Control::shutdown() +{ + if (!initted) return 0; + initted = false; + return 1; +} + +void Control::stop() +{ + logger->log("Control", Log::NOTICE, "Request stop"); + + Message* m = new Message(); // break master loop + m->message = Message::SHUTDOWN; + m->p_to = Message::CONTROL; + postMessage(m); +} + +void Control::doWallpaper() +{ + Video* video = Video::getInstance(); + + // Blue background + Boxx* bbg = new Boxx(); + bbg->setSize(video->getScreenWidth(), video->getScreenHeight()); + bbg->createBuffer(); + bbg->fillColour(DrawStyle::WALLPAPER); + boxstack->add(bbg); + boxstack->update(bbg); + boxstack->remove(bbg); + + // Wallpaper + wallpaper = new Boxx(); + wallpaper->setSize(video->getScreenWidth(), video->getScreenHeight()); + wallpaper->createBuffer(); + wallpaper->setBackgroundColour(DrawStyle::WALLPAPER); + + wallpaper_pict = new WJpegTYPE(); + wallpaper_pict->setSize(video->getScreenWidth(), video->getScreenHeight()); + + if (video->getFormat() == Video::PAL) + { + logger->log("Control", Log::DEBUG, "PAL wallpaper selected"); +#ifndef _MIPS_ARCH + wallpaper_pict->init("/wallpaperPAL.jpg"); +#else + wallpaper_pict->init("wallpaperPAL.jpg"); +#endif + } + else + { + logger->log("Control", Log::DEBUG, "NTSC wallpaper selected"); + wallpaper_pict->init("/wallpaperNTSC.jpg"); + } + + if (DrawStyle::WALLPAPER.alpha) + wallpaper_pict->setVisible(true); + else + wallpaper_pict->setVisible(false); + + wallpaper->add(wallpaper_pict); + wallpaper->draw(); + + boxstack->add(wallpaper); + boxstack->update(wallpaper); + + OsdVector* osdv = dynamic_cast(Osd::getInstance()); + if (osdv) osdv->updateBackgroundColor(DrawStyle::WALLPAPER); +} + +void Control::run() +{ + if (!initted) return; + irun = true; + + // just in case + Video::getInstance()->signalOn(); + Led::getInstance()->on(); + + doWallpaper(); + + if (crashed) + { + buildCrashedBox(); + } + else + { + VConnect* vconnect = new VConnect(); + boxstack->add(vconnect); + vconnect->run(); + } + + + // FIXME Input::NA_SIGNAL is possibly obsolete now + + std::unique_lock lockWrapper(messageQueueMutex); // locks. unlocks on out-of-scope + + inputMan->start(); + + while(irun) + { + messageQueueCond.wait(lockWrapper, [&] { return !irun || !messages.empty(); }); + logger->log("Control", Log::DEBUG, "woke"); + + if (!irun) break; + + while(!messages.empty()) + { + Message* m = messages.front(); + messages.pop_front(); + + lockWrapper.unlock(); + + processMessage(m); + delete m; + + lockWrapper.lock(); + } + } + + inputMan->stop(); + + boxstack->removeAllExceptWallpaper(); + boxstack->remove(wallpaper); + delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; +} + +void Control::processMessage(Message* m) +{ + // FIXME - a slight modification - how if messagereceivers were to register + // themselves as receivers to avoid the calling-a-deleted-object problem + // then only deliver/register/unregister would have to be protected + + logger->log("Control", Log::DEBUG, "processing message %i", m->message); + + + if ((m->p_to == Message::CONTROL) || (m->to == this)) // Maybe don't check m->to here? Always use predefined? + { + switch(m->message) + { + case Message::SHUTDOWN: + { + irun = false; + break; + } + // << FIXME OBSELETE + case Message::STOP_PLAYBACK: + { + handleCommand(Input::STOP); // an odd way of doing it, but so simple + break; + } + // Also connection_lost comes from player - anywhere else? + // FIXME OBSELETE >> + + + case Message::VDR_CONNECTED: + { + doJustConnected(static_cast(m->from)); + break; + } + case Message::SCREENSHOT: + { + logger->log("Osd", Log::NOTICE, "Screenshot Message arrived"); + Osd::getInstance()->screenShot("out.jpg"); + break; + } + case Message::CONNECTION_LOST: + { + doFromTheTop(true); + break; + } + case Message::INPUT_EVENT: + { + logger->log("Control", Log::NOTICE, "INPUT_EVENT %i", m->parameter); + + handleCommand(m->parameter); + break; + } + case Message::CHANGE_LANGUAGE: + { + boxstack->removeAllExceptWallpaper(); + boxstack->update(wallpaper); + I18n::initialize(); + if (!VDR::getInstance()->isConnected()) { connectionLost(); break; } + VWelcome* vw = new VWelcome(); + vw->draw(); + boxstack->add(vw); + boxstack->update(vw); + break; + } + case Message::LAST_VIEW_CLOSE: + { + // Shouldn't be done like this. Some generic message pass back from vinfo perhaps + if (crashed) + { + crashed = false; + doFromTheTop(false); + } + +// VWelcome* vw = new VWelcome(); +// vw->draw(); +// boxstack->add(vw); +// boxstack->update(vw); + + break; + } + case Message::NEW_PICTURE: + { + //Log::getInstance()->log("Control", Log::DEBUG, "TVMedia NEW_PICTURE"); + OsdVector* osdv = dynamic_cast(Osd::getInstance()); + if (osdv) osdv->informPicture(m->tag, reinterpret_cast(m->data)); + break; + } + case Message::NEW_PICTURE_STATIC: + { + //Log::getInstance()->log("Control", Log::DEBUG, "TVMedia NEW_PICTURE %x %x",m->tag,m->parameter); + OsdVector* osdv = dynamic_cast(Osd::getInstance()); + if (osdv) osdv->informPicture(static_cast(m->tag) << 32LL, reinterpret_cast(m->data)); + break; + } + } + } + else + { + /* FIXME + + Instead of sending through the boxstack, implement a more generic MessageReceiver interface + and have potential receivers register with something + When a message needs to be delivered, check if the receiver is still registered, if so, deliver the message + This could all be done using the existing big control mutex to keep it simple + */ + + logger->log("Control", Log::DEBUG, "Sending message to boxstack"); + boxstack->processMessage(m); + } +} + +void Control::handleCommand(int button) +{ + if (isStandby && (button != Input::POWER) + && (button != Input::POWERON) + && (button != Input::POWEROFF)) return; + + if (!connLost && boxstack->handleCommand(button)) return; // don't send to boxstack if connLost + + // command was not handled + + switch(button) + { + case Input::VOLUMEUP: + case Input::VOLUMEDOWN: + { + if (inputMan->handlesVolume()) // CEC volume handler? + { + if (button == Input::VOLUMEDOWN) + inputMan->volumeDown(); + else + inputMan->volumeUp(); + } + else + { + VVolume* v = new VVolume(); + boxstack->add(v); + v->handleCommand(button); // this will draw+show + } + return; + } + case Input::MUTE: + { + if (inputMan->handlesVolume()) + { + inputMan->volumeMute(); + } + else + { + VMute* v = new VMute(); + v->draw(); + boxstack->add(v); + boxstack->update(v); + } + return; + } + case Input::POWER: + { + doStandby(); + return; + } + case Input::POWERON: + { + doPowerOn(); + return; + } + case Input::POWEROFF: + { + doPowerOff(); + return; + } + case Input::OK: + { + // FIXME + if (!connLost) return; // if connLost, handle Input::OK + doFromTheTop(false); + return; + } + case Input::GO: + { + VSleeptimer* sleep = new VSleeptimer(); + boxstack->add(sleep); + sleep->handleCommand(button); // this will draw+show + return; + } + } +} + +/* +void Control::sig1() +{ +#ifdef DEV + Message* m = new Message(); // break into master mutex + m->message = Message::SCREENSHOT; + m->to = this; + postMessage(m); +#endif +} +*/ + +void Control::doStandby() +{ + if (isStandby) + { + doPowerOn(); + } + else + { + doPowerOff(); + } +} + + +void Control::doPowerOn() +{ + if (isStandby) + { + Video::getInstance()->signalOn(); + Led::getInstance()->on(); + InputMan::getInstance()->changePowerState(true); + isStandby = false; + + VConnect* vconnect = new VConnect(); + boxstack->add(vconnect); + vconnect->run(); + } +} + +void Control::doPowerOff() +{ + if (!isStandby) + { + VDR::getInstance()->shutdownVDR(); + boxstack->removeAllExceptWallpaper(); + Video::getInstance()->signalOff(); + boxstack->update(wallpaper); + + VDR::getInstance()->configSave("General", "Last Power State", "Off"); + logger->unsetExternLogger(); + VDR::getInstance()->disconnect(); + Led::getInstance()->off(); + InputMan::getInstance()->changePowerState(false); + isStandby = true; + Sleeptimer::getInstance()->shutdown(); + } +} + +void Control::doFromTheTop(bool which) +{ + if (isStandby) return; + if (which) + { + if (connLost) + { + logger->log("Control", Log::NOTICE, "Connection lost dialog already present"); + return; + } + + logger->log("Control", Log::NOTICE, "Doing connection lost dialog"); + connLost = new VInfo(); + connLost->setSize(360, 200); + connLost->createBuffer(); + if (Video::getInstance()->getFormat() == Video::PAL) + connLost->setPosition(190, 170); + else + connLost->setPosition(180, 120); + connLost->setOneLiner(tr("Connection lost")); + connLost->setDropThrough(); + connLost->setBorderOn(1); + connLost->setTitleBarColour(DrawStyle::DANGER); + connLost->okButton(); + connLost->draw(); + boxstack->add(connLost); + boxstack->update(connLost); + + clearMQInputEvents(); + } + else + { + logger->unsetExternLogger(); + VDR::getInstance()->disconnect(); + boxstack->removeAllExceptWallpaper(); + boxstack->update(wallpaper); + connLost = NULL; + + flushMessageQueue(); + + // at this point, everything should be reset to first-go + + VConnect* vconnect = new VConnect(); + boxstack->add(vconnect); + vconnect->run(); + } +} + +void Control::clearMQInputEvents() +{ + std::lock_guard lg(messageQueueMutex); // Get the lock + + MQueueI i = messages.begin(); + while(i != messages.end()) + { + Message* m = *i; + if (m->message == Message::INPUT_EVENT) + { + delete m; + i = messages.erase(i); + } + else + { + ++i; + } + } +} + +void Control::doReboot() +{ + + logger->unsetExternLogger(); + VDR::getInstance()->disconnect(); + // just kill it... + logger->log("Control", Log::NOTICE, "Reboot"); +#ifndef WIN32 +#ifndef VOMP_HAS_EXIT + // some plattforms, want a proper deinitialisation of their hardware before reboot + Osd::getInstance()->shutdown(); + Audio::getInstance()->shutdown(); + Video::getInstance()->shutdown(); + InputMan::getInstance()->shutdown(); + + reboot(LINUX_REBOOT_CMD_RESTART); + // if reboot is not allowed -> stop + stop(); + + +#else + stop(); + +#ifdef __ANDROID__ + exit(0); +#endif + +#endif +#endif //Would we support this on windows? +} + +void Control::connectionLost() +{ + logger->unsetExternLogger(); + Message* m = new Message(); // break into master mutex + m->message = Message::CONNECTION_LOST; + m->p_to = Message::CONTROL; + postMessage(m); +} + +void Control::buildCrashedBox() +{ + VInfo* crash = new VInfo(); + crash->setSize(360, 250); + crash->createBuffer(); + if (Video::getInstance()->getFormat() == Video::PAL) + crash->setPosition(190, 146); + else + crash->setPosition(180, 96); + crash->setMainText("Oops, vomp crashed.. :(\nPlease report this crash to the author, with as much detail as possible about what you were doing at the time that might have caused the crash."); + crash->setBorderOn(1); + crash->setTitleBarColour(DrawStyle::DANGER); + crash->okButton(); + crash->setExitable(); + crash->draw(); + boxstack->add(crash); + boxstack->update(crash); +} + +int Control::getLangPref(bool subtitle, const char* langcode) +{ + std::vector::iterator itty=langcodes.begin(); + char templangcode[4]; + templangcode[0] = langcode[0]; + templangcode[1] = langcode[1]; + templangcode[2] = langcode[2]; + templangcode[3] = '\0'; + int langpos = 0; + while (itty != langcodes.end()) + { + size_t pos = (*itty).langcode.find(templangcode); + if (pos != std::string::npos) + { + //vector::iterator itty2=langcodes.begin(); + for (unsigned int i = 0; i < langcodes.size(); i++) + { + int pref = 0; + if (subtitle) + pref = langcodes[i].subtitlepref; + else + pref = langcodes[i].audiopref; + if (pref < 0) break; + + if (subtitle) + { + if (langcodes[i].subtitlepref==langpos) return i; + } + else + { + if (langcodes[i].audiopref==langpos) return i; + } + } + break; + } + itty++; + langpos++; + } + return langcodes.size(); //neutral +} + +void Control::doJustConnected(VConnect* vconnect) +{ + I18n::initialize(); + if (!VDR::getInstance()->isConnected()) { connectionLost(); return; } + logger->log("Control", Log::INFO, "Entering doJustConnected"); + + Video* video = Video::getInstance(); + Audio* audio = Audio::getInstance(); + boxstack->remove(vconnect); + + VInfo* vi = new VInfo(); + vi->setSize(400, 200); + vi->createBuffer(); + if (video->getFormat() == Video::PAL) + vi->setPosition(170, 200); + else + vi->setPosition(160, 150); + vi->setOneLiner(tr("Connected, loading config")); + vi->draw(); + boxstack->add(vi); + boxstack->update(vi); + + // FIXME make config system + + VDR* vdr = VDR::getInstance(); + char* config; + + // See if we're supposed to do network logging + config = vdr->configLoad("Advanced", "Network logging"); + if (config && !STRCASECMP(config, "On")) + { + logger->log("Control", Log::INFO, "Turning on network logging"); + logger->setExternLogger(vdr); + } + else + { + logger->unsetExternLogger(); + logger->log("Control", Log::INFO, "Turned off network logging"); + } + if (config) delete[] config; + + config = vdr->configLoad("Advanced", "Skin Name"); + if (config) + { + const char **skinnames=SkinFactory::getSkinNames(); + for (int i=0;isetVisible(true); + else + wallpaper_pict->setVisible(false); + + wallpaper->draw(); + boxstack->update(wallpaper); + } + } + else + { + SkinFactory::InitSkin(0); + } + + // See if config says to override video format (PAL/NTSC) + config = vdr->configLoad("General", "Override Video Format"); + if (config) + { + logger->log("Control", Log::DEBUG, "Override Video Format is present"); + + if ( (!strcmp(config, "PAL") && (video->getFormat() != Video::PAL)) + || (!strcmp(config, "NTSC") && (video->getFormat() != Video::NTSC)) + || (!strcmp(config, "PAL_M") && (video->getFormat() != Video::PAL_M)) + || (!strcmp(config, "NTSC_J") && (video->getFormat() != Video::NTSC_J)) + ) + { + // Oh sheesh, need to switch format. Bye bye TV... + + // Take everything down + boxstack->removeAllExceptWallpaper(); + boxstack->remove(wallpaper); + delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; + + Osd* osd = Osd::getInstance(); +#ifndef __ANDROID__ + osd->shutdown(); +#endif + video->shutdown(); + + inputMan->shutdown(); // need on raspberry shut not do any harm, hopefully + inputMan->init(); // FIXME this breaks badly now + + // Get video and osd back up with the new mode + if (!strcmp(config, "PAL")) + { + logger->log("Control", Log::DEBUG, "Switching to PAL"); + video->init(Video::PAL); + } + else if (!strcmp(config, "NTSC")) + { + logger->log("Control", Log::DEBUG, "Switching to NTSC"); + video->init(Video::NTSC); + } else if (!strcmp(config, "PAL_M")) + { + logger->log("Control", Log::DEBUG, "Switching to PAL_M"); + video->init(Video::PAL_M); + } else if (!strcmp(config, "NTSC_J")) + { + logger->log("Control", Log::DEBUG, "Switching to NTSC_J"); + video->init(Video::NTSC_J); + } + delete[] config; + +#ifndef __ANDROID__ + //we do not init twice + osd->init(); +#endif + + // Put the wallpaper back + doWallpaper(); + + // Re add the vinfo + vi = new VInfo(); + vi->setSize(400, 200); + vi->createBuffer(); + if (video->getFormat() == Video::PAL) + vi->setPosition(170, 200); + else + vi->setPosition(160, 150); + + vi->setOneLiner(tr("Connected, loading config")); + vi->draw(); + boxstack->add(vi); + boxstack->update(vi); + } + else + { + logger->log("Control", Log::DEBUG, "Already in requested mode, or request was not 'PAL' or 'NTSC'"); + } + } + else + { + logger->log("Control", Log::DEBUG, "Phew, no dangerous on-the-fly mode switching to do!"); + } + + // Power off if first boot and config says so + if (firstBoot) + { + firstBoot = false; + + logger->log("Control", Log::DEBUG, "Load power after boot"); + + config = vdr->configLoad("General", "Power After Boot"); + + if (config) + { + if (!STRCASECMP(config, "On")) + { + logger->log("Control", Log::INFO, "Config says Power After Boot = On"); + } + else if (!STRCASECMP(config, "Off")) + { + logger->log("Control", Log::INFO, "Config says Power After Boot = Off"); + doStandby(); + delete[] config; + return; // quit here + } + else if (!STRCASECMP(config, "Last state")) + { + char* lastPowerState = vdr->configLoad("General", "Last Power State"); + if (lastPowerState) + { + if (!STRCASECMP(lastPowerState, "On")) + { + logger->log("Control", Log::INFO, "Config says Last Power State = On"); + } + else if (!STRCASECMP(lastPowerState, "Off")) + { + logger->log("Control", Log::INFO, "Config says Last Power State = Off"); + doStandby(); + delete[] config; + return; // quit here + } + else + { + logger->log("Control", Log::INFO, "Config General/Last Power State not understood"); + } + } + else + { + logger->log("Control", Log::INFO, "Config General/Last Power State not found"); + } + } + else + { + logger->log("Control", Log::INFO, "Config/Power After Boot not understood"); + } + delete[] config; + } + else + { + logger->log("Control", Log::INFO, "Config General/Power After Boot not found"); + } + } + + + // Go S-Video if config says so + + config = vdr->configLoad("TV", "Connection"); + + if (config) + { + if (!STRCASECMP(config, "S-Video")) + { + logger->log("Control", Log::INFO, "Switching to S-Video as Connection=%s", config); + video->setConnection(Video::SVIDEO); + } else if (!STRCASECMP(config, "HDMI")) + { + logger->log("Control", Log::INFO, "Switching to HDMI as Connection=%s", config); + video->setConnection(Video::HDMI); + } else if (!STRCASECMP(config, "HDMI3D")) + { + logger->log("Control", Log::INFO, "Switching to HDMI3D as Connection=%s", config); + video->setConnection(Video::HDMI3D); + } + else + { + logger->log("Control", Log::INFO, "Switching to RGB/Composite as Connection=%s", config); + video->setConnection(Video::COMPOSITERGB); + } + delete[] config; + } + else + { + logger->log("Control", Log::INFO, "Config TV/S-Video not found"); + } + + // Set to shutdown VDR if config says + + config = vdr->configLoad("General", "VDR shutdown"); + if (config) + { + if (!STRCASECMP(config, "On")) + { + logger->log("Control", Log::INFO, "Shutdown VDR when shutting down vomp"); + vdr->setVDRShutdown(true); + } + else if (!STRCASECMP(config, "Off")) + { + logger->log("Control", Log::INFO, "Shutdown only vomp"); + vdr->setVDRShutdown(false); + } + } + else + { + logger->log("Control", Log::INFO, "Default shutdown only vomp"); + vdr->setVDRShutdown(false); // Default + } + + // Get TV aspect ratio + + config = vdr->configLoad("TV", "Aspect"); + if (config) + { + if (!STRCASECMP(config, "16:9")) + { + logger->log("Control", Log::INFO, "/// Switching to TV aspect 16:9"); + video->setTVsize(Video::ASPECT16X9); + } + else + { + logger->log("Control", Log::INFO, "/// Switching to TV aspect 4:3"); + video->setTVsize(Video::ASPECT4X3); + } + delete[] config; + } + else + { + logger->log("Control", Log::INFO, "Config TV/Aspect type not found, going 4:3"); + video->setTVsize(Video::ASPECT4X3); + } + + config = vdr->configLoad("TV", "Widemode"); + if (config) + { + if (!STRCASECMP(config, "Letterbox")) + { + logger->log("Control", Log::INFO, "Setting letterbox mode"); + video->setMode(Video::LETTERBOX); + } + else + { + logger->log("Control", Log::INFO, "Setting chop-sides mode"); + video->setMode(Video::NORMAL); + } + delete[] config; + } + else + { +#ifdef __ANDROID__ + logger->log("Control", Log::INFO, "Config TV/Widemode not found, Setting letterbox mode"); + video->setMode(Video::LETTERBOX); +#else + logger->log("Control", Log::INFO, "Config TV/Widemode not found, Setting chop-sides mode"); + video->setMode(Video::NORMAL); +#endif + } + + config = vdr->configLoad("Advanced", "TCP receive window"); + if (config) + { + size_t newTCPsize = atoi(config); + delete[] config; + + logger->log("Control", Log::INFO, "Setting TCP window size %i", newTCPsize); + vdr->setReceiveWindow(newTCPsize); + } + else + { + logger->log("Control", Log::INFO, "TCP window size not found, setting 2048"); + if (DEFAULT_TCP_WINDOWSIZE) vdr->setReceiveWindow(2048); // Default + } + + config = vdr->configLoad("Advanced", "Font Name"); + if (config) + { + Osd::getInstance()->setFont(config); + logger->log("Control", Log::INFO, "Setting Font to %s", config); + delete[] config; + + } + + + // Set recording list type + +#ifdef ADVANCED_MENUES + config = vdr->configLoad("Advanced", "Menu type"); + + if (config) + { + if (!STRCASECMP(config, "Advanced")) + { + logger->log("Control", Log::INFO, "Switching to Advanced menu"); + advMenus = true; + } + else + { + logger->log("Control", Log::INFO, "Switching to Classic menu"); + advMenus = false; + } + delete[] config; + } + else + { + logger->log("Control", Log::INFO, "Config General/menu type not found"); + advMenus = true; + } +#endif + + config = vdr->configLoad("Advanced", "Disable WOL"); + if (config) + { + if (!STRCASECMP(config, "Yes")) + { + logger->log("Control", Log::INFO, "Config says disable WOL"); + Wol::getInstance()->setEnabled(false); + } + else + { + logger->log("Control", Log::INFO, "Config says enable WOL"); + Wol::getInstance()->setEnabled(true); + } + + delete[] config; + } + else + { + logger->log("Control", Log::INFO, "By default, enable WOL"); + Wol::getInstance()->setEnabled(true); + } + /* device dependend config */ + audio->loadOptionsFromServer(vdr); + video->loadOptionsFromServer(vdr); + inputMan->loadOptionsFromServer(vdr); + + video->executePendingModeChanges(); + // config done + + // Save power state = on + + vdr->configSave("General", "Last Power State", "On"); + + // Make sure connection didn't die + if (!vdr->isConnected()) + { + Control::getInstance()->connectionLost(); + } + else + { + boxstack->remove(vi); + + VWelcome* vw = new VWelcome(); + vw->draw(); + boxstack->add(vw); + boxstack->update(vw); + + // Enter pre-keys here +// handleCommand(Input::OK); +// handleCommand(Input::THREE); +// handleCommand(Input::SIX); +// handleCommand(Input::OK); +// handleCommand(Input::UP); +// handleCommand(Input::PLAY); +// handleCommand(Input::DOWN); +// handleCommand(Input::DOWN); +// handleCommand(Input::DOWN); +// handleCommand(Input::RIGHT); +// handleCommand(Input::RED); + } +} diff --git a/control.h b/control.h new file mode 100644 index 0000000..6ed82be --- /dev/null +++ b/control.h @@ -0,0 +1,113 @@ +/* + Copyright 2004-2020 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP. If not, see . +*/ + +#ifndef COMMAND_H +#define COMMAND_H + +#ifndef WIN32 +#include // for reboot +#include +#include +#endif + +#include +#ifndef WIN32 +#include // why? +#endif + +#include +#include + +#include "defines.h" +#include "messagequeue.h" + +class VConnect; +class Message; +class InputMan; +class Boxx; +class BoxStack; +class Log; +class VInfo; +class WJpeg; + +struct ASLPref +{ + std::string langcode; + int audiopref; + int subtitlepref; +}; + +typedef std::vector ASLPrefList; + +class Control : public MessageQueue +{ + public: + Control(); + ~Control(); + static Control* getInstance(); + + int init(bool crashed = false); + int shutdown(); + void run(); + void stop(); + void doReboot(); + void connectionLost(); + + void setAdvMenus(bool adv) { advMenus = adv; }; + bool isAdvMenus() { return advMenus; }; + int getLangPref(bool subtitle,const char* langcode); + void setSubDefault(int subon) { subdefault = subon; }; + int getSubDefault() { return subdefault; }; + ASLPrefList &getASLList() { return langcodes; }; + + private: + void handleCommand(int); + void doStandby(); + void doPowerOn(); + void doPowerOff(); + void doJustConnected(VConnect* vconnect); + void doWallpaper(); + void doFromTheTop(bool which); // true - show vinfo,wait. false - del vinfo,restart + void buildCrashedBox(); +// void sig1(); + void clearMQInputEvents(); + + static Control* instance; + + Log* logger; + BoxStack* boxstack; + InputMan* inputMan; + + bool initted{}; + bool irun{}; + bool isStandby{}; + bool firstBoot{true}; + Boxx* wallpaper{}; + WJpeg* wallpaper_pict{}; + VInfo* connLost{}; + bool crashed{}; + + bool advMenus{}; + ASLPrefList langcodes; + int subdefault; + + void processMessage(Message* m); +}; + +#endif diff --git a/demuxerts.cc b/demuxerts.cc index 7f2d4c1..b7059c5 100644 --- a/demuxerts.cc +++ b/demuxerts.cc @@ -533,14 +533,14 @@ int DemuxerTS::processTS(UCHAR* buf) bool dolby=false; int selected=-1; int prefered=-1; - Command* command = Command::getInstance(); + Control* control = Control::getInstance(); if (channelinfo.numDPids > 0 && Audio::getInstance()->maysupportAc3()) { ULONG j = 0; while (j < channelinfo.numDPids) { - int newpref = command->getLangPref(false, channelinfo.dpids[j].desc); + int newpref = control->getLangPref(false, channelinfo.dpids[j].desc); if (Audio::getInstance()->streamTypeSupported(channelinfo.dpids[j].type) && (prefered < 0 || newpref < prefered)) { @@ -557,7 +557,7 @@ int DemuxerTS::processTS(UCHAR* buf) ULONG j = 0; while (j < channelinfo.numAPids) { - int newpref = command->getLangPref(false, channelinfo.apids[j].desc); + int newpref = control->getLangPref(false, channelinfo.apids[j].desc); if (Audio::getInstance()->streamTypeSupported(channelinfo.apids[j].type) && (prefered < 0 || newpref < prefered)) { @@ -585,7 +585,7 @@ int DemuxerTS::processTS(UCHAR* buf) ULONG j = 0; while (j < channelinfo.numSPids) { - int newpref = command->getLangPref(true, channelinfo.spids[j].desc); + int newpref = control->getLangPref(true, channelinfo.spids[j].desc); if ( (prefered < 0 || newpref < prefered)) { selected = j; diff --git a/event.cc b/event.cc index 930605c..b11547b 100644 --- a/event.cc +++ b/event.cc @@ -20,7 +20,7 @@ #include "event.h" #include "log.h" -#include "command.h" +#include "control.h" #include "movieinfo.h" #include "seriesinfo.h" #include "vdr.h" @@ -44,7 +44,7 @@ void Event::loadinfos(UINT channelid) id, channelid, movieID, seriesID, episodeID); } - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + if (!vdr->isConnected()) Control::getInstance()->connectionLost(); if (movieID != 0) { @@ -57,5 +57,5 @@ void Event::loadinfos(UINT channelid) Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper SeriesInfo"); } - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + if (!vdr->isConnected()) Control::getInstance()->connectionLost(); } diff --git a/language-data.h b/language-data.h index 528f883..e3b1429 100644 --- a/language-data.h +++ b/language-data.h @@ -783,7 +783,7 @@ const I18n::tI18nPhrase I18n::Phrases[] = "Verbinding mislukt", "55", }, - // Command + // Control { "Connected, loading config", "Verbunden, lade Einstellungen", "Ansluten, laddar konfigurering", diff --git a/main.cc b/main.cc index aca7fa1..3453100 100644 --- a/main.cc +++ b/main.cc @@ -43,7 +43,7 @@ #include "timers.h" #include "vdr.h" #include "boxstack.h" -#include "command.h" +#include "control.h" #include "inputman.h" #include "wol.h" #include "vsleeptimer.h" @@ -80,7 +80,7 @@ Led* led; Osd* osd; Timers* timers; BoxStack* boxstack; -Command* command; +Control* control; VDR* vdr; Video* video; Audio* audio; @@ -141,11 +141,11 @@ int main(int argc, char** argv) video = new Video_TYPE(); boxstack = new BoxStack(); - command = new Command(); + control = new Control(); wol = new Wol(); sleeptimer = new Sleeptimer(); - if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !boxstack || !command || !wol || !sleeptimer) + if (!logger || !timers || !inputMan || !led || !osd || !video || !audio || !boxstack || !control || !wol || !sleeptimer) { printf("Could not create objects. Memory problems?\n"); shutdown(1); @@ -323,14 +323,14 @@ int main(int argc, char** argv) shutdown(1); } - success = command->init(crashed); + success = control->init(crashed); if (success) { - logger->log("Core", Log::INFO, "Command module initialised"); + logger->log("Core", Log::INFO, "Control module initialised"); } else { - logger->log("Core", Log::EMERG, "Command module failed to initialise"); + logger->log("Core", Log::EMERG, "Control module failed to initialise"); shutdown(1); } @@ -341,7 +341,7 @@ int main(int argc, char** argv) // Run main loop --------------------------------------------------------------------------------------------------- // Ok, all major device components and other bits are loaded and ready - command->run(); + control->run(); // When that returns quit ------------------------------------------------------------------------------------------ shutdown(0); @@ -365,7 +365,7 @@ void threadSignalReceiverFunction() logger->log("Core", Log::NOTICE, "Signal received: %i", sig); - if ((sig == SIGINT) || (sig == SIGTERM)) command->stop(); + if ((sig == SIGINT) || (sig == SIGTERM)) control->stop(); } } @@ -382,13 +382,13 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "BoxStack module shut down"); } - // FIXME, send a del all to boxstack first, then get rid of it after command? - if (command) // shut down command here in case views have posted messages + // FIXME, send a del all to boxstack first, then get rid of it after control? + if (control) // shut down control here in case views have posted messages { - command->shutdown(); - delete command; - command = NULL; - logger->log("Core", Log::NOTICE, "Command module shut down"); + control->shutdown(); + delete control; + control = NULL; + logger->log("Core", Log::NOTICE, "Control module shut down"); } if (vdr) diff --git a/message.h b/message.h index e362ec2..9b442f5 100644 --- a/message.h +++ b/message.h @@ -94,7 +94,3 @@ class Message }; #endif - -// FIXME idea - instead of always having to specify a real pointer in the "to" variable (meaning clients may have to -// run Command::getInstance() for e.g.), how about having some constant values for well known targets. Then -// clients may not need the #include "command.h" diff --git a/objects.mk b/objects.mk index ee66ea4..88aedcf 100644 --- a/objects.mk +++ b/objects.mk @@ -1,4 +1,4 @@ -OBJ_COMMON = command.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o \ +OBJ_COMMON = control.o thread.o timers.o i18n.o udp4.o udp6.o vdpc.o tcp.o \ message.o messagequeue.o wol.o audio.o video.o log.o \ vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o \ directory.o mark.o option.o vfeed.o afeed.o \ diff --git a/osdopengl.cc b/osdopengl.cc index 2b18a35..2ad47c5 100644 --- a/osdopengl.cc +++ b/osdopengl.cc @@ -20,7 +20,7 @@ #include "videoomx.h" #include "surfaceopengl.h" #include "message.h" -#include "command.h" +#include "control.h" #include "osdopengl.h" diff --git a/osdvector.cc b/osdvector.cc index b0bd6e1..c09bba4 100644 --- a/osdvector.cc +++ b/osdvector.cc @@ -21,7 +21,7 @@ #include "surfacevector.h" #include "vdr.h" #include "vdrresponsepacket.h" -#include "command.h" +#include "control.h" #include "message.h" // The next section is activated, if the magick++ PictureReader is provided, it should be available for many POSIX platforms diff --git a/osdvector.h b/osdvector.h index a901cda..1cbaae7 100644 --- a/osdvector.h +++ b/osdvector.h @@ -247,7 +247,7 @@ class OsdVector : public Osd virtual void getScreenSize(int &width, int &height)=0; virtual void getRealScreenSize(int &width, int &height)=0; - // should be only called from command thread + // should be only called from control thread void informPicture(LoadIndex index, ImageIndex i_index); @@ -312,7 +312,7 @@ class OsdVector : public Osd bool processReceivedPictures(); - // should be called from command thread + // should be called from control thread void receivePicture(VDR_ResponsePacket *vresp); void addStaticImage(unsigned int id); diff --git a/osdwinpixel.cc b/osdwinpixel.cc index 1698332..2b69778 100644 --- a/osdwinpixel.cc +++ b/osdwinpixel.cc @@ -27,7 +27,7 @@ #include "message.h" -#include "command.h" +#include "control.h" diff --git a/osdwinvector.cc b/osdwinvector.cc index 5e86c4a..dd48b6c 100644 --- a/osdwinvector.cc +++ b/osdwinvector.cc @@ -1246,7 +1246,7 @@ void OsdWinVector::createPicture(struct PictureInfo& pict_inf) m->message = Message::NEW_PICTURE_STATIC; m->tag = pict_inf.lindex >> 32LL; } - MessageQueue::getInstance()->postMessage(m); // inform command about new picture + MessageQueue::getInstance()->postMessage(m); // inform control about new picture } else { pict_inf.decoder->freeReference(pict_inf.reference); diff --git a/playervideolive.cc b/playervideolive.cc index 06d0dfc..b4111c0 100644 --- a/playervideolive.cc +++ b/playervideolive.cc @@ -35,7 +35,7 @@ #include "channel.h" #include "dvbsubtitles.h" #include "osdreceiver.h" -#include "command.h" +#include "control.h" #include "playervideolive.h" @@ -735,14 +735,14 @@ void PlayerVideoLive::threadMethod() int selected = -1; int prefered = -1; - Command* command = Command::getInstance(); + Control* control = Control::getInstance(); if (chan->numDPids > 0 && audio->maysupportAc3()) { ULONG j = 0; while (j < chan->numDPids) { - int newpref = command->getLangPref(false, chan->dpids[j].desc); + int newpref = control->getLangPref(false, chan->dpids[j].desc); if (Audio::getInstance()->streamTypeSupported(chan->dpids[j].type) && (prefered < 0 || newpref < prefered)) { selected = j; @@ -758,7 +758,7 @@ void PlayerVideoLive::threadMethod() ULONG j = 0; while (j < chan->numAPids) { - int newpref = command->getLangPref(false, chan->apids[j].desc); + int newpref = control->getLangPref(false, chan->apids[j].desc); if (Audio::getInstance()->streamTypeSupported(chan->apids[j].type) && (prefered < 0 || newpref < prefered)) { selected = j; @@ -798,7 +798,7 @@ void PlayerVideoLive::threadMethod() ULONG j = 0; while (j < chan->numSPids) { - int newpref = command->getLangPref(true, chan->spids[j].desc); + int newpref = control->getLangPref(true, chan->spids[j].desc); if ((prefered < 0 || newpref < prefered)) { selected = j; @@ -816,7 +816,7 @@ void PlayerVideoLive::threadMethod() { firstStart = false; - if (command->getSubDefault()) + if (control->getSubDefault()) turnSubtitlesOn(true); else turnSubtitlesOn(false); diff --git a/playervideorec.cc b/playervideorec.cc index 74e22f2..96b7d78 100644 --- a/playervideorec.cc +++ b/playervideorec.cc @@ -91,7 +91,7 @@ int PlayerVideoRec::init(bool p_isPesRecording, double framespersecond) video->blank(); audio->stop(); - if (Command::getInstance()->getSubDefault()) + if (Control::getInstance()->getSubDefault()) turnSubtitlesOn(true); else turnSubtitlesOn(false); diff --git a/recording.cc b/recording.cc index 908f4ee..2198568 100644 --- a/recording.cc +++ b/recording.cc @@ -23,7 +23,7 @@ #include "log.h" #include "demuxer.h" #include "demuxerts.h" -#include "command.h" +#include "control.h" #include "seriesinfo.h" #include "movieinfo.h" @@ -109,7 +109,7 @@ void Recording::loadRecInfo() recInfo = vdr->getRecInfo(fileName); Log::getInstance()->log("Recording", Log::DEBUG, "Recording has loaded recInfo %p", recInfo); - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + if (!vdr->isConnected()) Control::getInstance()->connectionLost(); if (movieInfo) delete movieInfo; if (seriesInfo) delete seriesInfo; @@ -122,7 +122,7 @@ void Recording::loadRecInfo() Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d", movieID, seriesID, episodeID); - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + if (!vdr->isConnected()) Control::getInstance()->connectionLost(); if (movieID != 0) { @@ -136,7 +136,7 @@ void Recording::loadRecInfo() } - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + if (!vdr->isConnected()) Control::getInstance()->connectionLost(); } @@ -155,7 +155,7 @@ void Recording::dropRecInfo() void Recording::loadMarks() { markList = vdr->getMarks(fileName); - if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost(); + if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost(); } bool Recording::isRadio(bool &h264) @@ -186,7 +186,7 @@ bool Recording::isRadio(bool &h264) free(buffer); vdr->stopStreaming(); - if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost(); + if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost(); Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo); diff --git a/vconnect.cc b/vconnect.cc index a13d903..2874e02 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -20,7 +20,7 @@ #include "defines.h" #include "video.h" #include "colour.h" -#include "command.h" +#include "control.h" #include "i18n.h" #include "boxstack.h" #include "message.h" @@ -163,8 +163,8 @@ void VConnect::threadMethod() logger->log("VConnect", Log::DEBUG, "Connected ok, doing login"); unsigned int version_server_min, version_server_max, version_client; int subtitles; - success = vdr->doLogin(&version_server_min, &version_server_max, &version_client, Command::getInstance()->getASLList(), subtitles); - Command::getInstance()->setSubDefault(subtitles); + success = vdr->doLogin(&version_server_min, &version_server_max, &version_client, Control::getInstance()->getASLList(), subtitles); + Control::getInstance()->setSubDefault(subtitles); if (!success) { diff --git a/vdr.cc b/vdr.cc index d2d1dc0..632a6b8 100644 --- a/vdr.cc +++ b/vdr.cc @@ -26,7 +26,7 @@ #include "wol.h" #include "vdrrequestpacket.h" #include "vdrresponsepacket.h" -#include "command.h" +#include "control.h" #ifdef VOMP_MEDIAPLAYER #include "media.h" #include "mediaprovider.h" @@ -442,10 +442,10 @@ void VDR::connectionDied() } } edMutex.unlock(); - // Ok, all event receviers should be dealt with. just in case there weren't any, inform command + // Ok, all event receviers should be dealt with. just in case there weren't any, inform control logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied"); - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); } bool VDR::ed_cb_find(EDReceiver* edr, void* userTag) @@ -1374,7 +1374,7 @@ MediaList* VDR::getMediaList(const MediaURI * root) SerializeBuffer* vresp = doRequestResponse(vrp,request.command); if (!vresp) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return NULL; } @@ -1406,7 +1406,7 @@ int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, } SerializeBuffer* vresp = doRequestResponse(vrp,request.command); if (!vresp) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return -1; } ULONG flags=0; @@ -1434,7 +1434,7 @@ int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* a } SerializeBuffer* vresp = doRequestResponse(vrp,request.command); if (!vresp) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return -1; } @@ -1463,7 +1463,7 @@ int VDR::getMediaInfo(ULONG channel, MediaInfo * result) { } SerializeBuffer* vresp = doRequestResponse(vrp,request.command); if (!vresp) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return -1; } @@ -1491,7 +1491,7 @@ int VDR::closeMediaChannel(ULONG channel) { } SerializeBuffer* vresp = doRequestResponse(vrp,request.command); if (!vresp) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return -1; } ULONG flags; diff --git a/vdr.h b/vdr.h index a7bc8d0..ad00955 100644 --- a/vdr.h +++ b/vdr.h @@ -41,7 +41,7 @@ #include "eventdispatcher.h" #include "i18n.h" #include "log.h" -#include "command.h" +#include "control.h" #include "tcp.h" class RecInfo; diff --git a/vepgsettimer.cc b/vepgsettimer.cc index a941293..b6f74b3 100644 --- a/vepgsettimer.cc +++ b/vepgsettimer.cc @@ -26,7 +26,7 @@ #include "log.h" #include "vinfo.h" #include "message.h" -#include "command.h" +#include "control.h" #include "messagequeue.h" #include "video.h" #include "input.h" @@ -251,7 +251,7 @@ void VEpgSetTimer::doit() if (!vdr->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); } if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success"); diff --git a/vepgsummary.cc b/vepgsummary.cc index d56dae8..4262dc9 100644 --- a/vepgsummary.cc +++ b/vepgsummary.cc @@ -27,7 +27,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" -#include "command.h" +#include "control.h" #include "boxstack.h" #include "event.h" #include "channel.h" diff --git a/vmediaview.cc b/vmediaview.cc index 6aca5b8..f1fff11 100644 --- a/vmediaview.cc +++ b/vmediaview.cc @@ -35,7 +35,7 @@ #include "vinfo.h" #include "i18n.h" #include "message.h" -#include "command.h" +#include "control.h" #include "mediaoptions.h" #include "mediaplayer.h" #include "log.h" @@ -761,7 +761,7 @@ void VMediaView::processMessage(Message* m) player->shutdown(); player=NULL; } - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); break; } } diff --git a/vopts.cc b/vopts.cc index 20b9be9..95c5fbf 100644 --- a/vopts.cc +++ b/vopts.cc @@ -32,7 +32,7 @@ #include "vdr.h" #include "messagequeue.h" #include "message.h" -#include "command.h" +#include "control.h" #include "staticartwork.h" #ifdef VOMP_PLATTFORM_MVP @@ -464,12 +464,12 @@ void VOpts::doSave() if (options[i]->userSetChoice == 1) { Log::getInstance()->log("Options", Log::DEBUG, "Setting classic menu"); - Command::getInstance()->setAdvMenus(false); + Control::getInstance()->setAdvMenus(false); } else { Log::getInstance()->log("Options", Log::DEBUG, "Setting advanced menu"); - Command::getInstance()->setAdvMenus(true); + Control::getInstance()->setAdvMenus(true); } break; } diff --git a/vradiorec.cc b/vradiorec.cc index deacb62..71d243c 100644 --- a/vradiorec.cc +++ b/vradiorec.cc @@ -17,7 +17,7 @@ along with VOMP. If not, see . */ -#include "command.h" +#include "control.h" #include "osd.h" #include "wsymbol.h" #include "recording.h" @@ -46,7 +46,7 @@ VRadioRec::VRadioRec(Recording* rec) startMargin = 0; endMargin = 0; - player = new PlayerRadioRec(Command::getInstance(), this); + player = new PlayerRadioRec(Control::getInstance(), this); char* cstartMargin = vdr->configLoad("Timers", "Start margin"); char* cendMargin = vdr->configLoad("Timers", "End margin"); @@ -148,7 +148,7 @@ void VRadioRec::go(bool resume) if (!vdr->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } @@ -313,7 +313,7 @@ void VRadioRec::processMessage(Message* m) { case PlayerRadioRec::CONNECTION_LOST: // connection lost detected { - // I can't handle this, send it to command + // I can't handle this, send it to control Message* m2 = new Message(); m2->p_to = Message::CONTROL; m2->message = Message::CONNECTION_LOST; @@ -344,7 +344,7 @@ void VRadioRec::stopPlay() playing = false; - if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } + if (!vdr->isConnected()) { Control::getInstance()->connectionLost(); return; } Log::getInstance()->log("VRadioRec", Log::DEBUG, "Post stopPlay"); } diff --git a/vrecordinglist.cc b/vrecordinglist.cc index 64641b9..cbbfe9b 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -33,7 +33,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" -#include "command.h" +#include "control.h" #include "vinfo.h" #include "log.h" @@ -109,7 +109,7 @@ void VRecordingList::doDeleteSelected() int success = recman->deleteRecording(toDelete); if (!VDR::getInstance()->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } @@ -149,7 +149,7 @@ void VRecordingList::doMoveRecording(Directory* toDir) int success = recman->moveRecording(toMove, toDir); if (!VDR::getInstance()->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } diff --git a/vrecordinglistadvanced.cc b/vrecordinglistadvanced.cc index 9ed10d8..e557029 100644 --- a/vrecordinglistadvanced.cc +++ b/vrecordinglistadvanced.cc @@ -35,7 +35,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" -#include "command.h" +#include "control.h" #include "vinfo.h" #include "log.h" #include "movieinfo.h" diff --git a/vrecordinglistclassic.cc b/vrecordinglistclassic.cc index b577596..fc1b7fa 100644 --- a/vrecordinglistclassic.cc +++ b/vrecordinglistclassic.cc @@ -31,7 +31,7 @@ #include "colour.h" #include "video.h" #include "i18n.h" -#include "command.h" +#include "control.h" #include "vinfo.h" #include "log.h" diff --git a/vtimerlist.cc b/vtimerlist.cc index 59bdd21..4b35947 100644 --- a/vtimerlist.cc +++ b/vtimerlist.cc @@ -29,7 +29,7 @@ #include "video.h" #include "i18n.h" #include "vtimeredit.h" -#include "command.h" +#include "control.h" #include "boxstack.h" #include "vinfo.h" #include "log.h" @@ -342,7 +342,7 @@ void VTimerList::processMessage(Message* m) ULONG retval = VDR::getInstance()->deleteTimer(recTimer); - if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; } + if (!VDR::getInstance()->isConnected()) { Control::getInstance()->connectionLost(); return; } Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval); if (retval != 10) diff --git a/vvideolivetv.cc b/vvideolivetv.cc index b7bd885..2f3bb74 100644 --- a/vvideolivetv.cc +++ b/vvideolivetv.cc @@ -29,7 +29,7 @@ #include "boxstack.h" #include "colour.h" #include "osd.h" -#include "command.h" +#include "control.h" #include "i18n.h" #include "wtextbox.h" #include "input.h" @@ -88,12 +88,12 @@ VVideoLiveTV::VVideoLiveTV(ChannelList* tchanList, ULONG initialChannelNumber, V if ((*chanList)[currentChannelIndex]->type == VDR::VIDEO) { streamType = VDR::VIDEO; - player = new PlayerVideoLive(Command::getInstance(), this, this, chanList); + player = new PlayerVideoLive(Control::getInstance(), this, this, chanList); } else { streamType = VDR::RADIO; - player = new PlayerRadioLive(Command::getInstance(), this, chanList); + player = new PlayerRadioLive(Control::getInstance(), this, chanList); } player->init(); @@ -699,7 +699,7 @@ void VVideoLiveTV::doEPG() { if (osd.getVisible()) clearScreen(); - if (!Command::getInstance()->isAdvMenus()) + if (!Control::getInstance()->isAdvMenus()) { VEpg* vepg = new VEpg(this, currentChannelIndex, chanList); vepg->draw(); @@ -1119,7 +1119,7 @@ void VVideoLiveTV::processMessage(Message* m) case PlayerVideoLive::CONNECTION_LOST: // connection lost detected { Log::getInstance()->log("VVideoLiveTV", Log::DEBUG, "Received connection lost from player"); - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); break; } diff --git a/vvideomedia.cc b/vvideomedia.cc index 13ffe3c..03d8558 100644 --- a/vvideomedia.cc +++ b/vvideomedia.cc @@ -368,7 +368,7 @@ void VVideoMedia::processMessage(Message* m) { case PlayerMedia::CONNECTION_LOST: // connection lost detected { - // I can't handle this, send it to command + // I can't handle this, send it to control Message* m2 = new Message(); m2->p_to = Message::CONTROL; m2->message = Message::CONNECTION_LOST; diff --git a/vvideorec.cc b/vvideorec.cc index 792f318..0be40e1 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -19,7 +19,7 @@ #include -#include "command.h" +#include "control.h" #include "osd.h" #include "wsymbol.h" #include "audio.h" @@ -56,7 +56,7 @@ VVideoRec::VVideoRec(Recording* rec, bool ish264) video->seth264mode(ish264); - player = new PlayerVideoRec(Command::getInstance(), this, this); + player = new PlayerVideoRec(Control::getInstance(), this, this); player->init(myRec->IsPesRecording,myRec->recInfo->fps); char* cstartMargin = vdr->configLoad("Timers", "Start margin"); @@ -181,7 +181,7 @@ void VVideoRec::go(bool resume) if (!vdr->isConnected()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } @@ -520,7 +520,7 @@ void VVideoRec::processMessage(Message* m) { case PlayerVideoRec::CONNECTION_LOST: // connection lost detected { - // I can't handle this, send it to command + // I can't handle this, send it to control Message* m2 = new Message(); m2->p_to = Message::CONTROL; m2->message = Message::CONNECTION_LOST; @@ -611,7 +611,7 @@ void VVideoRec::stopPlay() playing = false; - if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } + if (!vdr->isConnected()) { Control::getInstance()->connectionLost(); return; } Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay"); } diff --git a/vwelcome.cc b/vwelcome.cc index 4cfaa24..dc3655b 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -25,7 +25,7 @@ #include "vrecordinglistclassic.h" #include "vrecordinglistadvanced.h" #include "vtimerlist.h" -#include "command.h" +#include "control.h" #include "message.h" #include "colour.h" #include "video.h" @@ -235,7 +235,7 @@ int VWelcome::handleCommand(int command) } case Input::SEVEN: { - Command::getInstance()->doReboot(); + Control::getInstance()->doReboot(); return 2; } case Input::OK: @@ -273,7 +273,7 @@ int VWelcome::handleCommand(int command) } else if (option == 7) { - Command::getInstance()->doReboot(); + Control::getInstance()->doReboot(); return 2; } return 2; // never gets here @@ -315,7 +315,7 @@ void VWelcome::doChannelsList() } else { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); } } @@ -334,14 +334,14 @@ void VWelcome::doRadioList() } else { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); } } void VWelcome::doRecordingsList() { VRecordingList* vrec; - if (Command::getInstance()->isAdvMenus()) + if (Control::getInstance()->isAdvMenus()) vrec = new VRecordingListAdvanced(); else vrec = new VRecordingListClassic(); @@ -352,7 +352,7 @@ void VWelcome::doRecordingsList() if (!vrec->load()) { - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); } } @@ -369,7 +369,7 @@ void VWelcome::doTimersList() if (!vtl->load()) { delete vtl; - Command::getInstance()->connectionLost(); + Control::getInstance()->connectionLost(); return; } diff --git a/winmain.cc b/winmain.cc index 631c70c..726eb25 100644 --- a/winmain.cc +++ b/winmain.cc @@ -46,7 +46,7 @@ #include "osdwinvector.h" #endif #include "boxstack.h" -#include "command.h" +#include "control.h" #include "wol.h" #include "vsleeptimer.h" #include "messagequeue.h" @@ -63,7 +63,7 @@ Led* led; Osd* osd; Timers* timers; BoxStack* boxstack; -Command* command; +Control* control; VDR* vdr; Video* video; Audio* audio; @@ -110,9 +110,9 @@ int getClockRealTime(struct timespec *tp){ return 0; } -DWORD WINAPI commandthreadStart(void *arg) +DWORD WINAPI controlthreadStart(void *arg) { - command->run(); + control->run(); return 0; } @@ -170,11 +170,11 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd video = new VideoWin(); audio = new AudioWin(); boxstack = new BoxStack(); - command = new Command(); + control = new Control(); wol = new Wol(); sleeptimer = new Sleeptimer(); - if (!logger || !remote || !led || !osd || !video || !audio || !boxstack || !command || !sleeptimer) + if (!logger || !remote || !led || !osd || !video || !audio || !boxstack || !control || !sleeptimer) { ERROR_MSG("Could not create objects. Memory problems?\n"); shutdown(1); @@ -182,7 +182,7 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd return 0; } - messageQueue = command; + messageQueue = control; // Get logging module started -------------------------------------------------------------------------------------- @@ -311,14 +311,14 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd return 0; } - success = command->init(); + success = control->init(); if (success) { - logger->log("Core", Log::INFO, "Command module initialised"); + logger->log("Core", Log::INFO, "Control module initialised"); } else { - logger->log("Core", Log::EMERG, "Command module failed to initialise"); + logger->log("Core", Log::EMERG, "Control module failed to initialise"); shutdown(1); WSACleanup(); return 0; @@ -333,20 +333,20 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd // Ok, all major device components and other bits are loaded and ready lastmousemove=timeGetTime(); - HANDLE commandthread; - commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, + HANDLE controlthread; + controlthread= CreateThread(NULL, 0, controlthreadStart, NULL,0, NULL); MSG message; message.message=WM_NULL; bool run=true; - while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) { + while(run && WaitForSingleObject(controlthread,0)==WAIT_TIMEOUT) { if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) { if (TranslateAccelerator(win_main,acc,&message)==NULL) { TranslateMessage(&message); DispatchMessage(&message); switch (message.message) { case WM_QUIT: - run=false; //TODO post exit to command Messages + run=false; //TODO post exit to control Messages }; } } else { @@ -356,7 +356,7 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd } } // When that returns quit ------------------------------------------------------------------------------------------ - WaitForSingleObject(commandthread,INFINITE); + WaitForSingleObject(controlthread,INFINITE); shutdown(0); WSACleanup(); if (user32dll) FreeModule(user32dll); @@ -567,9 +567,9 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) switch (msg) { case WM_DESTROY: { - //TODO: call command + //TODO: call control logger->log("Core", Log::NOTICE, "Window closed, shutting down..."); - command->stop(); + control->stop(); PostQuitMessage(0); }break; case WM_SIZING: { @@ -837,11 +837,11 @@ void shutdown(int code) logger->log("Core", Log::NOTICE, "BoxStack module shut down"); } - if (command) // shut down command here in case views have posted messages + if (control) // shut down control here in case views have posted messages { - command->shutdown(); - delete command; - logger->log("Core", Log::NOTICE, "Command module shut down"); + control->shutdown(); + delete control; + logger->log("Core", Log::NOTICE, "Control module shut down"); } if (vdr) diff --git a/wremoteconfig.cc b/wremoteconfig.cc index 24e032c..fa5a13f 100644 --- a/wremoteconfig.cc +++ b/wremoteconfig.cc @@ -172,7 +172,7 @@ void WRemoteConfig::doSave() m->message = Message::CHANGED_REMOTECONTROL; m->to = parent; m->parameter = 0; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); } */ @@ -250,7 +250,7 @@ int WRemoteConfig::handleCommand(int command) m->message = Message::CLOSE_ME; m->from = this; m->to = viewman; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); return 2; */ } diff --git a/wwinaudiofilter.cc b/wwinaudiofilter.cc index bfa48a2..9e1737c 100644 --- a/wwinaudiofilter.cc +++ b/wwinaudiofilter.cc @@ -170,7 +170,7 @@ void WWinAudioFilter::doSave() m->message = Message::CHANGED_DEVICEOPTIONS; m->to = parent; m->parameter = 0; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); }*/ diff --git a/wwinmp3audiofilter.cc b/wwinmp3audiofilter.cc index 751cc1e..68e7019 100644 --- a/wwinmp3audiofilter.cc +++ b/wwinmp3audiofilter.cc @@ -178,7 +178,7 @@ void WWinMp3AudioFilter::processMessage(Message* m) m->message = Message::CHANGED_DEVICEOPTIONS; m->to = parent; m->parameter = 0; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); }*/ diff --git a/wwinvideofilter.cc b/wwinvideofilter.cc index d3a759f..8dd34e6 100644 --- a/wwinvideofilter.cc +++ b/wwinvideofilter.cc @@ -170,7 +170,7 @@ void WWinVideoFilter::doSave() m->message = Message::CHANGED_DEVICEOPTIONS; m->to = parent; m->parameter = 0; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); }*/ diff --git a/wwinvideoh264filter.cc b/wwinvideoh264filter.cc index c0c4e18..b82ccac 100644 --- a/wwinvideoh264filter.cc +++ b/wwinvideoh264filter.cc @@ -170,7 +170,7 @@ void WWinVideoH264Filter::doSave() m->message = Message::CHANGED_DEVICEOPTIONS; m->to = parent; m->parameter = 0; - //Command::getInstance()->postMessage(m); + //Control::getInstance()->postMessage(m); }*/