[SCM] kodi-pvr-hts/master: refactored Settings into a singleton class so it can be included separately instead of having to go through client.h (which is where the "tvh" pointer is declared)
tiber-guest at users.alioth.debian.org
tiber-guest at users.alioth.debian.org
Wed Mar 2 23:01:45 UTC 2016
The following commit has been merged in the master branch:
commit f013946b78e5b4770316883edfdf8028140d7d0a
Author: Sam Stenvall <sam.stenvall at nordsoftware.com>
Date: Wed Oct 14 10:57:39 2015 +0300
refactored Settings into a singleton class so it can be included
separately instead of having to go through client.h (which is
where the "tvh" pointer is declared)
diff --git a/pvr.hts/changelog.txt b/pvr.hts/changelog.txt
index faf8b26..5c1c6aa 100644
--- a/pvr.hts/changelog.txt
+++ b/pvr.hts/changelog.txt
@@ -1,5 +1,6 @@
2.2.9
- refactored the code by factoring out lots of things into separate files
+- refactored the Settings class into a singleton to avoid having to include client.h everywhere
2.2.8
- Updated to PVR API v4.1.0
diff --git a/src/AsyncState.cpp b/src/AsyncState.cpp
index 65c1d07..652033d 100644
--- a/src/AsyncState.cpp
+++ b/src/AsyncState.cpp
@@ -20,7 +20,6 @@
*/
#include "AsyncState.h"
-#include "client.h"
struct Param {
eAsyncState state;
diff --git a/src/AutoRecordings.cpp b/src/AutoRecordings.cpp
index 0ae37ee..3ac4e39 100644
--- a/src/AutoRecordings.cpp
+++ b/src/AutoRecordings.cpp
@@ -22,6 +22,7 @@
#include "AutoRecordings.h"
#include "Tvheadend.h"
+#include "tvheadend/Settings.h"
#include "tvheadend/utilities/Utilities.h"
using namespace PLATFORM;
@@ -190,14 +191,16 @@ PVR_ERROR AutoRecordings::SendAutorecAdd(const PVR_TIMER &timer)
/* */
/* bAutorecApproxTime disabled: => start time in kodi = begin of starting window in tvh */
/* => end time in kodi = end of starting window in tvh */
- if (tvh->GetSettings().bAutorecApproxTime)
+ const Settings &settings = Settings::GetInstance();
+
+ if (settings.bAutorecApproxTime)
{
/* Not sending causes server to set start and startWindow to any time */
if (timer.startTime > 0 && !timer.bStartAnyTime)
{
struct tm *tm_start = localtime(&timer.startTime);
- int32_t startWindowBegin = tm_start->tm_hour * 60 + tm_start->tm_min - tvh->GetSettings().iAutorecMaxDiff;
- int32_t startWindowEnd = tm_start->tm_hour * 60 + tm_start->tm_min + tvh->GetSettings().iAutorecMaxDiff;
+ int32_t startWindowBegin = tm_start->tm_hour * 60 + tm_start->tm_min - settings.iAutorecMaxDiff;
+ int32_t startWindowEnd = tm_start->tm_hour * 60 + tm_start->tm_min + settings.iAutorecMaxDiff;
/* Past midnight correction */
if (startWindowBegin < 0)
diff --git a/src/HTSPConnection.cpp b/src/HTSPConnection.cpp
index 4506667..4b5e043 100644
--- a/src/HTSPConnection.cpp
+++ b/src/HTSPConnection.cpp
@@ -31,11 +31,12 @@ extern "C" {
}
#include "Tvheadend.h"
-#include "client.h"
+#include "tvheadend/Settings.h"
using namespace std;
using namespace ADDON;
using namespace PLATFORM;
+using namespace tvheadend;
/*
* HTSP Response objct
@@ -111,7 +112,7 @@ CHTSPConnection::~CHTSPConnection()
std::string CHTSPConnection::GetWebURL ( const char *fmt, ... )
{
va_list va;
- tvheadend::Settings settings = tvh->GetSettings();
+ const Settings &settings = Settings::GetInstance();
// Generate the authentication string (user:pass@)
std::string auth = settings.strUsername;
@@ -135,7 +136,7 @@ bool CHTSPConnection::WaitForConnection ( void )
{
if (!m_ready) {
tvhtrace("waiting for registration...");
- m_regCond.Wait(m_mutex, m_ready, tvh->GetSettings().iConnectTimeout);
+ m_regCond.Wait(m_mutex, m_ready, Settings::GetInstance().iConnectTimeout);
}
return m_ready;
}
@@ -154,7 +155,7 @@ std::string CHTSPConnection::GetServerVersion ( void )
std::string CHTSPConnection::GetServerString ( void )
{
- tvheadend::Settings settings = tvh->GetSettings();
+ const Settings &settings = Settings::GetInstance();
CLockObject lock(m_mutex);
return StringUtils::Format("%s:%d [%s]", settings.strHostname.c_str(), settings.iPortHTSP,
@@ -230,7 +231,7 @@ bool CHTSPConnection::ReadMessage ( void )
cnt = 0;
while (cnt < len)
{
- r = m_socket->Read((char*)buf + cnt, len - cnt, tvh->GetSettings().iResponseTimeout);
+ r = m_socket->Read((char*)buf + cnt, len - cnt, Settings::GetInstance().iResponseTimeout);
if (r < 0)
{
tvherror("failed to read packet (%s)",
@@ -327,7 +328,7 @@ bool CHTSPConnection::SendMessage0 ( const char *method, htsmsg_t *msg )
htsmsg_t *CHTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int iResponseTimeout )
{
if (iResponseTimeout == -1)
- iResponseTimeout = tvh->GetSettings().iResponseTimeout;
+ iResponseTimeout = Settings::GetInstance().iResponseTimeout;
uint32_t seq;
@@ -388,7 +389,7 @@ htsmsg_t *CHTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int
htsmsg_t *CHTSPConnection::SendAndWait ( const char *method, htsmsg_t *msg, int iResponseTimeout )
{
if (iResponseTimeout == -1)
- iResponseTimeout = tvh->GetSettings().iResponseTimeout;
+ iResponseTimeout = Settings::GetInstance().iResponseTimeout;
if (!WaitForConnection())
return NULL;
@@ -475,8 +476,8 @@ bool CHTSPConnection::SendAuth
*/
void CHTSPConnection::Register ( void )
{
- std::string user = tvh->GetSettings().strUsername;
- std::string pass = tvh->GetSettings().strPassword;
+ std::string user = Settings::GetInstance().strUsername;
+ std::string pass = Settings::GetInstance().strPassword;
{
CLockObject lock(m_mutex);
@@ -527,7 +528,7 @@ void* CHTSPConnection::Process ( void )
{
static bool log = false;
static unsigned int retryAttempt = 0;
- tvheadend::Settings settings = tvh->GetSettings();
+ const Settings &settings = Settings::GetInstance();
while (!IsStopped())
{
diff --git a/src/HTSPDemuxer.cpp b/src/HTSPDemuxer.cpp
index 3a34646..232fbe0 100644
--- a/src/HTSPDemuxer.cpp
+++ b/src/HTSPDemuxer.cpp
@@ -20,7 +20,7 @@
*/
#include "Tvheadend.h"
-#include "client.h"
+#include "tvheadend/Settings.h"
#include "platform/threads/mutex.h"
#include "platform/threads/atomics.h"
@@ -39,6 +39,7 @@ extern "C" {
using namespace std;
using namespace ADDON;
using namespace PLATFORM;
+using namespace tvheadend;
CHTSPDemuxer::CHTSPDemuxer ( CHTSPConnection &conn )
: m_conn(conn), m_pktBuffer((size_t)-1),
@@ -183,7 +184,7 @@ bool CHTSPDemuxer::Seek
htsmsg_destroy(m);
/* Wait for time */
- if (!m_seekCond.Wait(m_conn.Mutex(), m_seekTime, tvh->GetSettings().iResponseTimeout))
+ if (!m_seekCond.Wait(m_conn.Mutex(), m_seekTime, Settings::GetInstance().iResponseTimeout))
{
tvherror("failed to get subscriptionSeek response");
return false;
diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp
index bc2aaf4..8a6f380 100644
--- a/src/Tvheadend.cpp
+++ b/src/Tvheadend.cpp
@@ -38,12 +38,12 @@ using namespace PLATFORM;
using namespace tvheadend;
using namespace tvheadend::entity;
-CTvheadend::CTvheadend(tvheadend::Settings settings)
- : m_settings(settings), m_streamchange(false), m_vfs(m_conn),
- m_queue((size_t)-1), m_asyncState(settings.iResponseTimeout),
+CTvheadend::CTvheadend()
+ : m_streamchange(false), m_vfs(m_conn),
+ m_queue((size_t)-1), m_asyncState(Settings::GetInstance().iResponseTimeout),
m_timeRecordings(m_conn), m_autoRecordings(m_conn)
{
- for (int i = 0; i < 1 || i < m_settings.iTotalTuners; i++)
+ for (int i = 0; i < 1 || i < Settings::GetInstance().iTotalTuners; i++)
{
m_dmx.push_back(new CHTSPDemuxer(m_conn));
}
@@ -286,7 +286,7 @@ PVR_ERROR CTvheadend::SendDvrDelete ( uint32_t id, const char *method )
/* Send and wait a bit longer than usual */
if ((m = m_conn.SendAndWait(method, m,
- std::max(30000, m_settings.iResponseTimeout))) == NULL)
+ std::max(30000, Settings::GetInstance().iResponseTimeout))) == NULL)
return PVR_ERROR_SERVER_ERROR;
/* Check for error */
@@ -711,7 +711,7 @@ PVR_ERROR CTvheadend::GetTimerTypes ( PVR_TIMER_TYPE types[], int *size )
TIMER_REPEATING_EPG_ATTRIBS |= PVR_TIMER_TYPE_SUPPORTS_RECORD_ONLY_NEW_EPISODES;
}
- if (!m_settings.bAutorecApproxTime)
+ if (!Settings::GetInstance().bAutorecApproxTime)
{
/* We need the end time to represent the end of the tvh starting window */
TIMER_REPEATING_EPG_ATTRIBS |= PVR_TIMER_TYPE_SUPPORTS_END_TIME;
@@ -1072,7 +1072,7 @@ PVR_ERROR CTvheadend::GetEpg
(long long)start, (long long)end);
/* Async transfer */
- if (m_settings.bAsyncEpg)
+ if (Settings::GetInstance().bAsyncEpg)
{
if (!m_asyncState.WaitForState(ASYNC_DONE))
return PVR_ERROR_FAILED;
@@ -1174,7 +1174,7 @@ bool CTvheadend::Connected ( void )
m_asyncState.SetState(ASYNC_NONE);
msg = htsmsg_create_map();
- htsmsg_add_u32(msg, "epg", m_settings.bAsyncEpg);
+ htsmsg_add_u32(msg, "epg", Settings::GetInstance().bAsyncEpg);
//htsmsg_add_u32(msg, "epgMaxTime", 0);
//htsmsg_add_s64(msg, "lastUpdate", 0);
if ((msg = m_conn.SendAndWait0("enableAsyncMetadata", msg)) == NULL)
@@ -1411,7 +1411,7 @@ void CTvheadend::SyncDvrCompleted ( void )
void CTvheadend::SyncEpgCompleted ( void )
{
/* Done */
- if (!m_settings.bAsyncEpg || m_asyncState.GetState() > ASYNC_EPG)
+ if (!Settings::GetInstance().bAsyncEpg || m_asyncState.GetState() > ASYNC_EPG)
return;
/* Schedules */
@@ -2068,8 +2068,8 @@ DemuxPacket* CTvheadend::DemuxRead ( void )
pkt = dmx->Read();
else
{
- if (dmx->GetChannelId() && m_settings.iPreTuneCloseDelay &&
- dmx->GetLastUse() + m_settings.iPreTuneCloseDelay < time(NULL))
+ if (dmx->GetChannelId() && Settings::GetInstance().iPreTuneCloseDelay &&
+ dmx->GetLastUse() + Settings::GetInstance().iPreTuneCloseDelay < time(NULL))
{
tvhtrace("untuning channel %u on subscription %u",
m_channels[dmx->GetChannelId()].GetNum(), dmx->GetSubscriptionId());
diff --git a/src/Tvheadend.h b/src/Tvheadend.h
index a7d82b3..493e373 100644
--- a/src/Tvheadend.h
+++ b/src/Tvheadend.h
@@ -80,7 +80,7 @@ extern "C" {
#define tvhdebug(...) tvhlog(ADDON::LOG_DEBUG, ##__VA_ARGS__)
#define tvhinfo(...) tvhlog(ADDON::LOG_INFO, ##__VA_ARGS__)
#define tvherror(...) tvhlog(ADDON::LOG_ERROR, ##__VA_ARGS__)
-#define tvhtrace(...) if (tvh->GetSettings().bTraceDebug) tvhlog(ADDON::LOG_DEBUG, ##__VA_ARGS__)
+#define tvhtrace(...) if (tvheadend::Settings::GetInstance().bTraceDebug) tvhlog(ADDON::LOG_DEBUG, ##__VA_ARGS__)
static inline void tvhlog ( ADDON::addon_log_t lvl, const char *fmt, ... )
{
char buf[16384];
@@ -367,7 +367,7 @@ class CTvheadend
: public PLATFORM::CThread
{
public:
- CTvheadend(tvheadend::Settings settings);
+ CTvheadend();
~CTvheadend();
void Start ( void );
@@ -376,11 +376,6 @@ public:
bool Connected ( void );
bool ProcessMessage ( const char *method, htsmsg_t *msg );
- inline const tvheadend::Settings& GetSettings () const
- {
- return m_settings;
- };
-
const tvheadend::entity::Channels& GetChannels () const
{
return m_channels;
@@ -419,7 +414,6 @@ private:
std::string GetImageURL ( const char *str );
PLATFORM::CMutex m_mutex;
- const tvheadend::Settings m_settings;
CHTSPConnection m_conn;
diff --git a/src/client.cpp b/src/client.cpp
index 6941d8c..d473bab 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -25,8 +25,8 @@
#include "platform/threads/mutex.h"
#include "platform/threads/atomics.h"
#include "platform/util/util.h"
-#include "tvheadend/Settings.h"
#include "Tvheadend.h"
+#include "tvheadend/Settings.h"
using namespace std;
using namespace ADDON;
@@ -142,7 +142,7 @@ ADDON_STATUS ADDON_Create(void* hdl, void* _unused(props))
ADDON_ReadSettings();
/* Create a settings object that can be used without locks */
- tvheadend::Settings settings;
+ tvheadend::Settings &settings = tvheadend::Settings::GetInstance();
settings.strHostname = g_strHostname;
settings.iPortHTSP = g_iPortHTSP;
settings.iPortHTTP = g_iPortHTTP;
@@ -170,7 +170,7 @@ ADDON_STATUS ADDON_Create(void* hdl, void* _unused(props))
settings.bAutorecApproxTime = (g_iAutorecApproxTime > 0);
settings.iAutorecMaxDiff = g_iAutorecMaxDiff;
- tvh = new CTvheadend(settings);
+ tvh = new CTvheadend();
tvh->Start();
/* Wait for connection */
diff --git a/src/tvheadend/Settings.h b/src/tvheadend/Settings.h
index 4b42fbd..2b8d090 100644
--- a/src/tvheadend/Settings.h
+++ b/src/tvheadend/Settings.h
@@ -25,7 +25,21 @@
namespace tvheadend {
- struct Settings {
+ /**
+ * Represents the current addon settings
+ */
+ class Settings {
+ public:
+
+ /**
+ * Singleton getter for the instance
+ */
+ static Settings& GetInstance()
+ {
+ static Settings settings;
+ return settings;
+ }
+
std::string strHostname;
int iPortHTSP;
int iPortHTTP;
@@ -39,6 +53,11 @@ namespace tvheadend {
int iPreTuneCloseDelay;
bool bAutorecApproxTime;
int iAutorecMaxDiff;
+
+ private:
+ Settings() { }
+ Settings(Settings const &) = delete;
+ void operator=(Settings const &) = delete;
};
}
\ No newline at end of file
diff --git a/src/tvheadend/entity/AutoRecording.cpp b/src/tvheadend/entity/AutoRecording.cpp
index 960ccf2..106afea 100644
--- a/src/tvheadend/entity/AutoRecording.cpp
+++ b/src/tvheadend/entity/AutoRecording.cpp
@@ -21,8 +21,10 @@
#include "AutoRecording.h"
+#include "../Settings.h"
#include "../../Tvheadend.h"
+using namespace tvheadend;
using namespace tvheadend::entity;
AutoRecording::AutoRecording(const std::string &id /*= ""*/) :
@@ -54,7 +56,7 @@ bool AutoRecording::operator!=(const AutoRecording &right)
time_t AutoRecording::GetStart() const
{
- if (tvh->GetSettings().bAutorecApproxTime)
+ if (Settings::GetInstance().bAutorecApproxTime)
{
/* Calculate the approximate start time from the starting window */
if ((m_startWindowBegin == int32_t(-1)) ||
@@ -90,7 +92,7 @@ void AutoRecording::SetStartWindowBegin(int32_t start)
time_t AutoRecording::GetStop() const
{
- if (tvh->GetSettings().bAutorecApproxTime)
+ if (Settings::GetInstance().bAutorecApproxTime)
{
/* Tvh doesn't have an approximate stop time => "any time" */
return 0;
--
kodi-pvr-hts packaging
More information about the pkg-multimedia-commits
mailing list