os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundServer.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundServer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,215 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32math.h>
1.20 +#include "MmfDevSoundServer.h"
1.21 +#include "MmfDevSoundServerStart.h"
1.22 +#include "MmfDevSoundSession.h"
1.23 +
1.24 +const TInt KDevSoundShutDownDelay = 0; //0 sec
1.25 +_LIT(KMMFDevSoundServerName, "MMFDevSoundServer-");
1.26 +
1.27 +
1.28 +
1.29 +EXPORT_C CMMFDevSoundServer* CMMFDevSoundServer::NewL(CMMFAudioServer* aAudioServer, TProcessId& aClientPID)
1.30 + {
1.31 + CMMFDevSoundServer* s = new(ELeave) CMMFDevSoundServer(aAudioServer, aClientPID);
1.32 + CleanupStack::PushL(s);
1.33 + s->ConstructL();
1.34 + CleanupStack::Pop();
1.35 + return s;
1.36 + }
1.37 +
1.38 +CMMFDevSoundServer::CMMFDevSoundServer(CMMFAudioServer* aAudioServer, TProcessId& aClientPID) :
1.39 + CMmfIpcServer(EPriorityStandard, EGlobalSharableSessions), iClientPID(aClientPID)
1.40 + {
1.41 + iAudioServer = aAudioServer;
1.42 + }
1.43 +
1.44 +void CMMFDevSoundServer::ConstructL()
1.45 + {
1.46 + RProcess client;
1.47 + User::LeaveIfError(client.Open(iClientPID));
1.48 + iClientHasCaps = client.HasCapability(ECapabilityMultimediaDD, KSuppressPlatSecDiagnostic);
1.49 + client.Close();
1.50 +
1.51 + iDelayDevSoundShutDown = CDelayDevSoundShutDown::NewL();
1.52 +
1.53 + // Call base class to Start server
1.54 + StartL(KNullDesC);
1.55 + }
1.56 +
1.57 +CMMFDevSoundServer::~CMMFDevSoundServer()
1.58 + {
1.59 + if (iDelayDevSoundShutDown)
1.60 + {
1.61 + iDelayDevSoundShutDown->Cancel();
1.62 + delete iDelayDevSoundShutDown;
1.63 + }
1.64 + }
1.65 +
1.66 +CMmfIpcSession* CMMFDevSoundServer::NewSessionL(const TVersion& aVersion) const
1.67 + {
1.68 + TVersion v(KMMFDevSoundServerVersion,KMMFDevSoundServerMinorVersionNumber,KMMFDevSoundServerBuildVersionNumber);
1.69 + if(!User::QueryVersionSupported(v, aVersion))
1.70 + User::Leave(KErrNotSupported);
1.71 +
1.72 + CMMFDevSoundSession* devSoundSession = CMMFDevSoundSession::NewL(iAudioServer->PolicyServerHandle());
1.73 + return devSoundSession;
1.74 + }
1.75 +
1.76 +void CMMFDevSoundServer::IncrementSessionId()
1.77 + {
1.78 + iDevSoundSessionId++;
1.79 + if(iDevSoundSessionId)
1.80 + iDelayDevSoundShutDown->Cancel();
1.81 +
1.82 + }
1.83 +
1.84 +void CMMFDevSoundServer::DecrementSessionId()
1.85 + {
1.86 + iDevSoundSessionId--;
1.87 + if ( iDevSoundSessionId == 0 )
1.88 + {
1.89 + iDelayDevSoundShutDown->SetDelay(TTimeIntervalMicroSeconds32(KDevSoundShutDownDelay));
1.90 + }
1.91 + }
1.92 +
1.93 +void CMMFDevSoundServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/)
1.94 + {
1.95 + // For the session requested, send event to client
1.96 + iSessionIter.SetToFirst();
1.97 + CMMFDevSoundSession* session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
1.98 + while (session != NULL)
1.99 + {
1.100 + if (session->DevSoundSessionId() == aSessionToAlert)
1.101 + {
1.102 + break; // Finished
1.103 + }
1.104 + session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
1.105 + }
1.106 + }
1.107 +
1.108 +void CMMFDevSoundServer::LaunchRequest(TInt aSessionId)
1.109 + {
1.110 + iSessionIter.SetToFirst();
1.111 + CMMFDevSoundSession* session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
1.112 + while (session != NULL)
1.113 + {
1.114 + if (session->DevSoundSessionId() == aSessionId)
1.115 + {
1.116 + break; // Finished
1.117 + }
1.118 + session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
1.119 + }
1.120 + }
1.121 +
1.122 +TBool CMMFDevSoundServer::CheckClientCapabilities()
1.123 + {
1.124 + return iClientHasCaps;
1.125 + }
1.126 +
1.127 +void CMMFDevSoundServer::SetClientCapabilitiesL(TThreadId aTid)
1.128 + {
1.129 + RThread clientThread;
1.130 + User::LeaveIfError(clientThread.Open(aTid));
1.131 + CleanupClosePushL(clientThread);
1.132 +
1.133 + RProcess clientProcess;
1.134 + User::LeaveIfError(clientThread.Process(clientProcess));
1.135 + CleanupClosePushL(clientProcess);
1.136 +
1.137 + iClientHasCaps = clientProcess.HasCapability(ECapabilityMultimediaDD, KSuppressPlatSecDiagnostic);
1.138 +
1.139 + CleanupStack::PopAndDestroy(2, &clientThread); // clientProcess, clientThread
1.140 + }
1.141 +
1.142 +void CMMFDevSoundServer::RenamePrioritizeServer()
1.143 + {
1.144 + //Rename devsound server name
1.145 + RThread devsoundServerThread;
1.146 + TThreadId threadId;
1.147 + TName name;
1.148 + name.Append(KMMFDevSoundServerName);
1.149 + threadId = devsoundServerThread.Id();
1.150 + name.AppendNum(threadId.Id(),EHex);
1.151 + //We are ignoring the error code returned from User::RenameThread
1.152 + //as it is not important here, may be for profiling
1.153 + User::RenameThread(name);
1.154 +
1.155 + //Set the devsound priority
1.156 + TThreadPriority devsoundServerPriority = static_cast<TThreadPriority>(KDevsoundServerPriority);
1.157 + devsoundServerThread.SetPriority(devsoundServerPriority);
1.158 + }
1.159 +
1.160 +CMMFDevSoundServer::CDelayDevSoundShutDown* CMMFDevSoundServer::CDelayDevSoundShutDown::NewL()
1.161 + {
1.162 + CDelayDevSoundShutDown* self = new(ELeave) CDelayDevSoundShutDown;
1.163 + CleanupStack::PushL(self);
1.164 + self->ConstructL();
1.165 + CleanupStack::Pop();
1.166 + return self;
1.167 + }
1.168 +
1.169 +CMMFDevSoundServer::CDelayDevSoundShutDown::CDelayDevSoundShutDown() : CActive(0)
1.170 + {
1.171 + }
1.172 +
1.173 +void CMMFDevSoundServer::CDelayDevSoundShutDown::ConstructL()
1.174 + {
1.175 + User::LeaveIfError(iTimer.CreateLocal());
1.176 + CActiveScheduler::Add(this);
1.177 + }
1.178 +
1.179 +CMMFDevSoundServer::CDelayDevSoundShutDown::~CDelayDevSoundShutDown()
1.180 + {
1.181 + Cancel();
1.182 + iTimer.Close();
1.183 + }
1.184 +
1.185 +
1.186 +void CMMFDevSoundServer::CDelayDevSoundShutDown::SetDelay(TTimeIntervalMicroSeconds32 aDelay)
1.187 + {
1.188 + __ASSERT_ALWAYS(!IsActive(),
1.189 + User::Panic(_L("CDelayedShutDown"), 1));
1.190 + iTimer.After(iStatus, aDelay);
1.191 + SetActive();
1.192 + }
1.193 +
1.194 +void CMMFDevSoundServer::CDelayDevSoundShutDown::RunL()
1.195 + {
1.196 + CActiveScheduler::Stop();
1.197 + }
1.198 +
1.199 +void CMMFDevSoundServer::CDelayDevSoundShutDown::DoCancel()
1.200 + {
1.201 + iTimer.Cancel();
1.202 + }
1.203 +
1.204 +/**
1.205 +@internalTechnology
1.206 +
1.207 +This function raises a panic on the client of the devsoundserver
1.208 +
1.209 +@param aError
1.210 + one of the several panic codes that may be raised by this dll on the client
1.211 +
1.212 +@panic EMMFDevSoundPlayDataWithoutInitialize is raised when playdata is called without initialization
1.213 +@panic EMMFDevSoundRecordDataWithoutInitialize is raised when recorddata is called without initialization
1.214 +*/
1.215 +GLDEF_C void PanicClient(const RMmfIpcMessage& aMessage, TMMFDevSoundClientPanicCodes aPanicCode)
1.216 + {
1.217 + aMessage.Panic(KMMFDevSoundClientPanicCategory, aPanicCode);
1.218 + }