os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicyServer.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) 2000-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 "MmfBtAudioPolicyServer.h"
    18 #include "MmfBtAudioPolicyStart.h"
    19 #include "MmfBtAudioPolicySession.h"
    20 
    21 const TInt KTimeOutInterval = 1000000;
    22 
    23 CMMFAudioPolicyServer* CMMFAudioPolicyServer::NewL()
    24 	{
    25 	CMMFAudioPolicyServer* s = new(ELeave) CMMFAudioPolicyServer();
    26 	CleanupStack::PushL(s);
    27 	s->ConstructL();
    28 	CleanupStack::Pop();
    29 	return s;
    30 	}
    31 
    32 CMMFAudioPolicyServer::CMMFAudioPolicyServer() :
    33 	CMmfIpcServer(EPriorityStandard)
    34 	{
    35 	}
    36 
    37 void CMMFAudioPolicyServer::ConstructL()
    38 	{
    39 	// Create AudioPolicy singleton
    40 	iAudioPolicy = CAudioPolicy::NewL(this);
    41 	TCallBack callBack(SendNotification,this);
    42 	iNotificationTimer = CNotificationTimer::NewL(callBack);
    43 	// Call base class to Start server
    44 	StartL(KNullDesC);
    45 	}
    46 
    47 CMMFAudioPolicyServer::~CMMFAudioPolicyServer()
    48 	{
    49 	if(iNotificationTimer != NULL)
    50 		{
    51 		StopNotificationTimer();
    52 		}
    53 	delete iAudioPolicy;
    54 	delete iNotificationTimer;
    55 	}
    56 
    57 CMmfIpcSession* CMMFAudioPolicyServer::NewSessionL(const TVersion& aVersion) const
    58 	{
    59 	TVersion v(KMMFAudioPolicyVersion,KMMFAudioPolicyMinorVersionNumber,KMMFAudioPolicyBuildVersionNumber);
    60 	if(!User::QueryVersionSupported(v, aVersion))
    61 		User::Leave(KErrNotSupported);
    62 	
    63 	CMMFAudioPolicySession* aAudioPolicySession = CMMFAudioPolicySession::NewL();
    64 	return aAudioPolicySession;
    65 	}
    66 
    67 void CMMFAudioPolicyServer::IncrementSessionId()
    68 	{
    69 	iPolicySessionId++;
    70 	}
    71 
    72 void CMMFAudioPolicyServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/, TMMFAudioPolicyEvent& aEvent)
    73 	{
    74 	TMMFAudioPolicyEvent eventForClient;
    75 	eventForClient.iEventType = aEvent.iEventType;
    76 	eventForClient.iErrorCode = aEvent.iErrorCode;
    77 	eventForClient.iState = aEvent.iState;
    78 
    79 	// For the session requested, send event to client
    80 	iSessionIter.SetToFirst();
    81 	CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
    82 	while (session != NULL)
    83 		{
    84 		if (session->PolicySessionId() == aSessionToAlert)
    85 			{
    86 			session->SendEventToClient(eventForClient);
    87 			break;  // Finished
    88 			}
    89 		session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
    90 		}
    91 	}
    92 	
    93 void CMMFAudioPolicyServer::LaunchRequest(TInt aSessionId, TMMFAudioPolicyEvent& aEvent)
    94 	{
    95 	iSessionIter.SetToFirst();
    96 	CMMFAudioPolicySession* session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
    97 	while (session != NULL)
    98 		{
    99 		if (session->PolicySessionId() == aSessionId)
   100 			{
   101 			session->SendEventToClient(aEvent);
   102 			break;  // Finished
   103 			}
   104 		session = STATIC_CAST(CMMFAudioPolicySession*, iSessionIter++);
   105 		}
   106 	}
   107 
   108 void CMMFAudioPolicyServer::IncrementSessionCount()
   109 	{
   110 	iPolicySessionCount++;
   111 	}
   112 
   113 CMMFAudioPolicyServer::CNotificationTimer *CMMFAudioPolicyServer::CNotificationTimer::NewL(TCallBack aCallBack)	
   114 	{
   115 	CNotificationTimer* self = new(ELeave) CNotificationTimer(aCallBack);
   116 	CleanupStack::PushL(self);
   117 	self->ConstructL();
   118 	CleanupStack::Pop(); // self
   119 	return self;
   120 	}
   121 
   122 CMMFAudioPolicyServer::CNotificationTimer::CNotificationTimer(TCallBack aCallBack)
   123 : CTimer(EPriorityHigh),iCallBack(aCallBack)
   124 	{
   125 	CActiveScheduler::Add(this);
   126 	}
   127 
   128 void CMMFAudioPolicyServer::CNotificationTimer::RunL()
   129 	{
   130 	iCallBack.CallBack();
   131 	}
   132 
   133 void CMMFAudioPolicyServer::DecrementSessionCount()
   134 	{
   135 	iPolicySessionCount--;
   136 	}
   137 
   138 TInt CMMFAudioPolicyServer::PolicySessionCount() 
   139 	{
   140 	return iPolicySessionCount;
   141 	}
   142 
   143 void CMMFAudioPolicyServer::StartNotificationTimer()
   144 	{
   145 	iNotificationTimer->After(KTimeOutInterval);
   146 	}
   147 	
   148 void CMMFAudioPolicyServer::StopNotificationTimer()
   149 	{
   150 	iNotificationTimer->Cancel();			
   151 	}
   152 
   153 TInt CMMFAudioPolicyServer::SendNotification(TAny* aAny)
   154 	{
   155 	CMMFAudioPolicyServer* policyServer = reinterpret_cast<CMMFAudioPolicyServer*>(aAny);
   156 	policyServer->iAudioPolicy->DoSendNotification();
   157 	return KErrNone;
   158 	}
   159 
   160 TBool CMMFAudioPolicyServer::IsTimerActive() const 
   161 	{
   162 	return iNotificationTimer->IsActive();
   163 	}