os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundServer.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32math.h>
    17 #include "MmfDevSoundServer.h"
    18 #include "MmfDevSoundServerStart.h"
    19 #include "MmfDevSoundSession.h"
    20 
    21 const TInt KDevSoundShutDownDelay = 0; //0 sec
    22 _LIT(KMMFDevSoundServerName, "MMFDevSoundServer-");
    23 
    24 
    25 
    26 EXPORT_C CMMFDevSoundServer* CMMFDevSoundServer::NewL(CMMFAudioServer* aAudioServer, TProcessId& aClientPID)
    27 	{
    28 	CMMFDevSoundServer* s = new(ELeave) CMMFDevSoundServer(aAudioServer, aClientPID);
    29 	CleanupStack::PushL(s);
    30 	s->ConstructL();
    31 	CleanupStack::Pop();
    32 	return s;
    33 	}
    34 
    35 CMMFDevSoundServer::CMMFDevSoundServer(CMMFAudioServer* aAudioServer, TProcessId& aClientPID) :
    36 	CMmfIpcServer(EPriorityStandard, EGlobalSharableSessions), iClientPID(aClientPID)
    37 	{
    38 	iAudioServer = aAudioServer;
    39 	}
    40 
    41 void CMMFDevSoundServer::ConstructL()
    42 	{
    43 	RProcess client;
    44 	User::LeaveIfError(client.Open(iClientPID));
    45 	iClientHasCaps = client.HasCapability(ECapabilityMultimediaDD, KSuppressPlatSecDiagnostic);
    46 	client.Close();
    47 
    48 	iDelayDevSoundShutDown = CDelayDevSoundShutDown::NewL();
    49 
    50 	// Call base class to Start server
    51 	StartL(KNullDesC);
    52 	}
    53 
    54 CMMFDevSoundServer::~CMMFDevSoundServer()
    55 	{
    56 	if (iDelayDevSoundShutDown)
    57 		{
    58 		iDelayDevSoundShutDown->Cancel();
    59 		delete iDelayDevSoundShutDown;
    60 		}
    61 	}
    62 
    63 CMmfIpcSession* CMMFDevSoundServer::NewSessionL(const TVersion& aVersion) const
    64 	{
    65 	TVersion v(KMMFDevSoundServerVersion,KMMFDevSoundServerMinorVersionNumber,KMMFDevSoundServerBuildVersionNumber);
    66 	if(!User::QueryVersionSupported(v, aVersion))
    67 		User::Leave(KErrNotSupported);
    68 	
    69 	CMMFDevSoundSession* devSoundSession = CMMFDevSoundSession::NewL(iAudioServer->PolicyServerHandle());
    70 	return devSoundSession;
    71 	}
    72 
    73 void CMMFDevSoundServer::IncrementSessionId()
    74 	{
    75 	iDevSoundSessionId++;
    76 	if(iDevSoundSessionId)
    77 		iDelayDevSoundShutDown->Cancel();
    78 
    79 	}
    80 
    81 void CMMFDevSoundServer::DecrementSessionId()
    82 	{
    83 	iDevSoundSessionId--;
    84     if ( iDevSoundSessionId == 0 )
    85 		{
    86 		iDelayDevSoundShutDown->SetDelay(TTimeIntervalMicroSeconds32(KDevSoundShutDownDelay));
    87  		}
    88 	}
    89 
    90 void CMMFDevSoundServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/)
    91 	{
    92 	// For the session requested, send event to client
    93 	iSessionIter.SetToFirst();
    94 	CMMFDevSoundSession* session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
    95 	while (session != NULL)
    96 		{
    97 		if (session->DevSoundSessionId() == aSessionToAlert)
    98 			{
    99 			break;  // Finished
   100 			}
   101 		session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
   102 		}
   103 	}
   104 
   105 void CMMFDevSoundServer::LaunchRequest(TInt aSessionId)
   106 	{
   107 	iSessionIter.SetToFirst();
   108 	CMMFDevSoundSession* session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
   109 	while (session != NULL)
   110 		{
   111 		if (session->DevSoundSessionId() == aSessionId)
   112 			{
   113 			break;  // Finished
   114 			}
   115 		session = static_cast<CMMFDevSoundSession*>(iSessionIter++);
   116 		}
   117 	}
   118 
   119 TBool CMMFDevSoundServer::CheckClientCapabilities()
   120 	{
   121 	return iClientHasCaps;
   122 	}
   123 
   124 void CMMFDevSoundServer::SetClientCapabilitiesL(TThreadId aTid)
   125 	{
   126 	RThread clientThread;
   127 	User::LeaveIfError(clientThread.Open(aTid));
   128 	CleanupClosePushL(clientThread);
   129 	
   130 	RProcess clientProcess;
   131 	User::LeaveIfError(clientThread.Process(clientProcess));
   132 	CleanupClosePushL(clientProcess);
   133 	
   134 	iClientHasCaps = clientProcess.HasCapability(ECapabilityMultimediaDD, KSuppressPlatSecDiagnostic);
   135 	
   136 	CleanupStack::PopAndDestroy(2, &clientThread);	// clientProcess, clientThread
   137 	}
   138 	
   139 void CMMFDevSoundServer::RenamePrioritizeServer()
   140 	{
   141 	//Rename devsound server name
   142 	RThread devsoundServerThread;
   143 	TThreadId threadId;
   144 	TName name;
   145 	name.Append(KMMFDevSoundServerName); 
   146 	threadId = devsoundServerThread.Id();
   147 	name.AppendNum(threadId.Id(),EHex);
   148 	//We are ignoring the error code returned from User::RenameThread
   149 	//as it is not important here, may be for profiling
   150 	User::RenameThread(name);
   151 	
   152 	//Set the devsound priority
   153 	TThreadPriority devsoundServerPriority = static_cast<TThreadPriority>(KDevsoundServerPriority);
   154 	devsoundServerThread.SetPriority(devsoundServerPriority);
   155 	}
   156 
   157 CMMFDevSoundServer::CDelayDevSoundShutDown* CMMFDevSoundServer::CDelayDevSoundShutDown::NewL()
   158 	{
   159 	CDelayDevSoundShutDown* self = new(ELeave) CDelayDevSoundShutDown;
   160 	CleanupStack::PushL(self);
   161 	self->ConstructL();
   162 	CleanupStack::Pop();
   163 	return self;
   164 	}
   165 
   166 CMMFDevSoundServer::CDelayDevSoundShutDown::CDelayDevSoundShutDown() : CActive(0)
   167 	{
   168 	}
   169         
   170 void CMMFDevSoundServer::CDelayDevSoundShutDown::ConstructL()
   171 	{
   172 	User::LeaveIfError(iTimer.CreateLocal());
   173 	CActiveScheduler::Add(this);
   174 	}
   175 
   176 CMMFDevSoundServer::CDelayDevSoundShutDown::~CDelayDevSoundShutDown()
   177 	{
   178 	Cancel();
   179 	iTimer.Close();
   180 	}
   181 
   182 
   183 void CMMFDevSoundServer::CDelayDevSoundShutDown::SetDelay(TTimeIntervalMicroSeconds32 aDelay)
   184 	{
   185 	__ASSERT_ALWAYS(!IsActive(),
   186 	User::Panic(_L("CDelayedShutDown"), 1));
   187 	iTimer.After(iStatus, aDelay);
   188 	SetActive();
   189 	}
   190 
   191 void CMMFDevSoundServer::CDelayDevSoundShutDown::RunL()
   192 	{
   193 	CActiveScheduler::Stop();
   194 	}
   195 
   196 void CMMFDevSoundServer::CDelayDevSoundShutDown::DoCancel()
   197 	{
   198 	iTimer.Cancel();
   199 	}
   200   
   201 /**
   202 @internalTechnology
   203 
   204 This function raises a panic on the client of the devsoundserver
   205 
   206 @param	aError
   207 		one of the several panic codes that may be raised by this dll on the client
   208 
   209 @panic	EMMFDevSoundPlayDataWithoutInitialize is raised when playdata is called without initialization
   210 @panic	EMMFDevSoundRecordDataWithoutInitialize is raised when recorddata is called without initialization
   211 */
   212 GLDEF_C void PanicClient(const RMmfIpcMessage& aMessage, TMMFDevSoundClientPanicCodes aPanicCode)
   213 	{
   214 	aMessage.Panic(KMMFDevSoundClientPanicCategory, aPanicCode);
   215 	}