summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2010-01-04 09:12:12 +0100
committerChristian Gmeiner <christian.gmeiner@gmail.com>2010-01-04 09:12:12 +0100
commit5aeb6af61490df93ff8be39cf62fe7782fe4674b (patch)
treedf3572c4b245b3b831758e281a927fb8f11a2264
parent3c5629fad2272c1ebe2343dfc233afb50d38292a (diff)
downloadvdr-plugin-dxr3-5aeb6af61490df93ff8be39cf62fe7782fe4674b.tar.gz
vdr-plugin-dxr3-5aeb6af61490df93ff8be39cf62fe7782fe4674b.tar.bz2
rework cSettings class to use a new way for setters and getters
The basic idea behind this commit is to get rid of those bad looking getters and setters, where we have no logic used by them.
-rw-r--r--Makefile2
-rw-r--r--accessors.h47
-rw-r--r--dxr3.c66
-rw-r--r--dxr3.h2
-rw-r--r--dxr3audio-alsa.c2
-rw-r--r--dxr3interface.c16
-rw-r--r--dxr3interface.h2
-rw-r--r--settings.c46
-rw-r--r--settings.h45
9 files changed, 105 insertions, 123 deletions
diff --git a/Makefile b/Makefile
index 07403a7..0eec9a8 100644
--- a/Makefile
+++ b/Makefile
@@ -68,7 +68,7 @@ DEFINES += -DMICROCODE=\"/lib/firmware/em8300.bin\"
OBJS = $(PLUGIN).o dxr3multichannelaudio.o \
dxr3syncbuffer.o dxr3audiodecoder.o dxr3blackframe.o dxr3audio.o \
- dxr3pesframe.o dxr3demuxdevice.o settings.o \
+ dxr3pesframe.o dxr3demuxdevice.o \
dxr3interface.o dxr3device.o \
dxr3output.o dxr3output-video.o dxr3output-audio.o dxr3osd.o dxr3spudecoder.o \
dxr3audio-oss.o dxr3audio-alsa.o spuencoder.o spuregion.o scaler.o
diff --git a/accessors.h b/accessors.h
new file mode 100644
index 0000000..708b266
--- /dev/null
+++ b/accessors.h
@@ -0,0 +1,47 @@
+/*
+ * _ _ _ _ _____
+ * __ ____| |_ __ _ __ | |_ _ __ _(_)_ __ __| |_ ___ _|___ /
+ * \ \ / / _` | '__|____| '_ \| | | | |/ _` | | '_ \ _____ / _` \ \/ / '__||_ \
+ * \ V / (_| | | |_____| |_) | | |_| | (_| | | | | |_____| (_| |> <| | ___) |
+ * \_/ \__,_|_| | .__/|_|\__,_|\__, |_|_| |_| \__,_/_/\_\_| |____/
+ * |_| |___/
+ *
+ * Copyright (C) 2010 Christian Gmeiner
+ *
+ * This file is part of vdr-plugin-dxr3.
+ *
+ * vdr-plugin-dxr3 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 version 2.
+ *
+ * vdr-plugin-dxr3 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 dxr3-plugin. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef ACCESSORS_H
+#define ACCESSORS_H
+
+// based on a very good idea from
+// * http://www.kirit.com/C%2B%2B%20killed%20the%20get%20%26%20set%20accessors
+// * http://www.kirit.com/C%2B%2B%20killed%20the%20get%20%26%20set%20accessors/A%20simple%20meta-accessor
+
+template<typename T>
+class Accessors {
+public:
+ Accessors() {}
+ explicit Accessors(const T &t) : m_t(t) {}
+
+ const T &operator() () const { return m_t; }
+ T operator() (const T &t) { return m_t = t; }
+
+private:
+ T m_t;
+};
+
+#endif /*ACCESSORS_H*/
diff --git a/dxr3.c b/dxr3.c
index d341512..8494f6d 100644
--- a/dxr3.c
+++ b/dxr3.c
@@ -34,17 +34,17 @@ eOSState cDxr3OsdItem::ProcessKey(eKeys Key)
break;
case DXR3_FORCE_LETTER_BOX:
- cSettings::instance()->SetForceLetterBox(
- !cSettings::instance()->GetForceLetterBox());
+ cSettings::instance()->forceLetterBox(
+ !cSettings::instance()->forceLetterBox());
break;
case DXR3_ANALOG_OUT:
- cSettings::instance()->SetUseDigitalOut(0);
+ cSettings::instance()->useDigitalOut(0);
//cDxr3Device::Instance().Reset();
break;
case DXR3_DIGITAL_OUT:
- cSettings::instance()->SetUseDigitalOut(1);
+ cSettings::instance()->useDigitalOut(1);
//cDxr3Device::Instance().Reset();
break;
}
@@ -57,31 +57,31 @@ eOSState cDxr3OsdItem::ProcessKey(eKeys Key)
// setup menu
cMenuSetupDxr3::cMenuSetupDxr3(void)
{
- newBrightness = cSettings::instance()->GetBrightness();
+ newBrightness = cSettings::instance()->brightness();
Add(new cMenuEditIntItem(tr("Brightness"),
&newBrightness, 0, 999));
- newContrast = cSettings::instance()->GetContrast();
+ newContrast = cSettings::instance()->contrast();
Add(new cMenuEditIntItem(tr("Contrast"),
&newContrast, 0, 999));
- newSaturation = cSettings::instance()->GetSaturation();
+ newSaturation = cSettings::instance()->saturation();
Add(new cMenuEditIntItem(tr("Saturation"),
&newSaturation, 0, 999));
- newVideoMode = (int) cSettings::instance()->GetVideoMode();
+ newVideoMode = (int) cSettings::instance()->videoMode();
menuVideoModes[0] = tr("PAL");
menuVideoModes[1] = tr("PAL60");
menuVideoModes[2] = tr("NTSC");
Add(new cMenuEditStraItem(tr("Video mode"),
&newVideoMode, 3, menuVideoModes));
- newUseWSS = cSettings::instance()->GetUseWSS();
+ newUseWSS = cSettings::instance()->useWss();
#ifdef EM8300_IOCTL_SET_WSS
Add(new cMenuEditBoolItem(tr("Use widescreen signaling (WSS)"),
&newUseWSS));
#endif
- newUseDigitalOut = cSettings::instance()->GetUseDigitalOut();
+ newUseDigitalOut = cSettings::instance()->useDigitalOut();
Add(new cMenuEditBoolItem(tr("Digital audio output"), &newUseDigitalOut));
- newHideMenu = cSettings::instance()->GetHideMenu();
+ newHideMenu = cSettings::instance()->hideMenu();
Add(new cMenuEditBoolItem(tr("Hide main menu entry"), &newHideMenu));
- newDxr3Card = cSettings::instance()->GetDxr3Card();
+ newDxr3Card = cSettings::instance()->card();
Add(new cMenuEditIntItem(tr("Card number"),
&newDxr3Card, 0, DXR3_MAX_CARDS - 1));
}
@@ -91,22 +91,22 @@ cMenuSetupDxr3::cMenuSetupDxr3(void)
void cMenuSetupDxr3::Store(void)
{
SetupStore("Brightness",
- cSettings::instance()->SetBrightness(newBrightness));
+ cSettings::instance()->brightness(newBrightness));
SetupStore("Contrast",
- cSettings::instance()->SetContrast(newContrast));
+ cSettings::instance()->contrast(newContrast));
SetupStore("Saturation",
- cSettings::instance()->SetSaturation(newSaturation));
+ cSettings::instance()->saturation(newSaturation));
SetupStore("Dxr3VideoMode",
- cSettings::instance()->SetVideoMode(
- (eVideoMode) newVideoMode));
+ cSettings::instance()->videoMode((eVideoMode) newVideoMode));
SetupStore("UseWSS",
- cSettings::instance()->SetUseWSS(newUseWSS));
+ cSettings::instance()->useWss(newUseWSS));
SetupStore("UseDigitalOut",
- cSettings::instance()->SetUseDigitalOut(newUseDigitalOut));
+ cSettings::instance()->useDigitalOut(newUseDigitalOut));
SetupStore("HideMenu",
- cSettings::instance()->SetHideMenu(newHideMenu));
+ cSettings::instance()->hideMenu(newHideMenu));
SetupStore("Dxr3Card",
- cSettings::instance()->SetDxr3Card(newDxr3Card));
+ cSettings::instance()->card(newDxr3Card));
+
// Apply (some of the) settings
cDxr3Interface::instance()->updateBcsValues();
@@ -170,42 +170,42 @@ bool cPluginDxr3::SetupParse(const char *Name, const char *Value)
{
if (!strcasecmp(Name, "UseDigitalOut"))
{
- cSettings::instance()->SetUseDigitalOut(atoi(Value));
+ cSettings::instance()->useDigitalOut(atoi(Value));
return true;
}
if (!strcasecmp(Name, "Dxr3Card"))
{
- cSettings::instance()->SetDxr3Card(atoi(Value));
+ cSettings::instance()->card(atoi(Value));
return true;
}
if (!strcasecmp(Name, "Dxr3VideoMode"))
{
- cSettings::instance()->SetVideoMode((eVideoMode) atoi(Value));
+ cSettings::instance()->videoMode((eVideoMode) atoi(Value));
return true;
}
if (!strcasecmp(Name, "UseWSS"))
{
- cSettings::instance()->SetUseWSS(atoi(Value));
+ cSettings::instance()->useWss(atoi(Value));
return true;
}
if (!strcasecmp(Name, "HideMenu"))
{
- cSettings::instance()->SetHideMenu(atoi(Value));
+ cSettings::instance()->hideMenu(atoi(Value));
return true;
}
if (!strcasecmp(Name, "Brightness"))
{
- cSettings::instance()->SetBrightness(atoi(Value));
+ cSettings::instance()->brightness(atoi(Value));
return true;
}
if (!strcasecmp(Name, "Contrast"))
{
- cSettings::instance()->SetContrast(atoi(Value));
+ cSettings::instance()->contrast(atoi(Value));
return true;
}
if (!strcasecmp(Name, "Saturation"))
{
- cSettings::instance()->SetSaturation(atoi(Value));
+ cSettings::instance()->saturation(atoi(Value));
return true;
}
@@ -215,7 +215,7 @@ bool cPluginDxr3::SetupParse(const char *Name, const char *Value)
// ==================================
const char* cPluginDxr3::MainMenuEntry()
{
- return cSettings::instance()->GetHideMenu() ?
+ return cSettings::instance()->hideMenu() ?
NULL : tr(MAINMENUENTRY);
}
@@ -260,17 +260,17 @@ cString cPluginDxr3::SVDRPCommand(const char *Command, const char *Option,
int value = atoi(Option);
if (!strcasecmp(Command, "BRI")) {
- cSettings::instance()->SetBrightness(value);
+ cSettings::instance()->brightness(value);
cDxr3Interface::instance()->updateBcsValues();
return cString::sprintf("Brightness set to %d", value);
}
if (!strcasecmp(Command, "CON")) {
- cSettings::instance()->SetContrast(value);
+ cSettings::instance()->contrast(value);
cDxr3Interface::instance()->updateBcsValues();
return cString::sprintf("Contrast set to %d", value);
}
if (!strcasecmp(Command, "SAT")) {
- cSettings::instance()->SetSaturation(value);
+ cSettings::instance()->saturation(value);
cDxr3Interface::instance()->updateBcsValues();
return cString::sprintf("Saturation set to %d", value);
}
diff --git a/dxr3.h b/dxr3.h
index 9bbceb9..2eb9eb7 100644
--- a/dxr3.h
+++ b/dxr3.h
@@ -69,7 +69,7 @@ public:
Add(new cDxr3OsdItem(hk(tr("Toggle force letterbox")),
DXR3_FORCE_LETTER_BOX));
- if (cSettings::instance()->GetUseDigitalOut())
+ if (cSettings::instance()->useDigitalOut())
Add(new cDxr3OsdItem(hk(tr("Switch to analog audio output")),
DXR3_ANALOG_OUT));
else
diff --git a/dxr3audio-alsa.c b/dxr3audio-alsa.c
index 2c411f9..46e5332 100644
--- a/dxr3audio-alsa.c
+++ b/dxr3audio-alsa.c
@@ -30,7 +30,7 @@ void cAudioAlsa::openDevice()
return;
// generate alsa card name
- int card = cSettings::instance()->GetDxr3Card();
+ int card = cSettings::instance()->card();
string cardname = "EM8300";
if (card > 0) {
diff --git a/dxr3interface.c b/dxr3interface.c
index ff6066b..f5563cb 100644
--- a/dxr3interface.c
+++ b/dxr3interface.c
@@ -147,7 +147,7 @@ void cDxr3Interface::SetAspectRatio(uint32_t ratio)
Lock();
- if (cSettings::instance()->GetForceLetterBox())
+ if (cSettings::instance()->forceLetterBox())
ratio = EM8300_ASPECTRATIO_16_9;
if (ratio != UNKNOWN_ASPECT_RATIO)
@@ -490,7 +490,7 @@ void cDxr3Interface::UploadMicroCode()
//! config and setup device via ioctl calls
void cDxr3Interface::ConfigureDevice()
{
- uint32_t videomode = cSettings::instance()->GetVideoMode();
+ uint32_t videomode = cSettings::instance()->videoMode();
switch (videomode) {
case PAL:
@@ -511,9 +511,9 @@ void cDxr3Interface::ConfigureDevice()
}
// set brightness/contrast/saturation
- m_bcs.brightness = cSettings::instance()->GetBrightness();
- m_bcs.contrast = cSettings::instance()->GetContrast();
- m_bcs.saturation = cSettings::instance()->GetSaturation();
+ m_bcs.brightness = cSettings::instance()->brightness();
+ m_bcs.contrast = cSettings::instance()->contrast();
+ m_bcs.saturation = cSettings::instance()->saturation();
dsyslog("dxr3: configure: brightness=%d,contrast=%d,saturation=%d",
m_bcs.brightness, m_bcs.contrast, m_bcs.saturation);
if (ioctl(m_fdControl, EM8300_IOCTL_SETBCS, &m_bcs) == -1) {
@@ -609,9 +609,9 @@ void cDxr3Interface::ResetHardware()
void cDxr3Interface::updateBcsValues()
{
// update m_bcs with values from settings
- m_bcs.brightness = cSettings::instance()->GetBrightness();
- m_bcs.contrast = cSettings::instance()->GetContrast();
- m_bcs.saturation = cSettings::instance()->GetSaturation();
+ m_bcs.brightness = cSettings::instance()->brightness();
+ m_bcs.contrast = cSettings::instance()->contrast();
+ m_bcs.saturation = cSettings::instance()->saturation();
// update bcs values in hardware
CHECK(ioctl(m_fdControl, EM8300_IOCTL_SETBCS, &m_bcs));
diff --git a/dxr3interface.h b/dxr3interface.h
index 0392654..96d551a 100644
--- a/dxr3interface.h
+++ b/dxr3interface.h
@@ -58,7 +58,7 @@ public:
~cDxr3Interface();
static int Dxr3Open(const char *name, int mode, bool report_error = true) {
- const char *filename = *cDxr3Name(name, cSettings::instance()->GetDxr3Card());
+ const char *filename = *cDxr3Name(name, cSettings::instance()->card());
int fd = open(filename, mode);
if (report_error && (fd < 0)) {
diff --git a/settings.c b/settings.c
deleted file mode 100644
index be60c21..0000000
--- a/settings.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * dxr3configdata.c
- *
- * Copyright (C) 2002-2004 Kai Möller
- * Copyright (C) 2004 Christian Gmeiner
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include "settings.h"
-
-// ==================================
-//! constructor
-cSettings::cSettings()
-{
- m_digitaloutput = 0;
- m_card = 0;
- m_forceletterbox = 0;
- m_videomode = PAL;
- m_brightness = 500;
- m_contrast = 500;
- m_saturation = 500;
- m_hidemenu = 0;
- m_usewss = 0;
-}
-
-// Local variables:
-// mode: c++
-// c-file-style: "stroustrup"
-// c-file-offsets: ((inline-open . 0))
-// tab-width: 4;
-// indent-tabs-mode: nil
-// End:
diff --git a/settings.h b/settings.h
index 78486fd..2ab7075 100644
--- a/settings.h
+++ b/settings.h
@@ -24,6 +24,7 @@
#define _DXR3_CONFIGDATA_H_
#include "singleton.h"
+#include "accessors.h"
#include <linux/em8300.h>
// ==================================
@@ -44,41 +45,21 @@ enum eVideoMode
class cSettings : public Singleton<cSettings>
{
public:
- cSettings();
+ cSettings() : useDigitalOut(0), card(0), forceLetterBox(0), videoMode(PAL),
+ brightness(500), contrast(500), saturation(500),
+ hideMenu(0), useWss(0) {}
- int GetUseDigitalOut() const { return m_digitaloutput; }
- int SetUseDigitalOut(int value) { return m_digitaloutput = value; }
- int GetDxr3Card() const { return m_card; }
- int SetDxr3Card(int value) { return m_card = value; }
- int GetForceLetterBox() const { return m_forceletterbox; }
- int SetForceLetterBox(int value) { return m_forceletterbox = value; }
+ Accessors<int> useDigitalOut;
+ Accessors<int> card;
+ Accessors<int> forceLetterBox;
+ Accessors<eVideoMode> videoMode;
- eVideoMode GetVideoMode() const { return m_videomode; }
- eVideoMode SetVideoMode(eVideoMode m) { return m_videomode = m; }
+ Accessors<int> brightness;
+ Accessors<int> contrast;
+ Accessors<int> saturation;
- int GetBrightness() const { return m_brightness; }
- int SetBrightness(int value) { return m_brightness = value; }
- int GetContrast() const { return m_contrast; }
- int SetContrast(int value) { return m_contrast = value; }
- int GetSaturation() const { return m_saturation; }
- int SetSaturation(int value) { return m_saturation = value; }
-
- int GetHideMenu() const { return m_hidemenu; }
- int SetHideMenu(int value) { return m_hidemenu = value; }
-
- int GetUseWSS() const { return m_usewss; }
- int SetUseWSS(int value) { return m_usewss = value; }
-
-private:
- eVideoMode m_videomode;
- int m_usewss;
- int m_digitaloutput;
- int m_card;
- int m_forceletterbox;
- int m_brightness;
- int m_contrast;
- int m_saturation;
- int m_hidemenu;
+ Accessors<int> hideMenu;
+ Accessors<int> useWss;
};
#endif /*_DXR3_CONFIGDATA_H_*/