Skip to content

Commit

Permalink
Remove classes Configuration and DBConfiguration
Browse files Browse the repository at this point in the history
The Configuration DBConfiguration has always been a shim to the
database see commit 85bb976
so I have replaced those few uses in mediaserver.cpp with direct
GetMythDB() database accesses.

However, setting a DBConfiguration to the global Configuration
was incorrect since the UPnP code looks for values that are
not present in the database, only optionally present in config.xml.

Note: I now have UDNs for MediaRenderer, MediaServer, and MasterMediaServer
in config.xml.  However, I also had UPnP/UDN/* in the settings table of my
database.
  • Loading branch information
ulmus-scott authored and bennettpeter committed Nov 18, 2022
1 parent d8976e5 commit bda2c8b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 229 deletions.
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/backendselect.cpp
Expand Up @@ -16,7 +16,7 @@

BackendSelection::BackendSelection(
MythScreenStack *parent, DatabaseParams *params,
Configuration *pConfig, bool exitOnFinish) :
XmlConfiguration *pConfig, bool exitOnFinish) :
MythScreenType(parent, "BackEnd Selection"),
m_dbParams(params), m_pConfig(pConfig), m_exitOnFinish(exitOnFinish)
{
Expand Down Expand Up @@ -46,7 +46,7 @@ BackendSelection::~BackendSelection()
}

BackendSelection::Decision BackendSelection::Prompt(
DatabaseParams *dbParams, Configuration *pConfig)
DatabaseParams *dbParams, XmlConfiguration *pConfig)
{
Decision ret = kCancelConfigure;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/backendselect.h
Expand Up @@ -45,10 +45,10 @@ class BackendSelection : public MythScreenType
kAcceptConfigure = +1,
};
static Decision Prompt(
DatabaseParams *dbParams, Configuration *pConfig);
DatabaseParams *dbParams, XmlConfiguration *pConfig);

BackendSelection(MythScreenStack *parent, DatabaseParams *params,
Configuration *pConfig, bool exitOnFinish = false);
XmlConfiguration *pConfig, bool exitOnFinish = false);
~BackendSelection() override;

bool Create(void) override; // MythScreenType
Expand All @@ -72,7 +72,7 @@ class BackendSelection : public MythScreenType
void CloseWithDecision(Decision d);

DatabaseParams *m_dbParams {nullptr};
Configuration *m_pConfig {nullptr};
XmlConfiguration *m_pConfig {nullptr};
bool m_exitOnFinish;
ItemMap m_devices;

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/mythcontext.cpp
Expand Up @@ -116,7 +116,7 @@ class MythContextPrivate : public QObject
DatabaseParams m_dbParams; ///< Current database host & WOL details
QString m_dbHostCp; ///< dbHostName backup

Configuration *m_pConfig {nullptr};
XmlConfiguration *m_pConfig {nullptr};

bool m_disableeventpopup {false};

Expand Down
108 changes: 0 additions & 108 deletions mythtv/libs/libmythbase/configuration.cpp
Expand Up @@ -24,10 +24,6 @@
#include "mythdirs.h"
#include "compat.h"

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

XmlConfiguration::XmlConfiguration( const QString &sFileName )
{
m_sPath = GetConfDir();
Expand All @@ -36,10 +32,6 @@ XmlConfiguration::XmlConfiguration( const QString &sFileName )
XmlConfiguration::Load();
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

bool XmlConfiguration::Load( void )
{
QString sName = m_sPath + '/' + m_sFileName;
Expand Down Expand Up @@ -81,10 +73,6 @@ bool XmlConfiguration::Load( void )
return true;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

bool XmlConfiguration::Save( void )
{
if (m_sFileName.isEmpty()) // Special case. No file is created
Expand Down Expand Up @@ -158,10 +146,6 @@ bool XmlConfiguration::Save( void )
return ok;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

QDomNode XmlConfiguration::FindNode( const QString &sName, bool bCreate )
{
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
Expand All @@ -174,10 +158,6 @@ QDomNode XmlConfiguration::FindNode( const QString &sName, bool bCreate )

}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

QDomNode XmlConfiguration::FindNode( QStringList &sParts, QDomNode &curNode, bool bCreate )
{
if (sParts.empty())
Expand All @@ -203,10 +183,6 @@ QDomNode XmlConfiguration::FindNode( QStringList &sParts, QDomNode &curNode, boo
return FindNode( sParts, child, bCreate );
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

int XmlConfiguration::GetValue( const QString &sSetting, int nDefault )
{
QDomNode node = FindNode( sSetting );
Expand All @@ -223,10 +199,6 @@ int XmlConfiguration::GetValue( const QString &sSetting, int nDefault )
return nDefault;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

QString XmlConfiguration::GetValue( const QString &sSetting, const QString &sDefault )
{
QDomNode node = FindNode( sSetting );
Expand All @@ -243,10 +215,6 @@ QString XmlConfiguration::GetValue( const QString &sSetting, const QString &sDef
return sDefault;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void XmlConfiguration::SetValue( const QString &sSetting, int nValue )
{
QString sValue = QString::number( nValue );
Expand All @@ -270,10 +238,6 @@ void XmlConfiguration::SetValue( const QString &sSetting, int nValue )
}
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void XmlConfiguration::SetValue( const QString &sSetting, const QString& sValue )
{
QDomNode node = FindNode( sSetting, true );
Expand All @@ -296,10 +260,6 @@ void XmlConfiguration::SetValue( const QString &sSetting, const QString& sValue
}
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void XmlConfiguration::ClearValue( const QString &sSetting )
{
QDomNode node = FindNode(sSetting);
Expand All @@ -315,71 +275,3 @@ void XmlConfiguration::ClearValue( const QString &sSetting )
}
}
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Uses MythContext to access settings in Database
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

bool DBConfiguration::Load( void )
{
return true;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

bool DBConfiguration::Save( void )
{
return true;
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

int DBConfiguration::GetValue( const QString &sSetting, int nDefault )
{
return GetMythDB()->GetNumSetting( sSetting, nDefault );
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

QString DBConfiguration::GetValue( const QString &sSetting, const QString& sDefault )
{
return GetMythDB()->GetSetting( sSetting, sDefault );
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void DBConfiguration::SetValue( const QString &sSetting, int nValue )
{
GetMythDB()->SaveSetting( sSetting, nValue );

}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void DBConfiguration::SetValue( const QString &sSetting, const QString& sValue )
{
GetMythDB()->SaveSetting( sSetting, sValue );
}

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

void DBConfiguration::ClearValue( const QString &sSetting )
{
GetMythDB()->ClearSetting( sSetting );
}
88 changes: 22 additions & 66 deletions mythtv/libs/libmythbase/configuration.h
Expand Up @@ -18,35 +18,6 @@
#include "libmythbase/mythbaseexp.h"
#include "libmythbase/mythchrono.h"

class MBASE_PUBLIC Configuration
{
public:

virtual ~Configuration() = default;

virtual bool Load ( void ) = 0;
virtual bool Save ( void ) = 0;

virtual int GetValue( const QString &sSetting, int Default ) = 0;
virtual QString GetValue( const QString &sSetting, const QString &Default ) = 0;
virtual bool GetBoolValue( const QString &sSetting, bool Default ) = 0;

virtual void SetValue( const QString &sSetting, int value ) = 0;
virtual void SetValue( const QString &sSetting, const QString &value ) = 0;
virtual void ClearValue( const QString &sSetting ) = 0;
virtual void SetBoolValue( const QString &sSetting, bool value ) = 0;

template <typename T>
typename std::enable_if<std::chrono::__is_duration<T>::value, T>::type
GetDuration(const QString &sSetting, T defaultval = T::zero())
{ return T(GetValue(sSetting, static_cast<int>(defaultval.count()))); }
template <typename T>
typename std::enable_if<std::chrono::__is_duration<T>::value, void>::type
SetDuration(const QString &sSetting, T value)
{ SetValue(sSetting, static_cast<int>(value.count())); }
};


//////////////////////////////////////////////////////////////////////////////
//
// **NOTE: Performance Issue ***
Expand All @@ -57,7 +28,7 @@ class MBASE_PUBLIC Configuration
//
//////////////////////////////////////////////////////////////////////////////

class MBASE_PUBLIC XmlConfiguration : public Configuration
class MBASE_PUBLIC XmlConfiguration
{
protected:

Expand All @@ -74,48 +45,33 @@ class MBASE_PUBLIC XmlConfiguration : public Configuration

explicit XmlConfiguration( const QString &sFileName );

~XmlConfiguration() override = default;

bool Load ( void ) override; // Configuration
bool Save ( void ) override; // Configuration
bool Load();
bool Save();

int GetValue( const QString &sSetting, int Default ) override; // Configuration
QString GetValue( const QString &sSetting, const QString &Default ) override; // Configuration
bool GetBoolValue( const QString &sSetting, bool Default ) override // Configuration
int GetValue(const QString &sSetting, int Default);
QString GetValue(const QString &sSetting, const QString &Default);
bool GetBoolValue(const QString &sSetting, bool Default )
{return static_cast<bool>(GetValue(sSetting, static_cast<int>(Default))); }

void SetValue( const QString &sSetting, int value ) override; // Configuration
void SetValue( const QString &sSetting, const QString &value ) override; // Configuration
void ClearValue( const QString &sSetting ) override; // Configuration
void SetBoolValue( const QString &sSetting, bool value ) override // Configuration
void SetValue(const QString &sSetting, int value);
void SetValue(const QString &sSetting, const QString &value);
void ClearValue(const QString &sSetting );
void SetBoolValue(const QString &sSetting, bool value )
{SetValue(sSetting, static_cast<int>(value)); }
};

//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////

class MBASE_PUBLIC DBConfiguration : public Configuration
{
public:

DBConfiguration() = default;

~DBConfiguration() override = default;

bool Load ( void ) override; // Configuration
bool Save ( void ) override; // Configuration

int GetValue( const QString &sSetting, int Default ) override; // Configuration
QString GetValue( const QString &sSetting, const QString &Default ) override; // Configuration
bool GetBoolValue( const QString &sSetting, bool Default ) override // Configuration
{return static_cast<bool>(GetValue(sSetting, static_cast<int>(Default))); }
template <typename T>
typename std::enable_if_t<std::chrono::__is_duration<T>::value, T>
GetDuration(const QString &sSetting, T defaultval = T::zero())
{
return T(GetValue(sSetting, static_cast<int>(defaultval.count())));
}

void SetValue( const QString &sSetting, int value ) override; // Configuration
void SetValue( const QString &sSetting, const QString &value ) override; // Configuration
void ClearValue( const QString &sSetting ) override; // Configuration
void SetBoolValue( const QString &sSetting, bool value ) override // Configuration
{SetValue(sSetting, static_cast<int>(value)); }
template <typename T>
typename std::enable_if_t<std::chrono::__is_duration<T>::value>
SetDuration(const QString &sSetting, T value)
{
SetValue(sSetting, static_cast<int>(value.count()));
}
};

#endif // CONFIGURATION_H
17 changes: 3 additions & 14 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -53,7 +53,6 @@
#define LOC QString("MythCoreContext::%1(): ").arg(__func__)

MythCoreContext *gCoreContext = nullptr;
Configuration *MythCoreContext::g_pConfig {nullptr};

class MythCoreContextPrivate : public QObject
{
Expand Down Expand Up @@ -1806,21 +1805,11 @@ void MythCoreContext::ResetSockets(void)
dispatch(MythEvent("BACKEND_SOCKETS_CLOSED"));
}

void MythCoreContext::SetConfiguration( Configuration *pConfig )
XmlConfiguration *MythCoreContext::GetConfiguration()
{
delete g_pConfig;
g_pConfig = pConfig;
}

Configuration *MythCoreContext::GetConfiguration()
{
// If someone is asking for a config and it's nullptr, create a
// new XmlConfiguration since we don't have database info yet.

if (g_pConfig == nullptr)
g_pConfig = new XmlConfiguration( "config.xml" );
static auto config = XmlConfiguration("config.xml");

return g_pConfig;
return &config;
}

void MythCoreContext::InitPower(bool Create)
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythbase/mythcorecontext.h
Expand Up @@ -17,7 +17,7 @@
#include "mythsession.h"
#include "qtuplift.h"

class Configuration;
class XmlConfiguration;

static constexpr const char * MYTH_APPNAME_MYTHBACKEND { "mythbackend" };
static constexpr const char * MYTH_APPNAME_MYTHJOBQUEUE { "mythjobqueue" };
Expand Down Expand Up @@ -242,9 +242,7 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void ResetLanguage(void);
void ResetSockets(void);

static void SetConfiguration( Configuration *pConfig );
static Configuration* GetConfiguration();
static Configuration *g_pConfig;
static XmlConfiguration* GetConfiguration();

using PlaybackStartCb = void (QObject::*)(void);

Expand Down

0 comments on commit bda2c8b

Please sign in to comment.