Permalink
Browse files

Merge pull request #4725 from Montellese/announcement_refactor

refactor of CAnnouncementManager
  • Loading branch information...
2 parents d67a29d + 7ff78a4 commit fa8ea60e41dc573d83da4ba3954b1ae9f20d5748 @Montellese Montellese committed May 16, 2014
View
@@ -3517,7 +3517,7 @@ void CApplication::Stop(int exitCode)
try
{
CVariant vExitCode(exitCode);
- CAnnouncementManager::Announce(System, "xbmc", "OnQuit", vExitCode);
+ CAnnouncementManager::Get().Announce(System, "xbmc", "OnQuit", vExitCode);
SaveFileState(true);
@@ -3558,6 +3558,8 @@ void CApplication::Stop(int exitCode)
CLog::Log(LOGNOTICE, "stop player");
m_pPlayer->ClosePlayer();
+ CAnnouncementManager::Get().Deinitialize();
+
StopPVRManager();
StopServices();
//Sleep(5000);
@@ -4238,7 +4240,7 @@ void CApplication::OnPlayBackEnded()
CVariant data(CVariant::VariantTypeObject);
data["end"] = true;
- CAnnouncementManager::Announce(Player, "xbmc", "OnStop", m_itemCurrentFile, data);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnStop", m_itemCurrentFile, data);
CGUIMessage msg(GUI_MSG_PLAYBACK_ENDED, 0, 0);
g_windowManager.SendThreadMessage(msg);
@@ -4294,7 +4296,7 @@ void CApplication::OnPlayBackStopped()
CVariant data(CVariant::VariantTypeObject);
data["end"] = false;
- CAnnouncementManager::Announce(Player, "xbmc", "OnStop", m_itemCurrentFile, data);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnStop", m_itemCurrentFile, data);
CGUIMessage msg( GUI_MSG_PLAYBACK_STOPPED, 0, 0 );
g_windowManager.SendThreadMessage(msg);
@@ -4309,7 +4311,7 @@ void CApplication::OnPlayBackPaused()
CVariant param;
param["player"]["speed"] = 0;
param["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
- CAnnouncementManager::Announce(Player, "xbmc", "OnPause", m_itemCurrentFile, param);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnPause", m_itemCurrentFile, param);
}
void CApplication::OnPlayBackResumed()
@@ -4321,7 +4323,7 @@ void CApplication::OnPlayBackResumed()
CVariant param;
param["player"]["speed"] = 1;
param["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
- CAnnouncementManager::Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
}
void CApplication::OnPlayBackSpeedChanged(int iSpeed)
@@ -4333,7 +4335,7 @@ void CApplication::OnPlayBackSpeedChanged(int iSpeed)
CVariant param;
param["player"]["speed"] = iSpeed;
param["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
- CAnnouncementManager::Announce(Player, "xbmc", "OnSpeedChanged", m_itemCurrentFile, param);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnSpeedChanged", m_itemCurrentFile, param);
}
void CApplication::OnPlayBackSeek(int iTime, int seekOffset)
@@ -4347,7 +4349,7 @@ void CApplication::OnPlayBackSeek(int iTime, int seekOffset)
CJSONUtils::MillisecondsToTimeObject(seekOffset, param["player"]["seekoffset"]);;
param["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
param["player"]["speed"] = m_pPlayer->GetPlaySpeed();
- CAnnouncementManager::Announce(Player, "xbmc", "OnSeek", m_itemCurrentFile, param);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnSeek", m_itemCurrentFile, param);
g_infoManager.SetDisplayAfterSeek(2500, seekOffset/1000);
}
@@ -4565,7 +4567,7 @@ bool CApplication::WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed /* = false
{
// allow listeners to ignore the deactivation if it preceeds a powerdown/suspend etc
CVariant data(bPowerOffKeyPressed);
- CAnnouncementManager::Announce(GUI, "xbmc", "OnScreensaverDeactivated", data);
+ CAnnouncementManager::Get().Announce(GUI, "xbmc", "OnScreensaverDeactivated", data);
}
return result;
@@ -4695,7 +4697,7 @@ void CApplication::ActivateScreenSaver(bool forceType /*= false */)
if (!CAddonMgr::Get().GetAddon(CSettings::Get().GetString("screensaver.mode"), m_screenSaver))
m_screenSaver.reset(new CScreenSaver(""));
- CAnnouncementManager::Announce(GUI, "xbmc", "OnScreensaverActivated");
+ CAnnouncementManager::Get().Announce(GUI, "xbmc", "OnScreensaverActivated");
// disable screensaver lock from the login screen
m_iScreenSaveLock = g_windowManager.GetActiveWindow() == WINDOW_LOGIN_SCREEN ? 1 : 0;
@@ -4805,7 +4807,7 @@ bool CApplication::OnMessage(CGUIMessage& message)
CVariant param;
param["player"]["speed"] = 1;
param["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
- CAnnouncementManager::Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
+ CAnnouncementManager::Get().Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
if (m_pPlayer->IsPlayingAudio())
{
@@ -5380,7 +5382,7 @@ void CApplication::VolumeChanged() const
CVariant data(CVariant::VariantTypeObject);
data["volume"] = GetVolume();
data["muted"] = m_muted;
- CAnnouncementManager::Announce(Application, "xbmc", "OnVolumeChanged", data);
+ CAnnouncementManager::Get().Announce(Application, "xbmc", "OnVolumeChanged", data);
// if player has volume control, set it.
if (m_pPlayer->ControlsVolume())
@@ -707,6 +707,6 @@ void CPartyModeManager::Announce()
data["player"]["playerid"] = g_playlistPlayer.GetCurrentPlaylist();
data["property"]["partymode"] = m_bEnabled;
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Player, "xbmc", "OnPropertyChanged", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Player, "xbmc", "OnPropertyChanged", data);
}
}
@@ -716,5 +716,5 @@ void CPlayListPlayer::AnnouncePropertyChanged(int iPlaylist, const std::string &
CVariant data;
data["player"]["playerid"] = iPlaylist;
data["property"][strProperty] = value;
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Player, "xbmc", "OnPropertyChanged", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Player, "xbmc", "OnPropertyChanged", data);
}
@@ -245,7 +245,7 @@ ADDON_STATUS CAddonDll<TheDll, TheStruct, TheProps>::Create()
if (status == ADDON_STATUS_OK)
{
m_initialized = true;
- ANNOUNCEMENT::CAnnouncementManager::AddAnnouncer(this);
+ ANNOUNCEMENT::CAnnouncementManager::Get().AddAnnouncer(this);
}
else if ((status == ADDON_STATUS_NEED_SETTINGS) || (status == ADDON_STATUS_NEED_SAVEDSETTINGS))
{
@@ -311,7 +311,7 @@ void CAddonDll<TheDll, TheStruct, TheProps>::Stop()
template<class TheDll, typename TheStruct, typename TheProps>
void CAddonDll<TheDll, TheStruct, TheProps>::Destroy()
{
- ANNOUNCEMENT::CAnnouncementManager::RemoveAnnouncer(this);
+ ANNOUNCEMENT::CAnnouncementManager::Get().RemoveAnnouncer(this);
/* Unload library file */
try
@@ -109,7 +109,7 @@ void CGUIDialogKeyboardGeneric::OnInitWindow()
data["title"] = m_strHeading;
data["type"] = !m_hiddenInput ? "keyboard" : "password";
data["value"] = GetText();
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
}
bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
@@ -606,7 +606,7 @@ void CGUIDialogKeyboardGeneric::OnDeinitWindow(int nextWindowID)
m_strHeading = "";
g_Windowing.EnableTextInput(false);
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
}
void CGUIDialogKeyboardGeneric::MoveCursor(int iAmount)
@@ -91,15 +91,15 @@ void CGUIDialogNumeric::OnInitWindow()
data["title"] = control->GetDescription();
data["value"] = GetOutput();
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
}
void CGUIDialogNumeric::OnDeinitWindow(int nextWindowID)
{
// call base class
CGUIDialog::OnDeinitWindow(nextWindowID);
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
}
bool CGUIDialogNumeric::OnAction(const CAction &action)
@@ -36,8 +36,25 @@
using namespace std;
using namespace ANNOUNCEMENT;
-#define m_announcers XBMC_GLOBAL_USE(ANNOUNCEMENT::CAnnouncementManager::Globals).m_announcers
-#define m_critSection XBMC_GLOBAL_USE(ANNOUNCEMENT::CAnnouncementManager::Globals).m_critSection
+CAnnouncementManager::CAnnouncementManager()
+{ }
+
+CAnnouncementManager::~CAnnouncementManager()
+{
+ Deinitialize();
+}
+
+CAnnouncementManager& CAnnouncementManager::Get()
+{
+ static CAnnouncementManager s_instance;
+ return s_instance;
+}
+
+void CAnnouncementManager::Deinitialize()
+{
+ CSingleLock lock (m_critSection);
+ m_announcers.clear();
+}
void CAnnouncementManager::AddAnnouncer(IAnnouncer *listener)
{
@@ -1,6 +1,6 @@
#pragma once
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -18,34 +18,37 @@
* <http://www.gnu.org/licenses/>.
*
*/
+#include <vector>
#include "IAnnouncer.h"
#include "FileItem.h"
#include "threads/CriticalSection.h"
#include "utils/GlobalsHandling.h"
-#include <vector>
namespace ANNOUNCEMENT
{
class CAnnouncementManager
{
public:
+ virtual ~CAnnouncementManager();
+
+ static CAnnouncementManager& Get();
- class Globals
- {
- public:
- CCriticalSection m_critSection;
- std::vector<IAnnouncer *> m_announcers;
- };
+ void Deinitialize();
- static void AddAnnouncer(IAnnouncer *listener);
- static void RemoveAnnouncer(IAnnouncer *listener);
- static void Announce(AnnouncementFlag flag, const char *sender, const char *message);
- static void Announce(AnnouncementFlag flag, const char *sender, const char *message, CVariant &data);
- static void Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item);
- static void Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item, CVariant &data);
+ void AddAnnouncer(IAnnouncer *listener);
+ void RemoveAnnouncer(IAnnouncer *listener);
+
+ void Announce(AnnouncementFlag flag, const char *sender, const char *message);
+ void Announce(AnnouncementFlag flag, const char *sender, const char *message, CVariant &data);
+ void Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item);
+ void Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item, CVariant &data);
private:
+ CAnnouncementManager();
+ CAnnouncementManager(const CAnnouncementManager&);
+ CAnnouncementManager const& operator=(CAnnouncementManager const&);
+
+ CCriticalSection m_critSection;
+ std::vector<IAnnouncer *> m_announcers;
};
}
-
-XBMC_GLOBAL_REF(ANNOUNCEMENT::CAnnouncementManager::Globals,g_announcementManager_globals);
@@ -609,7 +609,7 @@ int CBuiltins::Execute(const CStdString& execString)
if (params.size() > 2)
data = CJSONVariantParser::Parse((const unsigned char *)params[2].c_str(), params[2].size());
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Other, params[0], params[1], data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::Other, params[0], params[1], data);
}
else
CLog::Log(LOGERROR, "XBMC.NotifyAll needs two parameters");
@@ -215,12 +215,12 @@ JSONRPC_STATUS CJSONRPC::SetConfiguration(const CStdString &method, ITransportLa
JSONRPC_STATUS CJSONRPC::NotifyAll(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result)
{
if (parameterObject["data"].isNull())
- CAnnouncementManager::Announce(Other, parameterObject["sender"].asString().c_str(),
+ CAnnouncementManager::Get().Announce(Other, parameterObject["sender"].asString().c_str(),
parameterObject["message"].asString().c_str());
else
{
CVariant data = parameterObject["data"];
- CAnnouncementManager::Announce(Other, parameterObject["sender"].asString().c_str(),
+ CAnnouncementManager::Get().Announce(Other, parameterObject["sender"].asString().c_str(),
parameterObject["message"].asString().c_str(), data);
}
@@ -67,13 +67,13 @@ XBPython::XBPython()
m_vecPlayerCallbackList.clear();
m_vecMonitorCallbackList.clear();
- CAnnouncementManager::AddAnnouncer(this);
+ CAnnouncementManager::Get().AddAnnouncer(this);
}
XBPython::~XBPython()
{
XBMC_TRACE;
- CAnnouncementManager::RemoveAnnouncer(this);
+ CAnnouncementManager::Get().RemoveAnnouncer(this);
}
#define LOCK_AND_COPY(type, dest, src) \
@@ -566,7 +566,7 @@ void XBPython::Uninitialize()
// don't handle any more announcements as most scripts are probably already
// stopped and executing a callback on one of their already destroyed classes
// would lead to a crash
- CAnnouncementManager::RemoveAnnouncer(this);
+ CAnnouncementManager::Get().RemoveAnnouncer(this);
LOCK_AND_COPY(std::vector<PyElem>,tmpvec,m_vecPyList);
m_vecPyList.clear();
@@ -291,12 +291,12 @@ void CDirectoryProvider::RegisterListProvider(bool hasLibraryContent)
if (hasLibraryContent && !m_isAnnounced)
{
m_isAnnounced = true;
- CAnnouncementManager::AddAnnouncer(this);
+ CAnnouncementManager::Get().AddAnnouncer(this);
}
else if (!hasLibraryContent && m_isAnnounced)
{
m_isAnnounced = false;
- CAnnouncementManager::RemoveAnnouncer(this);
+ CAnnouncementManager::Get().RemoveAnnouncer(this);
}
}
@@ -87,7 +87,7 @@ static void AnnounceRemove(const std::string& content, int id)
data["id"] = id;
if (g_application.IsMusicScanning())
data["transaction"] = true;
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnRemove", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnRemove", data);
}
static void AnnounceUpdate(const std::string& content, int id)
@@ -97,7 +97,7 @@ static void AnnounceUpdate(const std::string& content, int id)
data["id"] = id;
if (g_application.IsMusicScanning())
data["transaction"] = true;
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnUpdate", data);
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnUpdate", data);
}
CMusicDatabase::CMusicDatabase(void)
@@ -2522,7 +2522,7 @@ int CMusicDatabase::Cleanup(CGUIDialogProgress *pDlgProgress)
int ret = ERROR_OK;
unsigned int time = XbmcThreads::SystemClockMillis();
CLog::Log(LOGNOTICE, "%s: Starting musicdatabase cleanup ..", __FUNCTION__);
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanStarted");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanStarted");
// first cleanup any songs with invalid paths
if (pDlgProgress)
@@ -2608,7 +2608,7 @@ int CMusicDatabase::Cleanup(CGUIDialogProgress *pDlgProgress)
}
time = XbmcThreads::SystemClockMillis() - time;
CLog::Log(LOGNOTICE, "%s: Cleaning musicdatabase done. Operation took %s", __FUNCTION__, StringUtils::SecondsToTimeString(time / 1000).c_str());
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanFinished");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanFinished");
if (!Compress(false))
{
@@ -2618,7 +2618,7 @@ int CMusicDatabase::Cleanup(CGUIDialogProgress *pDlgProgress)
error:
RollbackTransaction();
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanFinished");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnCleanFinished");
return ret;
}
@@ -79,7 +79,7 @@ CMusicInfoScanner::~CMusicInfoScanner()
void CMusicInfoScanner::Process()
{
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnScanStarted");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnScanStarted");
try
{
unsigned int tick = XbmcThreads::SystemClockMillis();
@@ -236,7 +236,7 @@ void CMusicInfoScanner::Process()
CLog::Log(LOGDEBUG, "%s - Finished scan", __FUNCTION__);
m_bRunning = false;
- ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnScanFinished");
+ ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnScanFinished");
// we need to clear the musicdb cache and update any active lists
CUtil::DeleteMusicDatabaseDirectoryCache();
Oops, something went wrong.

0 comments on commit fa8ea60

Please sign in to comment.