diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-19 10:08:47 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-19 10:08:47 +0200 |
commit | 3e9031f96e17d7ac3babd4a0d0c70be1fcfbf3b7 (patch) | |
tree | 7b31365b1dd835e4f3b0546f97c37b385ff77128 | |
parent | 876ea90a3145c64c6b6b1e9109b8b8c9e3e11ce8 (diff) | |
download | vdr-plugin-graphlcd-3e9031f96e17d7ac3babd4a0d0c70be1fcfbf3b7.tar.gz vdr-plugin-graphlcd-3e9031f96e17d7ac3babd4a0d0c70be1fcfbf3b7.tar.bz2 |
set data via SVDRP and make these available to the skin-engine
-rw-r--r-- | display.c | 51 | ||||
-rw-r--r-- | display.h | 22 | ||||
-rw-r--r-- | plugin.c | 80 | ||||
-rw-r--r-- | skinconfig.c | 20 |
4 files changed, 166 insertions, 7 deletions
@@ -56,6 +56,8 @@ cGraphLCDDisplay::cGraphLCDDisplay() bBrightnessActive = true; mService = NULL; /* cannot be initialised here (mGraphLCDState not yet available) */ + + mExtData = new cExtData(); } cGraphLCDDisplay::~cGraphLCDDisplay() @@ -68,6 +70,8 @@ cGraphLCDDisplay::~cGraphLCDDisplay() delete mGraphLCDState; delete mService; + + delete mExtData; } bool cGraphLCDDisplay::Initialise(GLCD::cDriver * Lcd, const std::string & CfgPath, const std::string & SkinsPath, const std::string & SkinName) @@ -496,3 +500,50 @@ void cGraphLCDDisplay::Clear() { #endif mLcd->Refresh(false); } + + + +bool cExtData::Set(std::string key, std::string value, uint32_t expire) { + data[key] = value; + + if (expire > 0) { + expData[key] = cTimeMs::Now() + (expire * 1000); + } else { + expData.erase(key); // just in case of an old expiration entry for key + } + return true; +} + + +bool cExtData::Unset(std::string key) { + expData.erase(key); // ignore result; + return ( (data.erase(key) > 0) ? true : false ); +} + + +bool cExtData::IsSet(std::string key) { + std::string ret = Get(key); + return ( (ret != "") ? true : false ); +} + + +std::string cExtData::Get(std::string key) { + it = data.find(key); + if ( it != data.end() ) { + expDataIt = expData.find(key); + if ( expDataIt != expData.end() ) { + uint64_t expts = (*expDataIt).second; + if ( cTimeMs::Now() > expts ) { + expData.erase(key); + data.erase(key); + return ""; + } else { + return (*it).second; + } + } else { + return (*it).second; + } + } else { + return ""; + } +} @@ -18,6 +18,7 @@ #include <string> #include <vector> +#include <map> #include <glcdgraphics/bitmap.h> #include <glcddrivers/driver.h> @@ -47,6 +48,25 @@ enum eDisplayMode DisplayModeInteractive }; +// external data set via SVDRP +class cExtData +{ +private: + std::map<std::string,std::string> data; + std::map<std::string,std::string>::iterator it; + std::map<std::string,uint64_t> expData; + std::map<std::string,uint64_t>::iterator expDataIt; +public: + cExtData(void) {} + ~cExtData(void) { data.clear(); expData.clear(); } + + bool Set(std::string key, std::string value, uint32_t expire = 0); + bool Unset(std::string key); + bool IsSet(std::string key); + std::string Get(std::string key); +}; + + // Display update Thread class cGraphLCDDisplay : public cThread { @@ -71,6 +91,7 @@ public: GLCD::cDriver * GetDriver() const { return mLcd; } const eDisplayMode GetDisplayMode() const { return mDisplayMode; } + cExtData * GetExtData() const { return mExtData; } protected: virtual void Action(); @@ -104,6 +125,7 @@ private: /* display mode (normal or interactive) */ eDisplayMode mDisplayMode; uint64_t LastTimeDisplayMode; + cExtData * mExtData; }; #endif @@ -23,6 +23,8 @@ #include <vdr/plugin.h> +#include <ctype.h> + static const char * kPluginName = "graphlcd"; static const char *VERSION = "0.2.0-git"; @@ -234,8 +236,12 @@ const char **cPluginGraphLCD::SVDRPHelpPages(void) static const char *HelpPages[] = { "CLS Clear Display.", "UPD Update Display.", - "OFF Switch Plugin off.", - "ON Switch Plugin on.", + "OFF Switch Plugin off.", + "ON Switch Plugin on.", + "SET <key> <value> Set a key=value entry.", + "SETEXP <exp> <key> <value> Set a key=value entry which expires after <exp> secs.", + "UNSET <key> Unset (clear) entry <key>.", + "GET <key> Get value assigned to key.", NULL }; return HelpPages; @@ -243,6 +249,25 @@ const char **cPluginGraphLCD::SVDRPHelpPages(void) cString cPluginGraphLCD::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode) { + std::string option = Option; + size_t firstpos = std::string::npos; + size_t secondpos = std::string::npos; + firstpos = option.find_first_of(' '); + if (firstpos != std::string::npos) { + // remove extra spaces + while ( ((firstpos+1) < option.length()) && (option[firstpos+1] == ' ') ) { + option.erase(firstpos+1, 1); + } + secondpos = option.find_first_of(' ', firstpos+1); + if (firstpos != std::string::npos) { + // remove extra spaces + while ( ((secondpos+1) < option.length()) && (option[secondpos+1] == ' ') ) { + option.erase(secondpos+1, 1); + } + } + } + + if (strcasecmp(Command, "CLS") == 0) { if (GraphLCDSetup.PluginActive == 1) { return "Error: Plugin is active."; @@ -250,7 +275,7 @@ cString cPluginGraphLCD::SVDRPCommand(const char *Command, const char *Option, i mDisplay->Clear(); return "GraphLCD cleared."; }; - } + } else if (strcasecmp(Command, "UPD") == 0) { if (GraphLCDSetup.PluginActive == 0) { return "Error: Plugin is not active."; @@ -258,16 +283,59 @@ cString cPluginGraphLCD::SVDRPCommand(const char *Command, const char *Option, i mDisplay->Update(); return "GraphLCD updated."; }; - } - + } else if (strcasecmp(Command, "OFF") == 0) { GraphLCDSetup.PluginActive = 0; return "GraphLCD Plugin switched off."; - } + } else if (strcasecmp(Command, "ON") == 0) { GraphLCDSetup.PluginActive = 1; mDisplay->Update(); return "GraphLCD Plugin switched on."; + } else + if (strcasecmp(Command, "SET") == 0) { + if (firstpos != std::string::npos) { + std::string key = option.substr(0, firstpos); + if ( isalpha(key[0]) ) { + mDisplay->GetExtData()->Set(key, option.substr(firstpos+1)); + return "SET ok"; + } + } + return "SET requires two parameters: SET <key> <value>."; + } else + if (strcasecmp(Command, "SETEXP") == 0) { + if (secondpos != std::string::npos) { + std::string key = option.substr(firstpos+1, secondpos-firstpos-1); + std::string value = option.substr(secondpos+1); + if ( isalpha(key[0]) && isdigit(option[0]) ) { + uint32_t expsec = (uint32_t)strtol( option.substr(0, firstpos).c_str(), NULL, 10); + mDisplay->GetExtData()->Set( key, value, expsec ); + return "SETEXP ok"; + } + } + return "SETEXP requires three parameters: SETEXP <exp> <key> <value>."; + } else + if (strcasecmp(Command, "UNSET") == 0) { + if (firstpos == std::string::npos) { + mDisplay->GetExtData()->Unset( option ); + return "UNSET ok"; + } else { + return "UNSET requires exactly one parameter: UNSET <key>."; + } + } else + if (strcasecmp(Command, "GET") == 0) { + if (firstpos == std::string::npos) { + std::string res = mDisplay->GetExtData()->Get( option ); + std::string retval = "GET "; retval.append(option); retval.append(": "); + if (res != "" ) { + retval.append(res); + } else { + retval.append("(null)"); + } + return retval.c_str(); + } else { + return "GET requires exactly one parameter: GET <key>."; + } } return NULL; } diff --git a/skinconfig.c b/skinconfig.c index 89ff8a4..a564289 100644 --- a/skinconfig.c +++ b/skinconfig.c @@ -140,10 +140,12 @@ typedef enum _eTokenId tokDisplayMode, tokPrivateSettingEnd, - // external services + // external services and data tokPrivateServiceStart, tokServiceIsAvailable, tokServiceItem, + tokExtDataIsAvailable, + tokExtDataItem, tokPrivateServiceEnd, tokCountToken @@ -269,6 +271,8 @@ static const std::string Tokens[tokCountToken] = "privateServiceStart", "ServiceIsAvailable", "ServiceItem", + "ExtDataIsAvailable", + "ExtDataItem", "privateServiceEnd" }; @@ -691,6 +695,20 @@ GLCD::cType cGraphLCDSkinConfig::GetToken(const GLCD::tSkinToken & Token) return s->GetItem(ServiceName, ItemName); } break; + case tokExtDataIsAvailable: { + if (Token.Attrib.Text == "") + return false; + + return mDisplay->GetExtData()->IsSet( Token.Attrib.Text ); + } + break; + case tokExtDataItem: { + if (Token.Attrib.Text == "") + return false; + + return mDisplay->GetExtData()->Get( Token.Attrib.Text ); + } + break; default: break; } |