introduce eConfigManager baseclass
authorpieterg <pieterg@users.sourceforge.net>
Wed, 10 Aug 2011 18:38:25 +0000 (20:38 +0200)
committerpieterg <pieterg@users.sourceforge.net>
Thu, 2 May 2013 20:35:17 +0000 (22:35 +0200)
move python implementation into derived ePythonConfigQuery class

18 files changed:
lib/base/nconfig.cpp
lib/base/nconfig.h
lib/dvb/cablescan.cpp
lib/dvb/fastscan.cpp
lib/dvb/frontend.cpp
lib/dvb/pmt.cpp
lib/dvb/subtitle.cpp
lib/dvb_ci/dvbci.cpp
lib/gui/esubtitle.cpp
lib/python/Makefile.inc
lib/python/enigma_python.i
lib/python/pythonconfig.cpp [new file with mode: 0644]
lib/python/pythonconfig.h [new file with mode: 0644]
lib/service/servicedvb.cpp
lib/service/servicedvbstream.cpp
lib/service/servicedvd.cpp
lib/service/servicemp3.cpp
main/bsod.cpp

index 106558a..b1c58ca 100644 (file)
@@ -1,35 +1,37 @@
 #include <lib/base/nconfig.h>
-#include <lib/python/python.h>
 
-ePyObject ePythonConfigQuery::m_queryFunc;
+eConfigManager *eConfigManager::instance = NULL;
 
-void ePythonConfigQuery::setQueryFunc(ePyObject queryFunc)
+eConfigManager::eConfigManager() 
+{ 
+       instance = this; 
+}
+
+eConfigManager::~eConfigManager() 
+{ 
+       instance = NULL; 
+}
+
+eConfigManager *eConfigManager::getInstance() 
+{ 
+       return instance; 
+}
+
+std::string eConfigManager::getConfigValue(const char *key) 
+{
+       return instance ? instance->getConfig(key) : "";
+}
+
+int eConfigManager::getConfigIntValue(const char *key, int defaultvalue) 
 {
-       if (m_queryFunc)
-               Py_DECREF(m_queryFunc);
-       m_queryFunc = queryFunc;
-       if (m_queryFunc)
-               Py_INCREF(m_queryFunc);
+       std::string value = getConfigValue(key);
+       return (value != "") ? atoi(value.c_str()) : defaultvalue;
 }
 
-RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value)
+bool eConfigManager::getConfigBoolValue(const char *key, bool defaultvalue) 
 {
-       if (key && PyCallable_Check(m_queryFunc))
-       {
-               ePyObject pArgs = PyTuple_New(1);
-               PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(key));
-               ePyObject pRet = PyObject_CallObject(m_queryFunc, pArgs);
-               Py_DECREF(pArgs);
-               if (pRet)
-               {
-                       if (PyString_Check(pRet))
-                       {
-                               value.assign(PyString_AS_STRING(pRet));
-                               Py_DECREF(pRet);
-                               return 0;
-                       }
-                       Py_DECREF(pRet);
-               }
-       }
-       return -1;
+       std::string value = getConfigValue(key);
+       if (value == "True") return true;
+       if (value == "False") return false;
+       return defaultvalue;
 }
index 3667439..b48132f 100644 (file)
@@ -1,18 +1,24 @@
 #ifndef __lib_base_nconfig_h_
 #define __lib_base_nconfig_h_
 
-#include <lib/python/python.h>
+#include <string>
+#include <stdbool.h>
 
-class ePythonConfigQuery
+class eConfigManager
 {
-       static ePyObject m_queryFunc;
-       ePythonConfigQuery() {}
-       ~ePythonConfigQuery() {}
+protected:
+       static eConfigManager *instance;
+       static eConfigManager *getInstance();
+
+       virtual std::string getConfig(const char *key) = 0;
+
 public:
-       static void setQueryFunc(SWIG_PYOBJECT(ePyObject) func);
-#ifndef SWIG
-       static RESULT getConfigValue(const char *key, std::string &value);
-#endif
+       eConfigManager();
+       virtual ~eConfigManager();
+
+       static std::string getConfigValue(const char *key);
+       static int getConfigIntValue(const char *key, int defaultvalue = 0);
+       static bool getConfigBoolValue(const char *key, bool defaultvalue = false);
 };
 
-#endif // __lib_base_nconfig_h_
+#endif /* __lib_base_nconfig_h_ */
index d0a336f..574b97f 100644 (file)
@@ -345,9 +345,7 @@ void eCableScan::createBouquets()
        }
        bouquetFilename = replace_all(providerName, " ", "");
 
-       bool multibouquet = false;
-       std::string value;
-       multibouquet = (ePythonConfigQuery::getConfigValue("config.usage.multibouquet", value) >= 0 && value == "True");
+       bool multibouquet = eConfigManager::getConfigBoolValue("config.usage.multibouquet");
 
        if (multibouquet)
        {
index 4ee22f8..0e29b35 100644 (file)
@@ -619,9 +619,7 @@ void eFastScan::parseResult()
                }
        }
 
-       bool multibouquet = false;
-       std::string value;
-       multibouquet = (ePythonConfigQuery::getConfigValue("config.usage.multibouquet", value) >= 0 && value == "True");
+       bool multibouquet = eConfigManager::getConfigBoolValue("config.usage.multibouquet");
 
        if (multibouquet)
        {
index 06a7bdb..78da5e7 100644 (file)
@@ -2568,12 +2568,10 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                if (res)
                        goto tune_error;
 
-               std::string enable_5V;
                char configStr[255];
                snprintf(configStr, 255, "config.Nims.%d.terrestrial_5V", m_slotid);
                m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, timeout) );
-               ePythonConfigQuery::getConfigValue(configStr, enable_5V);
-               if (enable_5V == "True")
+               if (eConfigManager::getConfigBoolValue(configStr))
                        m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
                else
                        m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltageOff) );
index 6d17a50..0d34df8 100755 (executable)
@@ -388,13 +388,17 @@ int eDVBServicePMTHandler::getProgramInfo(program &program)
 
                std::string configvalue;
                std::vector<std::string> autoaudio_languages;
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_autoselect1", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.audio_autoselect1");
+               if (configvalue != "" && configvalue != "None")
                        autoaudio_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_autoselect2", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.audio_autoselect2");
+               if (configvalue != "" && configvalue != "None")
                        autoaudio_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_autoselect3", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.audio_autoselect3");
+               if (configvalue != "" && configvalue != "None")
                        autoaudio_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_autoselect4", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.audio_autoselect4");
+               if (configvalue != "" && configvalue != "None")
                        autoaudio_languages.push_back(configvalue);
 
                int autosub_txt_normal = -1;
@@ -404,13 +408,17 @@ int eDVBServicePMTHandler::getProgramInfo(program &program)
                int autosub_level =4;
 
                std::vector<std::string> autosub_languages;
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_autoselect1", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.subtitle_autoselect1");
+               if (configvalue != "" && configvalue != "None")
                        autosub_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_autoselect2", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.subtitle_autoselect2");
+               if (configvalue != "" && configvalue != "None")
                        autosub_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_autoselect3", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.subtitle_autoselect3");
+               if (configvalue != "" && configvalue != "None")
                        autosub_languages.push_back(configvalue);
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_autoselect4", configvalue) && configvalue != "None")
+               configvalue = eConfigManager::getConfigValue("config.autolanguage.subtitle_autoselect4");
+               if (configvalue != "" && configvalue != "None")
                        autosub_languages.push_back(configvalue);
 
                m_dsmcc_pid = program.dsmccPid;
@@ -494,13 +502,8 @@ int eDVBServicePMTHandler::getProgramInfo(program &program)
                        }
                }
 
-               bool defaultac3 = false;
-               bool useaudio_cache = false;
-
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_defaultac3", configvalue))
-                       defaultac3 = configvalue == "True";
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.audio_usecache", configvalue))
-                       useaudio_cache = configvalue == "True";
+               bool defaultac3 = eConfigManager::getConfigBoolValue("config.autolanguage.audio_defaultac3");
+               bool useaudio_cache = eConfigManager::getConfigBoolValue("config.autolanguage.audio_usecache");
 
                if (useaudio_cache && audio_cached != -1)
                        program.defaultAudioStream = audio_cached;
@@ -521,19 +524,10 @@ int eDVBServicePMTHandler::getProgramInfo(program &program)
                                program.defaultAudioStream = autoaudio_ac3;
                }
 
-               bool allow_hearingimpaired = false;
-               bool default_hearingimpaired = false;
-               bool defaultdvb = false;
-               int equallanguagemask = false;
-
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_hearingimpaired", configvalue))
-                       allow_hearingimpaired = configvalue == "True";
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_defaultimpaired", configvalue))
-                       default_hearingimpaired = configvalue == "True";
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_defaultdvb", configvalue))
-                       defaultdvb = configvalue == "True";
-               if (!ePythonConfigQuery::getConfigValue("config.autolanguage.equal_languages", configvalue))
-                       equallanguagemask = atoi(configvalue.c_str());
+               bool allow_hearingimpaired = eConfigManager::getConfigBoolValue("config.autolanguage.subtitle_hearingimpaired");
+               bool default_hearingimpaired = eConfigManager::getConfigBoolValue("config.autolanguage.subtitle_defaultimpaired");
+               bool defaultdvb = eConfigManager::getConfigBoolValue("config.autolanguage.subtitle_defaultdvb");
+               int equallanguagemask = eConfigManager::getConfigIntValue("config.autolanguage.equal_languages");
 
                if (defaultdvb)
                {
@@ -788,9 +782,7 @@ int eDVBServicePMTHandler::tuneExt(eServiceReferenceDVB &ref, int use_decode_dem
                        if (ref.path.empty())
                        {
                                m_dvb_scan = new eDVBScan(m_channel, true, false);
-                               std::string disable_background_scan;
-                               if (ePythonConfigQuery::getConfigValue("config.misc.disable_background_scan", disable_background_scan) < 0
-                                       || disable_background_scan != "True")
+                               if (!eConfigManager::getConfigBoolValue("config.misc.disable_background_scan"))
                                {
                                        /*
                                         * not starting a dvb scan triggers what appears to be a
@@ -822,9 +814,7 @@ int eDVBServicePMTHandler::tuneExt(eServiceReferenceDVB &ref, int use_decode_dem
 
                        if (m_service_type == offline) 
                        {
-                               std::string delay;
-                               ePythonConfigQuery::getConfigValue("config.recording.offline_decode_delay", delay);
-                               m_pvr_channel->setOfflineDecodeMode(atoi(delay.c_str()));
+                               m_pvr_channel->setOfflineDecodeMode(eConfigManager::getConfigIntValue("config.recording.offline_decode_delay"));
                        }
                }
        }
index be5598d..8001f19 100644 (file)
@@ -51,8 +51,7 @@ static int extract_pts(pts_t &pts, __u8 *pkt)
 
 void eDVBSubtitleParser::subtitle_process_line(subtitle_region *region, subtitle_region_object *object, int line, __u8 *data, int len)
 {
-       std::string configvalue;
-       bool subcentered = (ePythonConfigQuery::getConfigValue("config.subtitles.dvb_subtitles_centered", configvalue) >= 0 && configvalue == "True");
+       bool subcentered = eConfigManager::getConfigBoolValue("config.subtitles.dvb_subtitles_centered");
        int x = subcentered ? (region->width - len) /2 : object->object_horizontal_position;
        int y = object->object_vertical_position + line;
        if (x + len > region->width)
@@ -1176,13 +1175,8 @@ void eDVBSubtitleParser::subtitle_redraw(int page_id)
                                        break;
                        }
 
-                       std::string configvalue;
-                       int bcktrans = 0;
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.dvb_subtitles_backtrans", configvalue))
-                       {
-                               bcktrans = atoi(configvalue.c_str());
-                       }
-                       bool yellow = (ePythonConfigQuery::getConfigValue("config.subtitles.dvb_subtitles_yellow", configvalue) >= 0 && configvalue == "True");
+                       int bcktrans = eConfigManager::getConfigIntValue("config.subtitles.dvb_subtitles_backtrans");
+                       bool yellow = eConfigManager::getConfigBoolValue("config.subtitles.dvb_subtitles_yellow");
 
                        for (int i=0; i<clut_size; ++i)
                        {
index 08dd7a7..8bf1933 100644 (file)
@@ -237,8 +237,7 @@ static bool canDescrambleMultipleServices(int slotid)
 {
        char configStr[255];
        snprintf(configStr, 255, "config.ci.%d.canDescrambleMultipleServices", slotid);
-       std::string str;
-       ePythonConfigQuery::getConfigValue(configStr, str);
+       std::string str = eConfigManager::getConfigValue(configStr);
        if ( str == "auto" )
        {
                std::string appname = eDVBCI_UI::getInstance()->getAppName(slotid);
index 1f8f8c3..7133e04 100644 (file)
@@ -30,13 +30,9 @@ void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
        {
                int width = size().width() - startX * 2;
                std::string configvalue;
-               bool original_position = (ePythonConfigQuery::getConfigValue("config.subtitles.ttx_subtitle_original_position", configvalue) >= 0 && configvalue == "True");
-               bool rewrap = (ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_rewrap", configvalue) >= 0 && configvalue == "True");
-               int color_mode = 0;
-               if (!ePythonConfigQuery::getConfigValue("config.subtitles.ttx_subtitle_colors", configvalue))
-               {
-                       color_mode = atoi(configvalue.c_str());
-               }
+               bool original_position = eConfigManager::getConfigBoolValue("config.subtitles.ttx_subtitle_original_position");
+               bool rewrap = eConfigManager::getConfigBoolValue("config.subtitles.subtitle_rewrap");
+               int color_mode = eConfigManager::getConfigIntValue("config.subtitles.ttx_subtitle_colors", 1);
                gRGB color;
                bool original_colors = false;
                switch (color_mode)
@@ -58,11 +54,7 @@ void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
                {
                        int height = size().height() / 3;
 
-                       int lowerborder = 50;
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_position", configvalue))
-                       {
-                               lowerborder = atoi(configvalue.c_str());
-                       }
+                       int lowerborder = eConfigManager::getConfigIntValue("config.subtitles.subtitle_position", 50);
                        int line = newpage.m_elements[0].m_source_line;
                        /* create a new page with just one text element */
                        m_page.m_elements.push_back(eDVBTeletextSubtitlePageElement(color, "", 0));
@@ -132,18 +124,15 @@ void eSubtitleWidget::setPage(const eDVBSubtitlePage &p)
        invalidate(m_visible_region); // invalidate old visible regions
        m_visible_region.rects.clear();
        int line = 0;
-       int original_position = 0;
-       std::string configvalue;
-       if (!ePythonConfigQuery::getConfigValue("config.subtitles.dvb_subtitles_original_position", configvalue))
-               original_position = atoi(configvalue.c_str());
+       int original_position = eConfigManager::getConfigIntValue("config.subtitles.dvb_subtitles_original_position");
        for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
        {
                if (original_position)
                {
                        int lines = m_dvb_page.m_regions.size();
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_position", configvalue))
+                       int lowerborder = eConfigManager::getConfigIntValue("config.subtitles.subtitle_position", -1);
+                       if (lowerborder >= 0)
                        {
-                               int lowerborder = atoi(configvalue.c_str());
                                if (original_position == 1)
                                        it->m_position=ePoint(it->m_position.x(), p.m_display_size.height() - (lines - line) * it->m_pixmap->size().height() - lowerborder);
                                else
@@ -182,12 +171,7 @@ void eSubtitleWidget::setPage(const ePangoSubtitlePage &p)
                {
                        eRect &area = m_pango_page.m_elements[i].m_area;
                        area.setLeft(startX);
-                       int lowerborder=50;
-                       std::string subtitle_position;
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_position", subtitle_position))
-                       {
-                               lowerborder = atoi(subtitle_position.c_str());
-                       }
+                       int lowerborder = eConfigManager::getConfigIntValue("config.subtitles.subtitle_position", 50);
                        area.setTop(size_per_element * i + startY - lowerborder);
                        area.setWidth(width);
                        area.setHeight(size_per_element);
@@ -239,26 +223,16 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                std::string configvalue;
 
                int rt_halignment_flag;
-               if (ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_alignment", configvalue))
-                       configvalue = "center";
-               if (configvalue == "center")
-                       rt_halignment_flag = gPainter::RT_HALIGN_CENTER;
+               configvalue = eConfigManager::getConfigValue("config.subtitles.subtitle_alignment");
+               if (configvalue == "right")
+                       rt_halignment_flag = gPainter::RT_HALIGN_RIGHT;
                else if (configvalue == "left")
                        rt_halignment_flag = gPainter::RT_HALIGN_LEFT;
                else
-                       rt_halignment_flag = gPainter::RT_HALIGN_RIGHT;
-
-               int borderwidth = 2;
-               if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_borderwidth", configvalue))
-               {
-                       borderwidth = atoi(configvalue.c_str());
-               }
+                       rt_halignment_flag = gPainter::RT_HALIGN_CENTER;
 
-               int fontsize = 34;
-               if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_fontsize", configvalue))
-               {
-                       fontsize = atoi(configvalue.c_str());
-               }
+               int borderwidth = eConfigManager::getConfigIntValue("config.subtitles.subtitle_borderwidth", 2);
+               int fontsize = eConfigManager::getConfigIntValue("config.subtitles.subtitle_fontsize", 34);
 
                if (m_pixmap)
                {
@@ -303,7 +277,7 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                                text = replace_all(text, "&lt", "<");
                                text = replace_all(text, "&gt", ">");
 
-                               bool yellow_color = (ePythonConfigQuery::getConfigValue("config.subtitles.pango_subtitles_yellow", configvalue) >= 0 && configvalue == "True");
+                               bool yellow_color = eConfigManager::getConfigBoolValue("config.subtitles.pango_subtitles_yellow");
                                if (yellow_color)
                                        text = (std::string) gRGB(255,255,0) + text;
                                text = replace_all(text, "<i>", yellow_color ? "" : (std::string) gRGB(0,255,255));
index 578d089..1b9164d 100644 (file)
@@ -2,12 +2,14 @@ noinst_LIBRARIES += python/libenigma_python.a
 
 python_libenigma_python_a_SOURCES = \
        python/connections.cpp \
-       python/python.cpp
+       python/python.cpp \
+       python/pythonconfig.cpp
 
 pythonincludedir = $(pkgincludedir)/lib/python
 pythoninclude_HEADERS = \
        python/connections.h \
        python/python.h \
+       python/pythonconfig.h \
        python/swig.h
 
 nodist_python_libenigma_python_a_SOURCES = \
index 0d9548d..566efce 100644 (file)
@@ -41,7 +41,6 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/base/eenv.h>
 #include <lib/base/eerror.h>
 #include <lib/base/etpm.h>
-#include <lib/base/nconfig.h>
 #include <lib/base/message.h>
 #include <lib/driver/rc.h>
 #include <lib/driver/rcinput_swig.h>
@@ -72,6 +71,7 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/gui/evideo.h>
 #include <lib/gui/ecanvas.h>
 #include <lib/python/connections.h>
+#include <lib/python/pythonconfig.h>
 #include <lib/gui/elistbox.h>
 #include <lib/gui/elistboxcontent.h>
 #include <lib/gui/esubtitle.h>
@@ -183,7 +183,6 @@ typedef long time_t;
 %immutable eTuxtxtApp::appClosed;
 %include <lib/base/message.h>
 %include <lib/base/etpm.h>
-%include <lib/base/nconfig.h>
 %include <lib/driver/rc.h>
 %include <lib/driver/rcinput_swig.h>
 %include <lib/gdi/fb.h>
@@ -243,6 +242,7 @@ typedef long time_t;
 %include <lib/dvb_ci/dvbci_ui.h>
 %include <lib/dvb/db.h>
 %include <lib/python/python.h>
+%include <lib/python/pythonconfig.h>
 %include <lib/gdi/picload.h>
 /**************  eptr  **************/
 
diff --git a/lib/python/pythonconfig.cpp b/lib/python/pythonconfig.cpp
new file mode 100644 (file)
index 0000000..8cd92ed
--- /dev/null
@@ -0,0 +1,42 @@
+#include <lib/python/pythonconfig.h>
+#include <lib/python/python.h>
+
+ePyObject ePythonConfigQuery::m_queryFunc;
+
+void ePythonConfigQuery::setQueryFunc(ePyObject queryFunc)
+{
+       if (m_queryFunc)
+               Py_DECREF(m_queryFunc);
+       m_queryFunc = queryFunc;
+       if (m_queryFunc)
+               Py_INCREF(m_queryFunc);
+}
+
+RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value)
+{
+       if (key && PyCallable_Check(m_queryFunc))
+       {
+               ePyObject pArgs = PyTuple_New(1);
+               PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(key));
+               ePyObject pRet = PyObject_CallObject(m_queryFunc, pArgs);
+               Py_DECREF(pArgs);
+               if (pRet)
+               {
+                       if (PyString_Check(pRet))
+                       {
+                               value.assign(PyString_AS_STRING(pRet));
+                               Py_DECREF(pRet);
+                               return 0;
+                       }
+                       Py_DECREF(pRet);
+               }
+       }
+       return -1;
+}
+
+std::string ePythonConfigQuery::getConfig(const char *key)
+{
+       std::string value;
+       getConfigValue(key, value);
+       return value;
+}
diff --git a/lib/python/pythonconfig.h b/lib/python/pythonconfig.h
new file mode 100644 (file)
index 0000000..333b04c
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __lib_python_pythonconfig_h_
+#define __lib_python_pythonconfig_h_
+
+#include <lib/base/nconfig.h>
+#include <lib/python/python.h>
+
+class ePythonConfigQuery : public eConfigManager
+{
+       static ePyObject m_queryFunc;
+       ePythonConfigQuery() {}
+       ~ePythonConfigQuery() {}
+#ifndef SWIG
+       RESULT getConfigValue(const char *key, std::string &value);
+       std::string getConfig(const char *key);
+#endif
+public:
+       static void setQueryFunc(SWIG_PYOBJECT(ePyObject) func);
+};
+
+#endif // __lib_python_pythonconfig_h_
index 4ae13b1..d14bfa4 100644 (file)
@@ -1128,10 +1128,8 @@ void eDVBServicePlay::serviceEvent(int event)
                /* fill now/next with info from the epg cache, will be replaced by EIT when it arrives */
                updateEpgCacheNowNext();
 
-               std::string show_eit_nownext;
                /* default behaviour is to start an eit reader, and wait for now/next info, unless this is disabled */
-               if (ePythonConfigQuery::getConfigValue("config.usage.show_eit_nownext", show_eit_nownext) < 0
-                       || show_eit_nownext != "False")
+               if (eConfigManager::getConfigBoolValue("config.usage.show_eit_nownext", true))
                {
                        ePtr<iDVBDemux> m_demux;
                        if (!m_service_handler.getDataDemux(m_demux))
@@ -1669,8 +1667,9 @@ RESULT eDVBServicePlay::timeshift(ePtr<iTimeshiftService> &ptr)
                if (!m_timeshift_enabled)
                {
                        /* query config path */
-                       std::string tspath;
-                       if(ePythonConfigQuery::getConfigValue("config.usage.timeshift_path", tspath) == -1){
+                       std::string tspath = eConfigManager::getConfigValue("config.usage.timeshift_path");
+                       if(tspath == "")
+                       {
                                eDebug("could not query ts path from config");
                                return -4;
                        }
@@ -2323,8 +2322,8 @@ RESULT eDVBServicePlay::startTimeshift()
        if (!m_record)
                return -3;
 
-       std::string tspath;
-       if(ePythonConfigQuery::getConfigValue("config.usage.timeshift_path", tspath) == -1)
+       std::string tspath = eConfigManager::getConfigValue("config.usage.timeshift_path");
+       if (tspath == "")
        {
                eDebug("could not query ts path");
                return -5;
@@ -2792,12 +2791,12 @@ void eDVBServicePlay::updateDecoder(bool sendSeekableStateChanged)
                else
                {
                        std::string value;
-                       bool showRadioBackground = (ePythonConfigQuery::getConfigValue("config.misc.showradiopic", value) < 0 || value == "True");
+                       bool showRadioBackground = eConfigManager::getConfigBoolValue("config.misc.showradiopic", true);
                        std::string radio_pic;
                        if (showRadioBackground)
-                               ePythonConfigQuery::getConfigValue("config.misc.radiopic", radio_pic);
+                               radio_pic = eConfigManager::getConfigValue("config.misc.radiopic");
                        else
-                               ePythonConfigQuery::getConfigValue("config.misc.blackradiopic", radio_pic);
+                               radio_pic = eConfigManager::getConfigValue("config.misc.blackradiopic");
                        m_decoder->setRadioPic(radio_pic);
                }
 
@@ -3110,11 +3109,7 @@ PyObject *eDVBServicePlay::getCachedSubtitle()
                eDVBServicePMTHandler &h = m_timeshift_active ? m_service_handler_timeshift : m_service_handler;
                if (!h.getProgramInfo(program))
                {
-                       bool usecache=false;
-                       std::string configvalue;
-                       if (!ePythonConfigQuery::getConfigValue("config.autolanguage.subtitle_usecache", configvalue))
-                               usecache = configvalue == "True";
-
+                       bool usecache = eConfigManager::getConfigBoolValue("config.autolanguage.subtitle_usecache");
                        int stream=program.defaultSubtitleStream;
                        int tmp = m_dvb_service->getCacheEntry(eDVBService::cSUBTITLE);
 
@@ -3251,23 +3246,15 @@ void eDVBServicePlay::newSubtitlePage(const eDVBTeletextSubtitlePage &page)
        if (m_subtitle_widget)
        {
                int subtitledelay = 0;
-               std::string configvalue;
                if (!page.m_have_pts && (m_is_pvr || m_timeshift_enabled))
                {
                        eDebug("Subtitle without PTS and recording");
-                       subtitledelay = 315000;
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_noPTSrecordingdelay", configvalue))
-                       {
-                               subtitledelay = atoi(configvalue.c_str());
-                       }
+                       subtitledelay = eConfigManager::getConfigIntValue("config.subtitles.subtitle_noPTSrecordingdelay", 315000);
                }
                else
                {
                        /* check the setting for subtitle delay in live playback, either with pts, or without pts */
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_bad_timing_delay", configvalue))
-                       {
-                               subtitledelay = atoi(configvalue.c_str());
-                       }
+                       subtitledelay = eConfigManager::getConfigIntValue("config.subtitles.subtitle_bad_timing_delay", 0);
                }
 
                if (!page.m_have_pts || subtitledelay)
@@ -3359,12 +3346,8 @@ void eDVBServicePlay::newDVBSubtitlePage(const eDVBSubtitlePage &p)
                        m_decoder->getPTS(0, pos);
                if ( abs(pos-p.m_show_time)>1800000 && (m_is_pvr || m_timeshift_enabled))
                {
-                       std::string configvalue;
-                       int subtitledelay = 315000;
-                       if (!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_noPTSrecordingdelay", configvalue))
-                       {
-                               subtitledelay = atoi(configvalue.c_str());
-                       }
+                       eDebug("Subtitle without PTS and recording");
+                       int subtitledelay = eConfigManager::getConfigIntValue("config.subtitles.subtitle_noPTSrecordingdelay", 315000);
 
                        eDVBSubtitlePage tmppage;
                        tmppage = p;
@@ -3373,12 +3356,7 @@ void eDVBServicePlay::newDVBSubtitlePage(const eDVBSubtitlePage &p)
                }
                else
                {
-                       int subtitledelay = 0;
-                       std::string configvalue;
-                       if(!ePythonConfigQuery::getConfigValue("config.subtitles.subtitle_bad_timing_delay", configvalue))
-                       {
-                               subtitledelay = atoi(configvalue.c_str());
-                       }
+                       int subtitledelay = eConfigManager::getConfigIntValue("config.subtitles.subtitle_bad_timing_delay", 0);
                        if (subtitledelay != 0)
                        {
                                eDVBSubtitlePage tmppage;
@@ -3417,12 +3395,9 @@ void eDVBServicePlay::setAC3Delay(int delay)
 {
        if (m_dvb_service)
                m_dvb_service->setCacheEntry(eDVBService::cAC3DELAY, delay ? delay : -1);
-       if (m_decoder) {
-               std::string config_delay;
-               int config_delay_int = 0;
-               if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
-                       config_delay_int = atoi(config_delay.c_str());
-               m_decoder->setAC3Delay(delay + config_delay_int);
+       if (m_decoder) 
+       {
+               m_decoder->setAC3Delay(delay + eConfigManager::getConfigIntValue("config.av.generalAC3delay"));
        }
 }
 
@@ -3430,14 +3405,9 @@ void eDVBServicePlay::setPCMDelay(int delay)
 {
        if (m_dvb_service)
                m_dvb_service->setCacheEntry(eDVBService::cPCMDELAY, delay ? delay : -1);
-       if (m_decoder) {
-               std::string config_delay;
-               int config_delay_int = 0;
-               if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
-                       config_delay_int = atoi(config_delay.c_str());
-               else
-                       config_delay_int = 0;
-               m_decoder->setPCMDelay(delay + config_delay_int);
+       if (m_decoder) 
+       {
+               m_decoder->setPCMDelay(delay + eConfigManager::getConfigIntValue("config.av.generalPCMdelay"));
        }
 }
 
index b2a9203..4ce8e0d 100644 (file)
@@ -107,14 +107,13 @@ int eDVBServiceStream::doPrepare()
                /* allocate a ts recorder if we don't already have one. */
        if (m_state == stateIdle)
        {
-               std::string stream_ecm, stream_eit, stream_ait, descramble_setting;
-               m_stream_ecm = (ePythonConfigQuery::getConfigValue("config.streaming.stream_ecm", stream_ecm) >= 0 && stream_ecm == "True");
-               m_stream_eit = (ePythonConfigQuery::getConfigValue("config.streaming.stream_eit", stream_eit) >= 0 && stream_eit == "True");
-               m_stream_ait = (ePythonConfigQuery::getConfigValue("config.streaming.stream_ait", stream_ait) >= 0 && stream_ait == "True");
+               m_stream_ecm = eConfigManager::getConfigBoolValue("config.streaming.stream_ecm");
+               m_stream_eit = eConfigManager::getConfigBoolValue("config.streaming.stream_eit");
+               m_stream_ait = eConfigManager::getConfigBoolValue("config.streaming.stream_ait");
                m_pids_active.clear();
                m_state = statePrepared;
                eDVBServicePMTHandler::serviceType servicetype = m_stream_ecm ? eDVBServicePMTHandler::scrambled_streamserver : eDVBServicePMTHandler::streamserver;
-               bool descramble = (ePythonConfigQuery::getConfigValue("config.streaming.descramble", descramble_setting) < 0 || descramble_setting != "False");
+               bool descramble = eConfigManager::getConfigBoolValue("config.streaming.descramble", true);
                return m_service_handler.tune(m_ref, 0, 0, 0, NULL, servicetype, descramble);
        }
        return 0;
index 4795eb8..bbafb53 100644 (file)
@@ -103,8 +103,8 @@ eServiceDVD::eServiceDVD(eServiceReference ref):
        ddvd_set_dvd_path(m_ddvdconfig, ref.path.c_str());
        ddvd_set_ac3thru(m_ddvdconfig, 0);
 
-       std::string ddvd_language;
-       if (!ePythonConfigQuery::getConfigValue("config.osd.language", ddvd_language))
+       std::string ddvd_language = eConfigManager::getConfigValue("config.osd.language");
+       if (ddvd_language != "")
                ddvd_set_language(m_ddvdconfig, (ddvd_language.substr(0,2)).c_str());
 
        int fd = open("/proc/stb/video/aspect", O_RDONLY);
index 403c876..9301b6a 100644 (file)
@@ -346,12 +346,11 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
 
                std::string config_str;
-               if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
+               if (eConfigManager::getConfigBoolValue("config.mediaplayer.useAlternateUserAgent"))
                {
-                       if ( config_str == "True" )
-                               ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
+                       m_useragent = eConfigManager::getConfigValue("config.mediaplayer.alternateUserAgent");
                }
-               if ( m_useragent.length() == 0 )
+               if (m_useragent.empty())
                        m_useragent = "Enigma2 Mediaplayer";
 
                if (strstr(filename, " buffer=1"))
@@ -1983,14 +1982,8 @@ void eServiceMP3::pullSubtitle(GstBuffer *buffer)
                {
                        if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
                        {
-                               int delay = 0;
-                               std::string configvalue;
-                               if(ePythonConfigQuery::getConfigValue("config.subtitles.pango_subtitles_delay", configvalue)==0)
-                                       delay = atoi(configvalue.c_str());
-
-                               int subtitle_fps = 1; // = original
-                               if(ePythonConfigQuery::getConfigValue("config.subtitles.pango_subtitles_fps", configvalue)==0)
-                                       subtitle_fps = atoi(configvalue.c_str());
+                               int delay = eConfigManager::getConfigIntValue("config.subtitles.pango_subtitles_delay");
+                               int subtitle_fps = eConfigManager::getConfigIntValue("config.subtitles.pango_subtitles_fps");
 
                                double convert_fps = 1.0;
                                if (subtitle_fps > 1 && m_framerate > 0)
@@ -2237,9 +2230,7 @@ void eServiceMP3::setAC3Delay(int delay)
                 */
                if (videoSink)
                {
-                       std::string config_delay;
-                       if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
-                               config_delay_int += atoi(config_delay.c_str());
+                       config_delay_int += eConfigManager::getConfigIntValue("config.av.generalAC3delay");
                }
                else
                {
@@ -2270,9 +2261,7 @@ void eServiceMP3::setPCMDelay(int delay)
                 */
                if (videoSink)
                {
-                       std::string config_delay;
-                       if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
-                               config_delay_int += atoi(config_delay.c_str());
+                       config_delay_int += eConfigManager::getConfigIntValue("config.av.generalPCMdelay");
                }
                else
                {
index 82a3386..ff635d6 100644 (file)
@@ -69,9 +69,8 @@ static void addToLogbuffer(int level, const std::string &log)
 
 static const std::string getConfigString(const std::string &key, const std::string &defaultValue)
 {
-       std::string value;
+       std::string value = eConfigManager::getConfigValue(key.c_str());
 
-       ePythonConfigQuery::getConfigValue(key.c_str(), value);
        //we get at least the default value if python is still alive
        if (!value.empty())
                return value;