From c38ee9e1b7c3fc32a4639a2ccb4fca2adb7813d3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Nov 2008 00:57:51 +0100 Subject: [PATCH] Disable audio device when silent profile is selected. Audio will be disabled when user changes profile to silent. The current profile isn't checked at application's startup yet, so if game is started when silent profile is already selected, audio will be enabled. --- SDL.kdevelop.filelist | 1 + src/main/symbian/ProfileWatcher.h | 24 ++++++++++++++++++ src/main/symbian/SDL_main.cpp | 51 +++++++++++++++++++++++++++++++++++++++ symbian/include/sdlepocapi.h | 11 ++++++++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/symbian/ProfileWatcher.h diff --git a/SDL.kdevelop.filelist b/SDL.kdevelop.filelist index 93abbc2..1530edf 100644 --- a/SDL.kdevelop.filelist +++ b/SDL.kdevelop.filelist @@ -101,6 +101,7 @@ src/loadso/dummy src/loadso/dummy/SDL_sysloadso.c src/main src/main/symbian +src/main/symbian/ProfileWatcher.h src/main/symbian/SDL_env.cpp src/main/symbian/SDL_main.cpp src/main/symbian/debug.cpp diff --git a/src/main/symbian/ProfileWatcher.h b/src/main/symbian/ProfileWatcher.h new file mode 100644 index 0000000..de6e73e --- /dev/null +++ b/src/main/symbian/ProfileWatcher.h @@ -0,0 +1,24 @@ +#ifndef PROFILE_WATCHER_H +#define PROFILE_WATCHER_H + +#include +#include +#include + +#include "sdlepocapi.h" + +class ProfileWatcher : public CActive +{ + public: + ProfileWatcher(MProfileWatcher& observer); + ~ProfileWatcher(); + + private: + void RunL(); + void DoCancel(); + + CRepository* m_repository; + MProfileWatcher& m_observer; +}; + +#endif diff --git a/src/main/symbian/SDL_main.cpp b/src/main/symbian/SDL_main.cpp index 80d34cc..094198c 100644 --- a/src/main/symbian/SDL_main.cpp +++ b/src/main/symbian/SDL_main.cpp @@ -17,6 +17,7 @@ extern "C" { #include #include #include +#include "ProfileWatcher.h" CSDL* g_SDL = NULL; @@ -75,6 +76,40 @@ TSdlCleanupItem::TSdlCleanupItem(TSdlCleanupOperation aOperation, void* aItem) : iOperation(aOperation), iItem(aItem), iThread(RThread().Id()) {} + +ProfileWatcher::ProfileWatcher(MProfileWatcher& observer) + : CActive(EPriorityLow) + , m_repository(CRepository::NewL(KCRUidProfileEngine)) + , m_observer(observer) +{ + CActiveScheduler::Add(this); + m_repository->NotifyRequest(KProEngActiveProfile, iStatus); + SetActive(); +} + +ProfileWatcher::~ProfileWatcher() +{ + Cancel(); + delete m_repository; +} + +void ProfileWatcher::DoCancel() +{ + m_repository->NotifyCancel(KProEngActiveProfile); +} + +void ProfileWatcher::RunL() +{ + int value; + if(m_repository->Get(KProEngActiveProfile, value) == KErrNone) + { + m_observer.ProfileChanged(value); + } + m_repository->NotifyRequest(KProEngActiveProfile, iStatus); + SetActive(); +} + + class CSdlAppServ : public CActive { public: @@ -244,6 +279,7 @@ static int DoMain() CSDL::CSDL() : m_orientationWait( false ) , m_soundPauseReason( SPR_NONE ) + , m_profileWatcher( new ProfileWatcher(*this) ) { __ASSERT_ALWAYS(gEpocEnv == NULL, PANIC(KErrAlreadyExists)); gEpocEnv = new EpocSdlEnvData; @@ -258,6 +294,8 @@ CSDL::CSDL() CSDL::~CSDL() { + delete m_profileWatcher; + g_SDL = NULL; delete m_eventQueue; @@ -375,3 +413,16 @@ void CSDL::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApi break; } } + +void CSDL::ProfileChanged(int profile) +{ + // Check for silent profile + if(profile == 1) + { + m_soundPauseReason |= SPR_SILENTPROFILE; + } + else + { + m_soundPauseReason &= ~SPR_SILENTPROFILE; + } +} diff --git a/symbian/include/sdlepocapi.h b/symbian/include/sdlepocapi.h index 487a2dd..4d12266 100644 --- a/symbian/include/sdlepocapi.h +++ b/symbian/include/sdlepocapi.h @@ -19,7 +19,14 @@ extern "C" int SDL_main (int argc, char* argv[]); } -class CSDL : public MRemConCoreApiTargetObserver +class ProfileWatcher; +class MProfileWatcher +{ + public: + virtual void ProfileChanged(int profile) = 0; +}; + +class CSDL : public MRemConCoreApiTargetObserver, public MProfileWatcher { public: enum SoundPauseReason @@ -45,12 +52,14 @@ class CSDL : public MRemConCoreApiTargetObserver private: void MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct); + void ProfileChanged(int profile); CEventQueue* m_eventQueue; bool m_orientationWait; TSize m_size; TDisplayMode m_mode; int m_soundPauseReason; + ProfileWatcher* m_profileWatcher; }; extern CSDL* g_SDL; -- 2.11.4.GIT