summaryrefslogtreecommitdiff
path: root/extdata.c
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-09-17 21:28:10 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-09-17 21:28:10 +0200
commit0703b948dd63eb281df5dc531abdf66818becdf7 (patch)
treeb76b3ba4634a95ed71c0dd2ab1e1a4354109870d /extdata.c
parent9e0f177243221e2123758d196315cb63d0f8902b (diff)
downloadvdr-plugin-graphlcd-0703b948dd63eb281df5dc531abdf66818becdf7.tar.gz
vdr-plugin-graphlcd-0703b948dd63eb281df5dc531abdf66818becdf7.tar.bz2
cExtData is now a singleton class, thus its content survives a DISCONN/CONNECT of a display; trans() now works as expected; three new tokens: 'IsMenuList', 'MenuText', 'MenuTextScroll'; support added for ':clean' and ':rest' for tokens 'MenuTitle', 'MenuCurrent', and 'MenuText'
Diffstat (limited to 'extdata.c')
-rw-r--r--extdata.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/extdata.c b/extdata.c
new file mode 100644
index 0000000..01107c1
--- /dev/null
+++ b/extdata.c
@@ -0,0 +1,88 @@
+/*
+ * GraphLCD plugin for the Video Disk Recorder
+ *
+ * extdata.c - external data sent via SVDRP
+ *
+ * This file is released under the GNU General Public License. Refer
+ * to the COPYING file distributed with this package.
+ *
+ * (c) 2011 Wolfgang Astleitner <mrwastl AT users sourceforge net>
+ */
+
+#include "extdata.h"
+
+#include <vdr/tools.h>
+
+#include <stdio.h>
+cExtData * cExtData::mExtDataInstance = NULL;
+
+cExtData * cExtData::GetExtData(void) {
+ if (mExtDataInstance == NULL) {
+ mExtDataInstance = new cExtData();
+ }
+ return mExtDataInstance;
+}
+
+
+void cExtData::ReleaseExtData(void) {
+ delete mExtDataInstance;
+ mExtDataInstance = NULL;
+}
+
+
+cExtData::~cExtData(void) {
+ data.clear();
+ expData.clear();
+}
+
+
+bool cExtData::Set(std::string key, std::string value, uint32_t expire) {
+ if (mExtDataInstance == NULL) return false; // paranoia check
+
+ 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) {
+ if (mExtDataInstance == NULL) return false; // paranoia check
+
+ 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) {
+ if (mExtDataInstance == NULL) return ""; // paranoia check
+
+ 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 "";
+ }
+}