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