summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2009-01-07 14:59:04 +0100
committerChristian Gmeiner <christian.gmeiner@gmail.com>2009-01-07 14:59:04 +0100
commitb97736a0a89ecbc3aa2ece133cc0a4839bd1e043 (patch)
treee4e5ae12f626bbabf8f469491d4a07b76418616e
parentb17bb75da5810312f1c29d93d92931a4a0fc87f5 (diff)
downloadvdr-plugin-dxr3-b97736a0a89ecbc3aa2ece133cc0a4839bd1e043.tar.gz
vdr-plugin-dxr3-b97736a0a89ecbc3aa2ece133cc0a4839bd1e043.tar.bz2
better singleton template
With the old singleton pattern it could happen that two instances are created. See... static T& Instance() { static T m_Instance; return m_Instance; } static T* InstanceP() { static T* m_InstanceP = new T; return m_InstanceP; }
-rw-r--r--Makefile6
-rw-r--r--dxr3.c14
-rw-r--r--dxr3singleton.h30
3 files changed, 22 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 0efa259..d8183a6 100644
--- a/Makefile
+++ b/Makefile
@@ -20,10 +20,10 @@ CXXFLAGS = -O2 -Wall -Woverloaded-virtual
### The directory environment:
-VDRDIR = ../../..
-LIBDIR = ../../lib
+VDRDIR = /usr/include/vdr
+LIBDIR = .
TMPDIR = /tmp
-FFMDIR = /usr/local/include/ffmpeg
+FFMDIR = /usr//include/libavcodec
EM8300 = /usr/include
### Allow user defined options to overwrite defaults:
diff --git a/dxr3.c b/dxr3.c
index 264aa72..bfa715b 100644
--- a/dxr3.c
+++ b/dxr3.c
@@ -33,8 +33,7 @@ eOSState cDxr3OsdItem::ProcessKey(eKeys Key)
{
case DXR3_RESET_HARDWARE:
cDxr3Interface::Instance().ResetHardware();
- if (cDxr3Device::InstanceP())
- cDxr3Device::InstanceP()->Reset();
+ cDxr3Device::Instance().Reset();
break;
case DXR3_FORCE_LETTER_BOX:
@@ -44,14 +43,12 @@ eOSState cDxr3OsdItem::ProcessKey(eKeys Key)
case DXR3_ANALOG_OUT:
cDxr3ConfigData::Instance().SetUseDigitalOut(0);
- if (cDxr3Device::InstanceP())
- cDxr3Device::InstanceP()->Reset();
+ cDxr3Device::Instance().Reset();
break;
case DXR3_DIGITAL_OUT:
cDxr3ConfigData::Instance().SetUseDigitalOut(1);
- if (cDxr3Device::InstanceP())
- cDxr3Device::InstanceP()->Reset();
+ cDxr3Device::Instance().Reset();
break;
}
}
@@ -123,8 +120,7 @@ void cMenuSetupDxr3::Store(void)
cDxr3Interface::Instance().SetBrightness(newBrightness);
cDxr3Interface::Instance().SetContrast(newContrast);
cDxr3Interface::Instance().SetSaturation(newSaturation);
- if (cDxr3Device::InstanceP())
- cDxr3Device::InstanceP()->Reset();
+ cDxr3Device::Instance().Reset();
}
// ==================================
@@ -175,7 +171,7 @@ cPluginDxr3::~cPluginDxr3()
// ==================================
bool cPluginDxr3::Initialize()
{
- cDxr3Device::InstanceP();
+ cDxr3Device::Instance();
return true;
}
diff --git a/dxr3singleton.h b/dxr3singleton.h
index b289328..ebfbe42 100644
--- a/dxr3singleton.h
+++ b/dxr3singleton.h
@@ -28,27 +28,25 @@
Is a nice solution to use only
one instance of a class.
*/
-template<typename T>
-class Singleton
-{
+template <class T>
+class Singleton {
+public:
+ virtual ~Singleton() {}
+ static T& Instance();
+
protected:
Singleton() {}
- virtual ~Singleton() {}
-public:
- static T& Instance()
- {
- static T m_Instance;
- return m_Instance;
- }
-
- static T* InstanceP()
- {
- static T* m_InstanceP = new T;
- return m_InstanceP;
- }
+private:
+ Singleton(const Singleton&);
};
+template <class T>
+T& Singleton<T>::Instance() {
+ static T instance;
+ return instance;
+}
+
#endif /*_DXR3_SINGLETON_H_*/
// Local variables: