mmresourcemgmt/mmresctrl/src/mmrcclient/mmrcclientimplementation.cpp
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     1 // Copyright (c) 2006-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 "mmrcclientimplementation.h"
       
    17 #include "mmrcclientmsgqueuehandler.h"
       
    18 #include "multimediaresourcecontrolobserver.h"
       
    19 #include "audiocontext.h"
       
    20 
       
    21 #include <a3f/maudiocontextobserver.h>
       
    22 
       
    23 
       
    24 const TInt KMsgQueueSlots = 8;
       
    25 
       
    26  
       
    27 /**
       
    28  */
       
    29 CMMRCClientImplementation::CMMRCClientImplementation(MMultimediaResourceControlObserver& aCallback) 
       
    30 : iObserver(aCallback)
       
    31 	{
       
    32 	TRACE_CREATE();
       
    33 	DP_CONTEXT(----> CMMRCClientImplementation::CMMRCClientImplementation *CD1*, CtxDevSound, DPLOCAL);
       
    34 	DP_IN();
       
    35 	DP_OUT();
       
    36 	}
       
    37 
       
    38 /**
       
    39  */
       
    40 CMMRCClientImplementation::~CMMRCClientImplementation()
       
    41 	{
       
    42 	DP_CONTEXT(----> CMMRCClientImplementation::~CMMRCClientImplementation *CD1*, CtxDevSound, DPLOCAL);
       
    43 	DP_IN();
       
    44 
       
    45 	if(iMsgClientQueueHandler)
       
    46 		{
       
    47 		delete iMsgClientQueueHandler;
       
    48 		}
       
    49 	iMsgQueue.Close();
       
    50 
       
    51 	DP_OUT();
       
    52 	}
       
    53 
       
    54 /**
       
    55  */
       
    56 CMMRCClientImplementation* CMMRCClientImplementation::NewL(MMultimediaResourceControlObserver& aCallback)
       
    57 	{
       
    58 	DP_STATIC_CONTEXT(----> CMMRCClientImplementation::NewL *CD1*, CtxDevSound, DPLOCAL);
       
    59 	DP_IN();
       
    60 	
       
    61 	CMMRCClientImplementation* self = new (ELeave) CMMRCClientImplementation(aCallback);
       
    62 	CleanupStack::PushL (self);
       
    63 	self->ConstructL ();
       
    64 	CleanupStack::Pop (self);
       
    65 
       
    66 	DP0_RET(self, "0x%x");
       
    67 	}
       
    68 
       
    69 /**
       
    70  */
       
    71 void CMMRCClientImplementation::ConstructL()
       
    72 	{
       
    73 	DP_CONTEXT(----> CMMRCClientImplementation::ConstructL *CD1*, CtxDevSound, DPLOCAL);
       
    74 	DP_IN();
       
    75 	
       
    76 	TInt error = iMMRCClientSession.Open (iObserver);
       
    77 	if ( KErrNotFound == error)
       
    78 		{
       
    79 		//The server is not found, create it
       
    80 		error = iMMRCClientSession.StartServer ();
       
    81 		User::LeaveIfError (error);
       
    82 
       
    83 		//Try again to create a connection to it
       
    84 		error = iMMRCClientSession.Open (iObserver);
       
    85 		#ifdef _DEBUG	
       
    86 		if(error != KErrNone)
       
    87 			{
       
    88 			RDebug::Print(_L("!!!!CMMRCClientImplementation::ConstructL - Open session 2 - error = %d"), error);
       
    89 			}
       
    90 		#endif
       
    91 		User::LeaveIfError (error);
       
    92 		}
       
    93 	#ifdef _DEBUG	
       
    94 	if(error != KErrNone)
       
    95 		{
       
    96 		RDebug::Print(_L("!!!!CMMRCClientImplementation::ConstructL - Open session 1 - error = %d"), error);
       
    97 		}
       
    98 	#endif
       
    99 	User::LeaveIfError (error);
       
   100 
       
   101 	//Create an un-named msg queue, a handle is needed to connect to it.
       
   102 	error = iMsgQueue.CreateGlobal (KNullDesC, KMsgQueueSlots,	EOwnerProcess);
       
   103 	#ifdef _DEBUG	
       
   104 	if(error != KErrNone)
       
   105 		{
       
   106 		RDebug::Print(_L("!!!!CMMRCClientImplementation::ConstructL - CreateGlobal - error = %d"), error);
       
   107 		}
       
   108 	#endif
       
   109 	User::LeaveIfError (error);
       
   110 	iMsgClientQueueHandler = CMMRCClientMsgQueueHandler::NewL (iMsgQueue, *this);
       
   111 
       
   112 	//Forward the message queue handle to the server, which will connect to it.
       
   113 	iMMRCClientSession.InitializeServerL(iMsgQueue);
       
   114 	
       
   115 	DP_OUT();
       
   116 	}
       
   117 /**
       
   118  */
       
   119 TUint64 CMMRCClientImplementation::LogOn(TProcessId aProcessId)
       
   120 	{
       
   121 	DP_CONTEXT(----> CMMRCClientImplementation::LogOn *CD1*, CtxDevSound, DPLOCAL);
       
   122 	DP_IN();
       
   123 	
       
   124 	TUint64 contextId = iMMRCClientSession.LogOn(aProcessId);
       
   125 	
       
   126 	DP0_RET(contextId, "contextId = %d");
       
   127 	}
       
   128 
       
   129 /**
       
   130  */
       
   131 void CMMRCClientImplementation::Close()
       
   132 	{
       
   133 	DP_CONTEXT(----> CMMRCClientImplementation::Close *CD1*, CtxDevSound, DPLOCAL);
       
   134 	DP_IN();
       
   135 
       
   136 	iMMRCClientSession.Close ();
       
   137 
       
   138 	DP_OUT();
       
   139 	}
       
   140 
       
   141 /**
       
   142  */
       
   143 TInt CMMRCClientImplementation::SendResourceRequest(MLogicalChain* aLogicalChainLastCommited, MLogicalChain* aLogicalChainRequested, CAudioContext* aContext)
       
   144 	{
       
   145 	DP_CONTEXT(----> CMMRCClientImplementation::SendResourceRequest *CD1*, CtxDevSound, DPLOCAL);
       
   146 	DP_IN();
       
   147 	
       
   148 	TInt err = iMMRCClientSession.SendResourceRequest(aLogicalChainLastCommited, aLogicalChainRequested, aContext);
       
   149 	
       
   150 	DP0_RET(err, "err = %d");
       
   151 	}
       
   152 
       
   153 /**y
       
   154  */
       
   155 void CMMRCClientImplementation::HandleMessage(TMMRCQueueItem& aMessage)
       
   156 	{
       
   157  	DP_CONTEXT(----> CMMRCClientImplementation::HandleMessage *CD1*, CtxDevSound, DPLOCAL);
       
   158 	DP_IN();
       
   159 	
       
   160 	#ifdef _DEBUG	
       
   161 		RDebug::Print(_L("RMMRCClientSession::ResourceRequestResponseL aMessage.iRequestType = %d, aMessage.iResult = %d, aMessage.iErrorCode = %d"), aMessage.iRequestType, aMessage.iResult, aMessage.iErrorCode);
       
   162 	#endif
       
   163 	
       
   164 	switch(aMessage.iRequestType)
       
   165 	{
       
   166 	
       
   167 	case EMMRCRequestCommitUpdate:
       
   168 		{
       
   169 		// Ignore this, now this will come directly from adaptation
       
   170 		// iObserver.ReceiveResourceUpdate(aMessage.iData, aMessage.iErrorCode);
       
   171 		}
       
   172 		break;
       
   173 
       
   174 	case EMMRCRequestCommitResponse:
       
   175 		{
       
   176 		// This would remain coming throug MMRC to update client side
       
   177 		iMMRCClientSession.ResourceRequestResponse(aMessage.iData, aMessage.iResult, aMessage.iErrorCode);
       
   178 		}
       
   179 		break;
       
   180 
       
   181 	case EMMRCRequestResourceUnallocated:
       
   182 		{
       
   183 		// Notification used for APR.
       
   184 		iObserver.CanResume();
       
   185 		}
       
   186 		break;
       
   187 		
       
   188 	default: //unknown message
       
   189 		#ifdef _DEBUG	
       
   190 			ASSERT(0);
       
   191 			RDebug::Print(_L("!!!!CMMRCClientImplementation::HandleMessage - Unknown message"));
       
   192 		#endif
       
   193 		break;
       
   194 	}
       
   195 	
       
   196 	DP_OUT();
       
   197 	}
       
   198 
       
   199 /**
       
   200  */
       
   201 TInt CMMRCClientImplementation::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
       
   202 	{
       
   203 	DP_CONTEXT(----> CMMRCClientImplementation::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
       
   204 	DP_IN();
       
   205 	
       
   206 	TInt err = iMMRCClientSession.RegisterAsClient(aEventType, aNotificationRegistrationData);
       
   207 
       
   208 	DP0_RET(err, "err = %d");
       
   209 	}
       
   210 	
       
   211 	
       
   212 /**
       
   213  */
       
   214 TInt CMMRCClientImplementation::CancelRegisterAsClient(TUid aEventType)
       
   215 	{
       
   216 	DP_CONTEXT(----> CMMRCClientImplementation::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
       
   217 	DP_IN();
       
   218 
       
   219 	TInt err = iMMRCClientSession.CancelRegisterAsClient(aEventType);
       
   220 
       
   221 	DP0_RET(err, "err = %d");
       
   222 	}
       
   223 	
       
   224 
       
   225 /**
       
   226  */
       
   227 TInt CMMRCClientImplementation::WillResumePlay()
       
   228 	{
       
   229 	DP_CONTEXT(----> CMMRCClientImplementation::WillResumePlay *CD1*, CtxDevSound, DPLOCAL);
       
   230 	DP_IN();
       
   231 
       
   232 	TInt err = iMMRCClientSession.WillResumePlay();
       
   233 
       
   234 	DP0_RET(err, "err = %d");
       
   235 	}
       
   236 	
       
   237 void CMMRCClientImplementation::ResetMessages()
       
   238 	{
       
   239 	DP_CONTEXT(----> CMMRCClientImplementation::ResetMessages *CD1*, CtxDevSound, DPLOCAL);
       
   240 	DP_IN();
       
   241 
       
   242 	iMMRCClientSession.ResetMessages();
       
   243 
       
   244 	DP_OUT();
       
   245 	}
       
   246 //EOF