sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "mmrcclientsession.h" sl@0: #include "mmrcserverstart.h" sl@0: #include "multimediaresourcecontrolobserver.h" sl@0: #include "mmrcadaptationproxy.h" sl@0: #include "mlogicalchain.h" sl@0: #include "audiocontext.h" sl@0: /** sl@0: * sl@0: */ sl@0: RMMRCClientSession::RMMRCClientSession() sl@0: : iLogicalChainLastCommited(NULL), sl@0: iLogicalChainRequested(NULL) sl@0: { sl@0: TRACE_CREATE(); sl@0: DP_CONTEXT(----> RMMRCClientSession::RMMRCClientSession *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: DP_OUT(); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: */ sl@0: RMMRCClientSession::~RMMRCClientSession() sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::~RMMRCClientSession *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: if(iMMRCClientSideServerRequestToAdaptationAO) sl@0: { sl@0: delete iMMRCClientSideServerRequestToAdaptationAO; sl@0: iMMRCClientSideServerRequestToAdaptationAO=0; sl@0: } sl@0: sl@0: DP_OUT(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: // Runs client-side and starts the separate server process sl@0: */ sl@0: TInt RMMRCClientSession::StartServer() sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::StartServer *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err = KErrNone; sl@0: err = StartMMRCServer(iServerThread); sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RMMRCClientSession::Open(MMultimediaResourceControlObserver& aCallback) sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::Open *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err = KErrNone; sl@0: iObserver = &aCallback; sl@0: sl@0: err = CreateSession(KMMRCServerName, TVersion(1,0,0)); sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TUint64 RMMRCClientSession::LogOn(TProcessId aProcessId) sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::LogOn *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: iCurrentRequestId = 0; sl@0: TUint64 contextId; sl@0: TPckg contextIdPckg(contextId); sl@0: TPckg processIdPckg(aProcessId); sl@0: TIpcArgs args(&processIdPckg, &contextIdPckg); sl@0: sl@0: SendReceive(EMMRCClientToServerRequestContextId,args); sl@0: sl@0: DP0_RET(contextId, "contextId = %d"); sl@0: } sl@0: sl@0: sl@0: /** sl@0: */ sl@0: void RMMRCClientSession::Close() sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::Close *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TRequestStatus RequestStatus; sl@0: SendReceive(EMMRCClientToServerCloseSession, TIpcArgs(0), RequestStatus); sl@0: User::WaitForRequest(RequestStatus); sl@0: if(iMMRCClientSideServerRequestToAdaptationAO) sl@0: { sl@0: delete iMMRCClientSideServerRequestToAdaptationAO; sl@0: iMMRCClientSideServerRequestToAdaptationAO=0; sl@0: } sl@0: sl@0: RHandleBase::Close(); sl@0: iServerThread.Close(); sl@0: sl@0: DP_OUT(); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: void RMMRCClientSession::InitializeServerL(RHandleBase& aMsgQueueHandle) sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::InitializeServerL *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: //Send the Client ThreadId sl@0: RThread me; sl@0: const TThreadId& id = me.Id(); sl@0: SendReceive(EMMRCClientToServerSetClientThreadId, TIpcArgs(&id)); sl@0: sl@0: //Create a client side adaptation proxy on the client schudeler sl@0: iMMRCClientSideServerRequestToAdaptationAO = CMMRCClientSideServerRequestToAdaptationAO::NewL(); sl@0: // send synchronously the pointer to the server sl@0: SendReceive(EMMRCClientToServerSetAdaptationProxy, TIpcArgs(iMMRCClientSideServerRequestToAdaptationAO)); sl@0: sl@0: //Send synchronously the Message Queue pointer to the server sl@0: SendReceive(EMMRCClientToServerSetMsgQueueHandle, TIpcArgs(aMsgQueueHandle)); sl@0: sl@0: DP_OUT(); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RMMRCClientSession::SendResourceRequest(MLogicalChain* aLogicalChainLastCommited, MLogicalChain* aLogicalChainRequested, CAudioContext* aContext) sl@0: { sl@0: DP_CONTEXT(----SSSS> RMMRCClientSession::SendResourceRequest *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err = KErrNone; sl@0: //Only one request at a time!!! sl@0: if(iLogicalChainLastCommited || iLogicalChainRequested) sl@0: { sl@0: err = KErrServerBusy; sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("!!RMMRCClientSession::SendResourceRequest - Second request but server busy")); sl@0: #endif sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: //Clone the chains; they are realesed on response sl@0: if( err == KErrNone ) sl@0: { sl@0: TRAP(err, iLogicalChainLastCommited = aLogicalChainLastCommited->CloneL()); sl@0: if( err == KErrNone ) sl@0: { sl@0: TRAP(err, iLogicalChainRequested = aLogicalChainRequested->CloneL()); sl@0: } sl@0: } sl@0: sl@0: //Send the request sl@0: if ( err == KErrNone ) sl@0: { sl@0: // AM To determine when we reached the limit of messages sl@0: err = Send(EMMRCClientToServerRequestResource, TIpcArgs(iLogicalChainLastCommited, iLogicalChainRequested, aContext, aContext->MsgVersion())); sl@0: } sl@0: #ifdef _DEBUG sl@0: else sl@0: { sl@0: RDebug::Print(_L("!!!!RMMRCClientSession::SendResourceRequest - Error = %d"), err); sl@0: } sl@0: #endif sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: void RMMRCClientSession::ResourceRequestResponse(MLogicalChain* aChainResponse, TMMRCServerToClientMessageResults /*aResult*/, TInt aError) sl@0: { sl@0: DP_CONTEXT(--------> RMMRCClientSession::ResourceRequestResponseL *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: //Check if the response is not null... Should never happen sl@0: if( aChainResponse == NULL && aError == KErrNone) sl@0: //coverity[var_compare_op] sl@0: { sl@0: RDebug::Print(_L("!!!!RMMRCClientSession::ResourceRequestResponseL - Chain in input NULL - KErrArgument")); sl@0: __ASSERT_ALWAYS(0, User::Panic(_L("MMRCClientSessionNullResponse"), 1)); sl@0: } sl@0: sl@0: iObserver->ReceiveResourceResponse(aChainResponse, aError); sl@0: //coverity[var_deref_model] sl@0: // Coverity incorrectly assumes that aChainResponse is always NULL sl@0: DP_OUT(); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RMMRCClientSession::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData) sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err (KErrNone); sl@0: err = SendReceive(EMMRCClientToServerRegisterAsClient, TIpcArgs(&aEventType, &aNotificationRegistrationData)); sl@0: sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RMMRCClientSession::CancelRegisterAsClient(TUid aEventType) sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err (KErrNone); sl@0: err = SendReceive(EMMRCClientToServerCancelRegisterAsClient, TIpcArgs(&aEventType)); sl@0: sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RMMRCClientSession::WillResumePlay() sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::WillResumePlay *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: TInt err (KErrNone); sl@0: err = SendReceive(EMMRCClientToServerWillResumePlay, TIpcArgs(0)); sl@0: sl@0: sl@0: DP0_RET(err, "err = %d"); sl@0: } sl@0: sl@0: void RMMRCClientSession::ResetMessages() sl@0: { sl@0: DP_CONTEXT(----> RMMRCClientSession::ResetMessages *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: sl@0: //Clean the logical chains sl@0: if(iLogicalChainLastCommited) sl@0: { sl@0: iLogicalChainLastCommited->Release(); sl@0: iLogicalChainLastCommited = NULL; sl@0: } sl@0: if(iLogicalChainRequested) sl@0: { sl@0: iLogicalChainRequested->Release(); sl@0: iLogicalChainRequested = NULL; sl@0: } sl@0: sl@0: DP_OUT(); sl@0: } sl@0: //EOF sl@0: