os/mm/mmresourcemgmt/mmresctrl/src/mmrcserver/mmrcserver.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) 2007-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 "mmrcserver.h"
sl@0
    17
#include "mmrcserversession.h"
sl@0
    18
#include "mmrcservercontroller.h"
sl@0
    19
#include "mmrcserverstart.h"
sl@0
    20
#include <a3f/a3ffourcclookup.h>
sl@0
    21
#include <a3f/a3f_trace_utils.h>
sl@0
    22
sl@0
    23
sl@0
    24
//------------------------------------------------------------------------------------
sl@0
    25
//
sl@0
    26
//------------------------------------------------------------------------------------
sl@0
    27
/**
sl@0
    28
 * Constructor
sl@0
    29
 */
sl@0
    30
CMMRCServer::CMMRCServer()
sl@0
    31
:  CServer2(EPriorityStandard)
sl@0
    32
	{ 
sl@0
    33
	TRACE_CREATE();
sl@0
    34
	DP_CONTEXT(----> CMMRCServer::CMMRCServer *CD1*, CtxDevSound, DPLOCAL);
sl@0
    35
	DP_IN();
sl@0
    36
	
sl@0
    37
	Cancel();
sl@0
    38
	
sl@0
    39
	DP_OUT();
sl@0
    40
	}
sl@0
    41
sl@0
    42
/**
sl@0
    43
 * Destructor.
sl@0
    44
 */
sl@0
    45
CMMRCServer::~CMMRCServer()
sl@0
    46
	{
sl@0
    47
	DP_CONTEXT(----> CMMRCServer::~CMMRCServer *CD1*, CtxDevSound, DPLOCAL);
sl@0
    48
	DP_IN();
sl@0
    49
	
sl@0
    50
	if(iMMRCServerController)
sl@0
    51
		{
sl@0
    52
		delete iMMRCServerController;
sl@0
    53
		}
sl@0
    54
	delete iFourCCConvertor;
sl@0
    55
	DP_OUT();
sl@0
    56
	}
sl@0
    57
sl@0
    58
//------------------------------------------------------------------------------------
sl@0
    59
//
sl@0
    60
//------------------------------------------------------------------------------------
sl@0
    61
/**
sl@0
    62
 * Constructs, and returns a pointer to, a new CMMRCServer object.
sl@0
    63
 * Leaves on failure.
sl@0
    64
 * @return CMMRCServer* A pointer to newly created utlitly object.
sl@0
    65
 */		
sl@0
    66
CMMRCServer* CMMRCServer::NewL()
sl@0
    67
	{
sl@0
    68
	DP_STATIC_CONTEXT(----> CMMRCServer::NewL *CD1*, CtxDevSound, DPLOCAL);
sl@0
    69
	DP_IN();
sl@0
    70
	
sl@0
    71
	CMMRCServer* self = NewLC();
sl@0
    72
	CleanupStack::Pop(self);
sl@0
    73
	
sl@0
    74
	DP0_RET(self, "0x%x");
sl@0
    75
	} 
sl@0
    76
sl@0
    77
/**
sl@0
    78
 * Constructs, leaves object on the cleanup stack, and returns a pointer
sl@0
    79
 * to, a new CMMRCServer object.
sl@0
    80
 * Leaves on failure.
sl@0
    81
 * @return CMMRCServer* A pointer to newly created utlitly object.
sl@0
    82
 */		
sl@0
    83
CMMRCServer* CMMRCServer::NewLC()
sl@0
    84
	{
sl@0
    85
	DP_STATIC_CONTEXT(----> CMMRCServer::Open *CD1*, CtxDevSound, DPLOCAL);
sl@0
    86
	DP_IN();
sl@0
    87
	
sl@0
    88
	CMMRCServer* self = new(ELeave) CMMRCServer;
sl@0
    89
	CleanupStack::PushL(self);
sl@0
    90
	self->ConstructL();
sl@0
    91
	
sl@0
    92
	DP0_RET(self, "self = 0x%x");
sl@0
    93
	}
sl@0
    94
sl@0
    95
/**
sl@0
    96
 	CMMRCServer::ConstructL
sl@0
    97
 	Symbian 2nd phase constructor can leave.
sl@0
    98
 */
sl@0
    99
void CMMRCServer::ConstructL()
sl@0
   100
	{
sl@0
   101
	DP_CONTEXT(----> CMMRCServer::ConstructL *CD1*, CtxDevSound, DPLOCAL);
sl@0
   102
	DP_IN();
sl@0
   103
	
sl@0
   104
	iMMRCServerController = CMMRCServerController::NewL();
sl@0
   105
	
sl@0
   106
	iFourCCConvertor = CFourCCConvertor::NewL();
sl@0
   107
	DP_OUT();
sl@0
   108
	}
sl@0
   109
sl@0
   110
//------------------------------------------------------------------------------------
sl@0
   111
//
sl@0
   112
//------------------------------------------------------------------------------------
sl@0
   113
/**
sl@0
   114
 * From CServer2. Creates a server-side client session object.
sl@0
   115
 * Creates a new session.  Only one session may be created with the ControllerProxyServer.
sl@0
   116
 * This function may leave with one of the system-wide error codes.
sl@0
   117
 * @param const TVersion& aVersion	The version number of the session.
sl@0
   118
 * @param const RMessage2& aMessage
sl@0
   119
 * @return A pointer to the new session.
sl@0
   120
 */
sl@0
   121
CSession2* CMMRCServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
sl@0
   122
	{
sl@0
   123
	DP_CONTEXT(----> CMMRCServer::NewSessionL *CD1*, CtxDevSound, DPLOCAL);
sl@0
   124
	DP_IN();
sl@0
   125
	
sl@0
   126
	TVersion version(KMMRCServerVersion,KMMRCServerMinorVersionNumber,KMMRCServerBuildVersionNumber);
sl@0
   127
	if(!User::QueryVersionSupported(version, aVersion))
sl@0
   128
		{
sl@0
   129
		User::Leave(KErrNotSupported);	   
sl@0
   130
		}
sl@0
   131
	CMMRCServerSession* mmrcSession = CMMRCServerSession::NewL(*iMMRCServerController, *iFourCCConvertor);
sl@0
   132
	
sl@0
   133
	DP0_RET(mmrcSession, "mmrcSession = 0x%x");
sl@0
   134
	}
sl@0
   135
sl@0
   136
/**
sl@0
   137
A utility function to panic the server.
sl@0
   138
*/
sl@0
   139
void CMMRCServer::PanicServer(TInt aPanic)
sl@0
   140
	{
sl@0
   141
	_LIT(KMMRCServerPanic,"MMRC Server panic");
sl@0
   142
	User::Panic(KMMRCServerPanic, aPanic);
sl@0
   143
	}
sl@0
   144
sl@0
   145
//------------------------------------------------------------------------------------
sl@0
   146
//
sl@0
   147
//------------------------------------------------------------------------------------
sl@0
   148
TInt CMMRCServer::ThreadFunctionL(TAny* /**aStarted*/)
sl@0
   149
	{
sl@0
   150
	DP_STATIC_CONTEXT(----> CMMRCServer::ThreadFunctionL *CD1*, CtxDevSound, DPLOCAL);
sl@0
   151
	DP_IN();
sl@0
   152
	
sl@0
   153
	// create an active scheduler and server
sl@0
   154
	CActiveScheduler* sched = new (ELeave) CActiveScheduler;
sl@0
   155
	CleanupStack::PushL(sched);
sl@0
   156
	
sl@0
   157
	//Install the active scheduler
sl@0
   158
	CActiveScheduler::Install(sched);
sl@0
   159
	
sl@0
   160
	CMMRCServer *server = CMMRCServer::NewLC();
sl@0
   161
		
sl@0
   162
sl@0
   163
	// Start the server
sl@0
   164
	TInt err = server->Start(KMMRCServerName);
sl@0
   165
	if (err != KErrNone)
sl@0
   166
		{
sl@0
   167
		CMMRCServer::PanicServer(KErrNoMemory);
sl@0
   168
		}
sl@0
   169
sl@0
   170
	// Let everyone know that we are ready to
sl@0
   171
	// deal with requests.
sl@0
   172
	RThread::Rendezvous(KErrNone);
sl@0
   173
sl@0
   174
	// And start fielding requests from client(s).
sl@0
   175
	CActiveScheduler::Start();
sl@0
   176
sl@0
   177
	// Tidy up...
sl@0
   178
	CleanupStack::PopAndDestroy(2, sched);
sl@0
   179
sl@0
   180
	DP0_RET(KErrNone, "error = %d");
sl@0
   181
	}
sl@0
   182
sl@0
   183
/**
sl@0
   184
Create the thread that will act as the server.
sl@0
   185
This function is exported from the DLL and called by the client.
sl@0
   186
sl@0
   187
Note that a server can also be implemented as a separate
sl@0
   188
executable (i.e. as a separate process).
sl@0
   189
*/
sl@0
   190
TInt CMMRCServer::ThreadFunction(TAny* aStarted)
sl@0
   191
	{
sl@0
   192
	DP_STATIC_CONTEXT(----> CMMRCServer::ThreadFunction *CD1*, CtxDevSound, DPLOCAL);
sl@0
   193
	DP_IN();
sl@0
   194
sl@0
   195
	// get clean-up stack
sl@0
   196
	CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0
   197
	if (cleanup == NULL)
sl@0
   198
		{
sl@0
   199
		CMMRCServer::PanicServer(KErrNoMemory);
sl@0
   200
		}
sl@0
   201
	
sl@0
   202
	TRAPD( err, ThreadFunctionL(aStarted) );
sl@0
   203
sl@0
   204
	delete cleanup; 
sl@0
   205
sl@0
   206
	DP0_RET(err, "error = %d");
sl@0
   207
	}
sl@0
   208
sl@0
   209
/**
sl@0
   210
Create the thread that will act as the server.
sl@0
   211
This function is exported from the DLL and called by the client.
sl@0
   212
sl@0
   213
Note that a server can also be implemented as a separate
sl@0
   214
executable (i.e. as a separate process).
sl@0
   215
*/
sl@0
   216
EXPORT_C TInt StartMMRCServer(RThread& aServerThread)
sl@0
   217
	{
sl@0
   218
	TInt res = KErrNone;
sl@0
   219
	
sl@0
   220
	// Create the server, if one with this name does not already exist.
sl@0
   221
	TFindServer findCountServer(KMMRCServerName);
sl@0
   222
	TFullName   name;
sl@0
   223
	
sl@0
   224
	// Need to check that the server exists.
sl@0
   225
	if ( findCountServer.Next(name) != KErrNone )
sl@0
   226
		{
sl@0
   227
		  // Create the thread for the server.
sl@0
   228
		res = aServerThread.Create(KMMRCServerName,
sl@0
   229
			CMMRCServer::ThreadFunction,
sl@0
   230
			KMMRCServerStackSize,
sl@0
   231
			KMMRCServerInitHeapSize,
sl@0
   232
			KMMRCServerMaxHeapSize,
sl@0
   233
			NULL
sl@0
   234
			);
sl@0
   235
			
sl@0
   236
		// The thread has been created OK so get it started - however
sl@0
   237
		// we need to make sure that it has started before we continue.
sl@0
   238
		if (res==KErrNone)
sl@0
   239
			{
sl@0
   240
			TRequestStatus rendezvousStatus;
sl@0
   241
			
sl@0
   242
			aServerThread.SetPriority(EPriorityNormal);
sl@0
   243
			aServerThread.Rendezvous(rendezvousStatus);
sl@0
   244
			aServerThread.Resume();
sl@0
   245
			User::WaitForRequest(rendezvousStatus);
sl@0
   246
			}
sl@0
   247
			
sl@0
   248
		  // The thread has not been created - clearly there's been a problem.
sl@0
   249
		else
sl@0
   250
			{
sl@0
   251
			aServerThread.Close();
sl@0
   252
			}
sl@0
   253
		}	
sl@0
   254
	return res;
sl@0
   255
	}
sl@0
   256
sl@0
   257
//EOF