mmresourcemgmt/mmresctrl/src/mmrcclient/mmrcclientsession.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 "mmrcclientsession.h"
       
    17 #include "mmrcserverstart.h"
       
    18 #include "multimediaresourcecontrolobserver.h"
       
    19 #include "mmrcadaptationproxy.h"
       
    20 #include "mlogicalchain.h"
       
    21 #include "audiocontext.h"
       
    22 /**
       
    23  * 
       
    24  */
       
    25 RMMRCClientSession::RMMRCClientSession()
       
    26 : iLogicalChainLastCommited(NULL),
       
    27   iLogicalChainRequested(NULL)
       
    28 	{
       
    29 	TRACE_CREATE();
       
    30 	DP_CONTEXT(----> RMMRCClientSession::RMMRCClientSession *CD1*, CtxDevSound, DPLOCAL);
       
    31 	DP_IN();
       
    32 	DP_OUT();
       
    33 	}
       
    34 
       
    35 /**
       
    36  * 
       
    37  */
       
    38 RMMRCClientSession::~RMMRCClientSession()
       
    39 	{
       
    40 	DP_CONTEXT(----> RMMRCClientSession::~RMMRCClientSession *CD1*, CtxDevSound, DPLOCAL);
       
    41 	DP_IN();
       
    42 	
       
    43 	if(iMMRCClientSideServerRequestToAdaptationAO)
       
    44 		{
       
    45 		delete iMMRCClientSideServerRequestToAdaptationAO;
       
    46 		iMMRCClientSideServerRequestToAdaptationAO=0;
       
    47 		}
       
    48 
       
    49 	DP_OUT();
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54 // Runs client-side and starts the separate server process
       
    55 */
       
    56 TInt RMMRCClientSession::StartServer()
       
    57 	{
       
    58 	DP_CONTEXT(----> RMMRCClientSession::StartServer *CD1*, CtxDevSound, DPLOCAL);
       
    59 	DP_IN();
       
    60 	
       
    61 	TInt err = KErrNone;
       
    62 	err = StartMMRCServer(iServerThread);
       
    63 	
       
    64 	DP0_RET(err, "err = %d");
       
    65 	}
       
    66 
       
    67 /**
       
    68 */
       
    69 TInt RMMRCClientSession::Open(MMultimediaResourceControlObserver& aCallback)
       
    70 	{
       
    71 	DP_CONTEXT(----> RMMRCClientSession::Open *CD1*, CtxDevSound, DPLOCAL);
       
    72 	DP_IN();
       
    73 	
       
    74 	TInt err = KErrNone;
       
    75 	iObserver = &aCallback;
       
    76 	
       
    77 	err = CreateSession(KMMRCServerName, TVersion(1,0,0));	 
       
    78 	
       
    79 	DP0_RET(err, "err = %d");
       
    80 	}
       
    81 
       
    82 /**
       
    83 */
       
    84 TUint64 RMMRCClientSession::LogOn(TProcessId aProcessId)
       
    85 	{
       
    86 	DP_CONTEXT(----> RMMRCClientSession::LogOn *CD1*, CtxDevSound, DPLOCAL);
       
    87 	DP_IN();
       
    88 	iCurrentRequestId = 0;
       
    89 	TUint64 contextId;
       
    90 	TPckg<TUint64> contextIdPckg(contextId);
       
    91 	TPckg<TProcessId> processIdPckg(aProcessId);
       
    92 	TIpcArgs args(&processIdPckg, &contextIdPckg);
       
    93 	
       
    94 	SendReceive(EMMRCClientToServerRequestContextId,args);
       
    95 	
       
    96 	DP0_RET(contextId, "contextId = %d");
       
    97 	}
       
    98 
       
    99 
       
   100 /**
       
   101  */
       
   102 void RMMRCClientSession::Close()
       
   103 	{
       
   104 	DP_CONTEXT(----> RMMRCClientSession::Close *CD1*, CtxDevSound, DPLOCAL);
       
   105 	DP_IN();
       
   106 
       
   107 	TRequestStatus RequestStatus;
       
   108 	SendReceive(EMMRCClientToServerCloseSession, TIpcArgs(0), RequestStatus);
       
   109 	User::WaitForRequest(RequestStatus); 
       
   110 	if(iMMRCClientSideServerRequestToAdaptationAO)
       
   111 		{
       
   112 		delete iMMRCClientSideServerRequestToAdaptationAO;
       
   113 		iMMRCClientSideServerRequestToAdaptationAO=0;
       
   114 		}
       
   115 	
       
   116 	RHandleBase::Close();
       
   117 	iServerThread.Close();
       
   118 	
       
   119 	DP_OUT();
       
   120 	}
       
   121 
       
   122 /**
       
   123 */
       
   124 void RMMRCClientSession::InitializeServerL(RHandleBase& aMsgQueueHandle)
       
   125 	{
       
   126 	DP_CONTEXT(----> RMMRCClientSession::InitializeServerL *CD1*, CtxDevSound, DPLOCAL);
       
   127 	DP_IN();
       
   128 	
       
   129 	//Send the Client ThreadId
       
   130 	RThread me;
       
   131 	const TThreadId& id = me.Id();
       
   132 	SendReceive(EMMRCClientToServerSetClientThreadId, TIpcArgs(&id));
       
   133 	
       
   134 	//Create a client side adaptation proxy on the client schudeler 
       
   135 	iMMRCClientSideServerRequestToAdaptationAO = CMMRCClientSideServerRequestToAdaptationAO::NewL();
       
   136 	// send synchronously the pointer to the server
       
   137 	SendReceive(EMMRCClientToServerSetAdaptationProxy, TIpcArgs(iMMRCClientSideServerRequestToAdaptationAO));
       
   138 	
       
   139 	//Send synchronously the Message Queue pointer to the server
       
   140 	SendReceive(EMMRCClientToServerSetMsgQueueHandle, TIpcArgs(aMsgQueueHandle));
       
   141 	
       
   142 	DP_OUT();
       
   143 	}
       
   144 
       
   145 /**
       
   146 */
       
   147 TInt RMMRCClientSession::SendResourceRequest(MLogicalChain* aLogicalChainLastCommited, MLogicalChain* aLogicalChainRequested, CAudioContext* aContext)
       
   148 	{
       
   149 	DP_CONTEXT(----SSSS> RMMRCClientSession::SendResourceRequest *CD1*, CtxDevSound, DPLOCAL);
       
   150 	DP_IN();
       
   151 
       
   152 	TInt err = KErrNone;
       
   153 	//Only one request at a time!!!
       
   154 	if(iLogicalChainLastCommited || iLogicalChainRequested)
       
   155 		{
       
   156 		err = KErrServerBusy;
       
   157 		#ifdef _DEBUG	
       
   158 			RDebug::Print(_L("!!RMMRCClientSession::SendResourceRequest -  Second request but server busy"));
       
   159 		#endif
       
   160 		DP0_RET(err, "err = %d");
       
   161 		}
       
   162 	
       
   163 	//Clone the chains; they are realesed on response
       
   164 	if( err == KErrNone )
       
   165 		{
       
   166 		TRAP(err, iLogicalChainLastCommited = aLogicalChainLastCommited->CloneL());
       
   167 		if( err == KErrNone )
       
   168 			{
       
   169 			TRAP(err, iLogicalChainRequested = aLogicalChainRequested->CloneL());
       
   170 			}
       
   171 		}
       
   172 		
       
   173 	//Send the request
       
   174 	if ( err == KErrNone )
       
   175 		{
       
   176 		// AM To determine when we reached the limit of messages
       
   177 		err = Send(EMMRCClientToServerRequestResource, TIpcArgs(iLogicalChainLastCommited, iLogicalChainRequested, aContext, aContext->MsgVersion()));
       
   178 		}
       
   179 	#ifdef _DEBUG	
       
   180 	else
       
   181 		{
       
   182 		RDebug::Print(_L("!!!!RMMRCClientSession::SendResourceRequest - Error = %d"), err);
       
   183 		}
       
   184 	#endif
       
   185 	
       
   186 	DP0_RET(err, "err = %d");
       
   187 	}
       
   188 
       
   189 /**
       
   190  */
       
   191  void RMMRCClientSession::ResourceRequestResponse(MLogicalChain* aChainResponse, TMMRCServerToClientMessageResults /*aResult*/, TInt aError)
       
   192 	{
       
   193 	DP_CONTEXT(--------> RMMRCClientSession::ResourceRequestResponseL *CD1*, CtxDevSound, DPLOCAL);
       
   194 	DP_IN();
       
   195 	
       
   196 	//Check if the response is not null... Should never happen
       
   197 	if( aChainResponse == NULL && aError == KErrNone)
       
   198 	//coverity[var_compare_op]	
       
   199 		{
       
   200 		RDebug::Print(_L("!!!!RMMRCClientSession::ResourceRequestResponseL -  Chain in input NULL - KErrArgument"));
       
   201 		__ASSERT_ALWAYS(0, User::Panic(_L("MMRCClientSessionNullResponse"), 1));
       
   202 		}
       
   203 	
       
   204 	iObserver->ReceiveResourceResponse(aChainResponse, aError);
       
   205 	//coverity[var_deref_model]
       
   206 	// Coverity incorrectly assumes that aChainResponse is always NULL
       
   207 	DP_OUT();
       
   208 	}
       
   209 
       
   210 /**
       
   211 */
       
   212 TInt RMMRCClientSession::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
       
   213 	{
       
   214 	DP_CONTEXT(----> RMMRCClientSession::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
       
   215 	DP_IN();
       
   216 	
       
   217 	TInt err (KErrNone);
       
   218 	err = SendReceive(EMMRCClientToServerRegisterAsClient, TIpcArgs(&aEventType, &aNotificationRegistrationData));
       
   219 
       
   220 	
       
   221 	DP0_RET(err, "err = %d");
       
   222 	}
       
   223 	
       
   224 /**
       
   225 */	
       
   226 TInt RMMRCClientSession::CancelRegisterAsClient(TUid aEventType)
       
   227 	{
       
   228 	DP_CONTEXT(----> RMMRCClientSession::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
       
   229 	DP_IN();
       
   230 	
       
   231 	TInt err (KErrNone);
       
   232 	err = SendReceive(EMMRCClientToServerCancelRegisterAsClient, TIpcArgs(&aEventType));
       
   233 
       
   234 	
       
   235 	DP0_RET(err, "err = %d");
       
   236 	}
       
   237 
       
   238 /**
       
   239 */	
       
   240 TInt RMMRCClientSession::WillResumePlay()
       
   241 	{
       
   242 	DP_CONTEXT(----> RMMRCClientSession::WillResumePlay *CD1*, CtxDevSound, DPLOCAL);
       
   243 	DP_IN();
       
   244 	
       
   245 	TInt err (KErrNone);
       
   246 	err = SendReceive(EMMRCClientToServerWillResumePlay, TIpcArgs(0));
       
   247 
       
   248 	
       
   249 	DP0_RET(err, "err = %d");
       
   250 	}
       
   251 	
       
   252 void RMMRCClientSession::ResetMessages()
       
   253 	{
       
   254 	DP_CONTEXT(----> RMMRCClientSession::ResetMessages *CD1*, CtxDevSound, DPLOCAL);
       
   255 	DP_IN();
       
   256 	
       
   257 	//Clean the logical chains
       
   258 	if(iLogicalChainLastCommited)
       
   259 		{
       
   260 		iLogicalChainLastCommited->Release();
       
   261 		iLogicalChainLastCommited = NULL;
       
   262 		}
       
   263 	if(iLogicalChainRequested)
       
   264 		{
       
   265 		iLogicalChainRequested->Release();
       
   266 		iLogicalChainRequested = NULL;
       
   267 		}
       
   268 	
       
   269 	DP_OUT();
       
   270 	}		
       
   271 //EOF
       
   272