Skip to content

Commit

Permalink
Short answer:
Browse files Browse the repository at this point in the history
If your patch breaks, ESC : %s/gContext/gCoreContext/g ENTER in 99% of cases.
If that doesn't fix it, it might be s/gContext->GetMainWindow/GetMythMainWindow/g
And make clean since the API version changed.

Long answer:

This commit is a MythContext reorganization patch.  The main goal is to get
the non-GUI portions of MythContext deeper into the library dependency
tree.  libmyth depends on libmythui which depends on libmythdb.  This means
that neither libmythdb or libmythui can use anything in the current
MythContext.  This patch addresses this issue by moving most of MythContext
into libmythdb as MythCoreContext.  This will for instance allow libmythdb
and libmythui code to use the existing master backend connection rather than
having to open a new connection to talk to the master.

To accomplish the above, this patch...

- moves the non-GUI portions of MythContext to a new MythCoreContext class
  located in libs/libmythdb/mythcorecontext.(cpp|h).  Also changes
  #include mythcontext.h to #include mythcorecontext.h where applicable.

- adds a new gCoreContext global pointer to the MythCoreContext instance.
  gCoreContext is now used in most places that gContext was used previously
  since most of these methods are now in MythCoreContext.  The global
  gCoreContext creation/deletion is handled by the global MythContext.
  MythContext does not inherit from MythCoreContext because we need the
  routines in MythCoreContext to be accessible via the gCoreContext pointer
  inside libmythdb and libmythui.

- moves mythsystem.(cpp|h) from libmythui to libmythdb

- moves the following methods out of MythContext:

  MythContext::sendPlaybackStart() -> sendPlaybackStart() in libmyth/util.cpp
  MythContext::sendPlaybackEnd()   -> sendPlaybackEnd() in libmyth/util.cpp

- gets rid of the following methods:

  MythContext::GetMainWindow()     (use mythmainwindow.h's GetMythMainWindow())
  MythContext::SetMainWindow()     (not needed without ::GetMainWindow())
  MythContext::TranslateKeyPress() (already commented as deprecated,
                                    use GetMythMainWindow()->TranslateKeyPress())

- creates the following method(s):

  MythContext::SetDisableEventPopup(bool) (used by frontend's exit prompt
                                           code to disable popups since
                                           MythContext::SetMainWindow() does
                                           not exist anymore)

- performs some minor header cleanup, converting some files from #including
  mythcontext.h to instead include mythverbose.h since all they needed was
  access to the VERBOSE macro.


You'll need to do a make clean on this one.  The binary API is updated and
libmythdb, libmythui, and libmyth are all changed more than a tiny bit.
Most of the rest of the changes are s/gContext/gCoreContext/g with a little
s/mythcontext.h/mythcorecontext.h/ thrown in for #include changes.

=============================================================================



git-svn-id: http://svn.mythtv.org/svn/trunk@24623 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
cpinkham committed May 13, 2010
1 parent 807c9ca commit f4e86cd
Show file tree
Hide file tree
Showing 222 changed files with 2,803 additions and 2,642 deletions.
10 changes: 5 additions & 5 deletions mythtv/libs/libmyth/audiooutputalsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythcorecontext.h"
#include "audiooutputalsa.h"

#define LOC QString("ALSA: ")
Expand Down Expand Up @@ -753,17 +753,17 @@ void AudioOutputALSA::OpenMixer(bool setstartingvolume)
{
int volume;

mixer_control = gContext->GetSetting("MixerControl", "PCM");
mixer_control = gCoreContext->GetSetting("MixerControl", "PCM");

SetupMixer();

if (mixer_handle != NULL && setstartingvolume)
{
volume = gContext->GetNumSetting("MasterMixerVolume", 80);
volume = gCoreContext->GetNumSetting("MasterMixerVolume", 80);
SetCurrentVolume("Master", 0, volume);
SetCurrentVolume("Master", 1, volume);

volume = gContext->GetNumSetting("PCMMixerVolume", 80);
volume = gCoreContext->GetNumSetting("PCMMixerVolume", 80);
SetCurrentVolume("PCM", 0, volume);
SetCurrentVolume("PCM", 1, volume);
}
Expand All @@ -780,7 +780,7 @@ void AudioOutputALSA::SetupMixer(void)
{
int err;

QString alsadevice = gContext->GetSetting("MixerDevice", "default");
QString alsadevice = gCoreContext->GetSetting("MixerDevice", "default");
QString device = alsadevice.remove(QString("ALSA:"));

if (mixer_handle != NULL)
Expand Down
30 changes: 15 additions & 15 deletions mythtv/libs/libmyth/audiooutputbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,32 @@ AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
memset(tmp_buff, 0, sizeof(short) * kAudioTempBufSize);
memset(&audiotime_updated, 0, sizeof(audiotime_updated));
memset(audiobuffer, 0, sizeof(char) * kAudioRingBufferSize);
orig_config_channels = gContext->GetNumSetting("MaxChannels", 2);
src_quality = gContext->GetNumSetting("AudioUpmixType", 2);
orig_config_channels = gCoreContext->GetNumSetting("MaxChannels", 2);
src_quality = gCoreContext->GetNumSetting("AudioUpmixType", 2);
//Set default upsampling quality to medium if using stereo
if (orig_config_channels == 2)
src_quality = 1;

// Handle override of SRC quality settings
if (gContext->GetNumSetting("AdvancedAudioSettings", false) &&
gContext->GetNumSetting("SRCQualityOverride", false))
if (gCoreContext->GetNumSetting("AdvancedAudioSettings", false) &&
gCoreContext->GetNumSetting("SRCQualityOverride", false))
{
src_quality = gContext->GetNumSetting("SRCQuality", 1);
src_quality = gCoreContext->GetNumSetting("SRCQuality", 1);
// Extra test to keep backward compatibility with earlier SRC code setting
if (src_quality > 2)
src_quality = 2;
VERBOSE(VB_AUDIO, LOC + QString("Force SRC quality (%1)").arg(src_quality));
}

if (!settings.upmixer)
configured_audio_channels = gContext->GetNumSetting("AudioDefaultUpmix", false) ? orig_config_channels : 2;
configured_audio_channels = gCoreContext->GetNumSetting("AudioDefaultUpmix", false) ? orig_config_channels : 2;
else
if (settings.upmixer == 1)
configured_audio_channels = 2;
else
configured_audio_channels = 6;

allow_ac3_passthru = (orig_config_channels > 2) ? gContext->GetNumSetting("AC3PassThru", false) : false;
allow_ac3_passthru = (orig_config_channels > 2) ? gCoreContext->GetNumSetting("AC3PassThru", false) : false;

// You need to call Reconfigure from your concrete class.
// Reconfigure(laudio_bits, laudio_channels,
Expand Down Expand Up @@ -278,7 +278,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
killaudio = false;
pauseaudio = false;
was_paused = true;
internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
internal_vol = gCoreContext->GetNumSetting("MythControlsVolume", 0);

numlowbuffer = 0;

Expand Down Expand Up @@ -378,9 +378,9 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
// Only used for software volume
if (set_initial_vol && internal_vol)
{
QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
QString controlLabel = gCoreContext->GetSetting("MixerControl", "PCM");
controlLabel += "MixerVolume";
volume = gContext->GetNumSetting(controlLabel, 80);
volume = gCoreContext->GetNumSetting(controlLabel, 80);
}

SyncVolume();
Expand All @@ -392,9 +392,9 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
if (audio_buffer_unused < 0)
audio_buffer_unused = 0;

if (!gContext->GetNumSetting("AdvancedAudioSettings", false))
if (!gCoreContext->GetNumSetting("AdvancedAudioSettings", false))
audio_buffer_unused = 0;
else if (!gContext->GetNumSetting("AggressiveSoundcardBuffer", false))
else if (!gCoreContext->GetNumSetting("AggressiveSoundcardBuffer", false))
audio_buffer_unused = 0;

audbuf_timecode = 0;
Expand All @@ -410,7 +410,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
VERBOSE(VB_AUDIO, LOC + QString("create upmixer"));
if (configured_audio_channels == 6)
{
surround_mode = gContext->GetNumSetting("AudioUpmixType", 2);
surround_mode = gCoreContext->GetNumSetting("AudioUpmixType", 2);
}

upmixer = new FreeSurround(
Expand Down Expand Up @@ -684,9 +684,9 @@ void AudioOutputBase::SetSWVolume(int new_volume, bool save)
volume = new_volume;
if (save)
{
QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
QString controlLabel = gCoreContext->GetSetting("MixerControl", "PCM");
controlLabel += "MixerVolume";
gContext->SaveSetting(controlLabel, volume);
gCoreContext->SaveSetting(controlLabel, volume);
}
}

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/audiooutputca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythcorecontext.h"
#include "audiooutputca.h"
#include "config.h"
#include "SoundTouch.h"
Expand Down Expand Up @@ -246,9 +246,9 @@ bool AudioOutputCA::OpenDevice()

if (internal_vol && set_initial_vol)
{
QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
QString controlLabel = gCoreContext->GetSetting("MixerControl", "PCM");
controlLabel += "MixerVolume";
SetCurrentVolume(gContext->GetNumSetting(controlLabel, 80));
SetCurrentVolume(gCoreContext->GetNumSetting(controlLabel, 80));
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audiooutputdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythverbose.h"
#include "audiooutputdx.h"

#include <windows.h>
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audiooutputjack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythcorecontext.h"
#include "audiooutputjack.h"
#include "util.h"

Expand Down Expand Up @@ -213,7 +213,7 @@ void AudioOutputJACK::VolumeInit(void)
{
int volume = 100;
if (set_initial_vol)
volume = gContext->GetNumSetting("MasterMixerVolume", 80);
volume = gCoreContext->GetNumSetting("MasterMixerVolume", 80);

JACK_SetAllVolume(audioid, volume);
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audiooutputnull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythverbose.h"
#include "audiooutputnull.h"

AudioOutputNULL::AudioOutputNULL(const AudioSettings &settings) :
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmyth/audiooutputoss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace std;
#define LOC_WARN QString("AudioOuputOSS, Warning: ")
#define LOC_ERR QString("AudioOuputOSS, Error: ")

#include "mythcontext.h"
#include "mythcorecontext.h"
#include "audiooutputoss.h"
#include "util.h"

Expand Down Expand Up @@ -316,14 +316,14 @@ void AudioOutputOSS::VolumeInit()
mixerfd = -1;
int volume = 0;

QString device = gContext->GetSetting("MixerDevice", "/dev/mixer");
QString device = gCoreContext->GetSetting("MixerDevice", "/dev/mixer");
if (device.toLower() == "software")
return;

QByteArray dev = device.toAscii();
mixerfd = open(dev.constData(), O_RDONLY);

QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
QString controlLabel = gCoreContext->GetSetting("MixerControl", "PCM");

if (controlLabel == "Master")
{
Expand All @@ -344,7 +344,7 @@ void AudioOutputOSS::VolumeInit()
if (set_initial_vol)
{
int tmpVol;
volume = gContext->GetNumSetting("MasterMixerVolume", 80);
volume = gCoreContext->GetNumSetting("MasterMixerVolume", 80);
tmpVol = (volume << 8) + volume;
int ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmpVol);
if (ret < 0)
Expand All @@ -353,7 +353,7 @@ void AudioOutputOSS::VolumeInit()
QString("Error Setting initial Master Volume") + ENO);
}

volume = gContext->GetNumSetting("PCMMixerVolume", 80);
volume = gCoreContext->GetNumSetting("PCMMixerVolume", 80);
tmpVol = (volume << 8) + volume;
ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_PCM), &tmpVol);
if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audiooutputpulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ bool AudioOutputPulseAudio::ConnectPlaybackStream(void)
(char*)"under");
if (set_initial_vol)
{
int volume = gContext->GetNumSetting("MasterMixerVolume", 80);
int volume = gCoreContext->GetNumSetting("MasterMixerVolume", 80);
pa_cvolume_set(&volume_control, audio_channels,
(float)volume * (float)PA_VOLUME_NORM / 100.0f);
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audiooutputwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using namespace std;

#include "mythcontext.h"
#include "mythverbose.h"
#include "audiooutputwin.h"

#include <windows.h>
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/audiopulseutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "util.h" // for IsPulseAudioRunning()
#include "exitcodes.h"
#include "mythverbose.h"
#include "mythcontext.h"
#include "mythcorecontext.h"

#ifdef USING_PULSE

Expand Down Expand Up @@ -342,7 +342,7 @@ int pulseaudio_handle_startup(void)
VERBOSE(VB_IMPORTANT, "WARNING: You have told MythTV to ignore it.");
VERBOSE(VB_IMPORTANT, "WARNING: ");
}
else if (gContext->GetSetting("AudioOutputDevice")
else if (gCoreContext->GetSetting("AudioOutputDevice")
.toLower().contains("pulseaudio"))
{
// Don't disable PulseAudio if we're using it explicitly
Expand Down
34 changes: 17 additions & 17 deletions mythtv/libs/libmyth/dbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QSqlError>

#include "dbutil.h"
#include "mythcontext.h"
#include "mythcorecontext.h"
#include "storagegroup.h"
#include "util.h"
#include "mythdb.h"
Expand Down Expand Up @@ -92,8 +92,8 @@ bool DBUtil::IsNewDatabase(void)
*/
bool DBUtil::IsBackupInProgress(void)
{
QString backupStartTimeStr = gContext->GetSetting("BackupDBLastRunStart");
QString backupEndTimeStr = gContext->GetSetting("BackupDBLastRunEnd");
QString backupStartTimeStr = gCoreContext->GetSetting("BackupDBLastRunStart");
QString backupEndTimeStr = gCoreContext->GetSetting("BackupDBLastRunEnd");

if (backupStartTimeStr.isEmpty())
{
Expand Down Expand Up @@ -195,7 +195,7 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
return kDB_Backup_Disabled;
#endif

if (gContext->GetNumSetting("DisableAutomaticBackup", 0))
if (gCoreContext->GetNumSetting("DisableAutomaticBackup", 0))
{
VERBOSE(VB_IMPORTANT, "Database backups disabled. Skipping backup.");
return kDB_Backup_Disabled;
Expand All @@ -208,7 +208,7 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
}

QString backupScript = GetShareDir() + "mythconverg_backup.pl";
backupScript = gContext->GetSetting("DatabaseBackupScript", backupScript);
backupScript = gCoreContext->GetSetting("DatabaseBackupScript", backupScript);

if (!QFile::exists(backupScript))
{
Expand All @@ -220,7 +220,7 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
bool result = false;
MSqlQuery query(MSqlQuery::InitCon());

gContext->SaveSettingOnHost("BackupDBLastRunStart",
gCoreContext->SaveSettingOnHost("BackupDBLastRunStart",
QDateTime::currentDateTime()
.toString("yyyy-MM-dd hh:mm:ss"), NULL);

Expand All @@ -235,7 +235,7 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
if (!result)
result = DoBackup(filename);

gContext->SaveSettingOnHost("BackupDBLastRunEnd",
gCoreContext->SaveSettingOnHost("BackupDBLastRunEnd",
QDateTime::currentDateTime()
.toString("yyyy-MM-dd hh:mm:ss"), NULL);

Expand Down Expand Up @@ -335,7 +335,7 @@ QString DBUtil::CreateBackupFilename(QString prefix, QString extension)
QString DBUtil::GetBackupDirectory()
{
QString directory;
StorageGroup sgroup("DB Backups", gContext->GetHostName());
StorageGroup sgroup("DB Backups", gCoreContext->GetHostName());
QStringList dirList = sgroup.GetDirList();
if (dirList.size())
{
Expand Down Expand Up @@ -373,8 +373,8 @@ bool DBUtil::CreateTemporaryDBConf(
bool ok = true;
filename = createTempFile("/tmp/mythtv_db_backup_conf_XXXXXX");
const QByteArray tmpfile = filename.toLocal8Bit();
const DatabaseParams dbParams = gContext->GetDatabaseParams();
const QString dbSchemaVer = gContext->GetSetting("DBSchemaVer");
const DatabaseParams dbParams = gCoreContext->GetDatabaseParams();
const QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");

FILE *fp = fopen(tmpfile.constData(), "w");
if (!fp)
Expand Down Expand Up @@ -411,12 +411,12 @@ bool DBUtil::CreateTemporaryDBConf(
*/
bool DBUtil::DoBackup(const QString &backupScript, QString &filename)
{
DatabaseParams dbParams = gContext->GetDatabaseParams();
QString dbSchemaVer = gContext->GetSetting("DBSchemaVer");
DatabaseParams dbParams = gCoreContext->GetDatabaseParams();
QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
QString backupDirectory = GetBackupDirectory();
QString backupFilename = CreateBackupFilename(dbParams.dbName + "-" +
dbSchemaVer, ".sql");
QString scriptArgs = gContext->GetSetting("BackupDBScriptArgs");
QString scriptArgs = gCoreContext->GetSetting("BackupDBScriptArgs");
if (!scriptArgs.isEmpty())
scriptArgs.prepend(" ");

Expand Down Expand Up @@ -502,8 +502,8 @@ bool DBUtil::DoBackup(const QString &backupScript, QString &filename)
*/
bool DBUtil::DoBackup(QString &filename)
{
DatabaseParams dbParams = gContext->GetDatabaseParams();
QString dbSchemaVer = gContext->GetSetting("DBSchemaVer");
DatabaseParams dbParams = gCoreContext->GetDatabaseParams();
QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
QString backupDirectory = GetBackupDirectory();

QString command;
Expand Down Expand Up @@ -596,7 +596,7 @@ bool DBUtil::QueryDBMSVersion(void)
// Allow users to override the string provided by the database server in
// case the value was changed to an unrecognizable string by whomever
// compiled the MySQL server
QString dbmsVersion = gContext->GetSetting("DBMSVersionOverride");
QString dbmsVersion = gCoreContext->GetSetting("DBMSVersionOverride");

if (dbmsVersion.isEmpty())
{
Expand Down Expand Up @@ -654,7 +654,7 @@ bool DBUtil::ParseDBMSVersion()
*/
int DBUtil::CountClients(void)
{
DatabaseParams DB = gContext->GetDatabaseParams();
DatabaseParams DB = gCoreContext->GetDatabaseParams();
int count = 0;

// QSqlQuery doesn't know how to parse the results of "SHOW PROCESSLIST",
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmyth/dialogbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using namespace std;

#include "dialogbox.h"
#include "mythcontext.h"
#include "mythwidgets.h"

#ifdef USING_MINGW
Expand Down

0 comments on commit f4e86cd

Please sign in to comment.