os/mm/mmresourcemgmt/mmresctrl/src/mmrcserver/mmrcserver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmresourcemgmt/mmresctrl/src/mmrcserver/mmrcserver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,257 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "mmrcserver.h"
    1.20 +#include "mmrcserversession.h"
    1.21 +#include "mmrcservercontroller.h"
    1.22 +#include "mmrcserverstart.h"
    1.23 +#include <a3f/a3ffourcclookup.h>
    1.24 +#include <a3f/a3f_trace_utils.h>
    1.25 +
    1.26 +
    1.27 +//------------------------------------------------------------------------------------
    1.28 +//
    1.29 +//------------------------------------------------------------------------------------
    1.30 +/**
    1.31 + * Constructor
    1.32 + */
    1.33 +CMMRCServer::CMMRCServer()
    1.34 +:  CServer2(EPriorityStandard)
    1.35 +	{ 
    1.36 +	TRACE_CREATE();
    1.37 +	DP_CONTEXT(----> CMMRCServer::CMMRCServer *CD1*, CtxDevSound, DPLOCAL);
    1.38 +	DP_IN();
    1.39 +	
    1.40 +	Cancel();
    1.41 +	
    1.42 +	DP_OUT();
    1.43 +	}
    1.44 +
    1.45 +/**
    1.46 + * Destructor.
    1.47 + */
    1.48 +CMMRCServer::~CMMRCServer()
    1.49 +	{
    1.50 +	DP_CONTEXT(----> CMMRCServer::~CMMRCServer *CD1*, CtxDevSound, DPLOCAL);
    1.51 +	DP_IN();
    1.52 +	
    1.53 +	if(iMMRCServerController)
    1.54 +		{
    1.55 +		delete iMMRCServerController;
    1.56 +		}
    1.57 +	delete iFourCCConvertor;
    1.58 +	DP_OUT();
    1.59 +	}
    1.60 +
    1.61 +//------------------------------------------------------------------------------------
    1.62 +//
    1.63 +//------------------------------------------------------------------------------------
    1.64 +/**
    1.65 + * Constructs, and returns a pointer to, a new CMMRCServer object.
    1.66 + * Leaves on failure.
    1.67 + * @return CMMRCServer* A pointer to newly created utlitly object.
    1.68 + */		
    1.69 +CMMRCServer* CMMRCServer::NewL()
    1.70 +	{
    1.71 +	DP_STATIC_CONTEXT(----> CMMRCServer::NewL *CD1*, CtxDevSound, DPLOCAL);
    1.72 +	DP_IN();
    1.73 +	
    1.74 +	CMMRCServer* self = NewLC();
    1.75 +	CleanupStack::Pop(self);
    1.76 +	
    1.77 +	DP0_RET(self, "0x%x");
    1.78 +	} 
    1.79 +
    1.80 +/**
    1.81 + * Constructs, leaves object on the cleanup stack, and returns a pointer
    1.82 + * to, a new CMMRCServer object.
    1.83 + * Leaves on failure.
    1.84 + * @return CMMRCServer* A pointer to newly created utlitly object.
    1.85 + */		
    1.86 +CMMRCServer* CMMRCServer::NewLC()
    1.87 +	{
    1.88 +	DP_STATIC_CONTEXT(----> CMMRCServer::Open *CD1*, CtxDevSound, DPLOCAL);
    1.89 +	DP_IN();
    1.90 +	
    1.91 +	CMMRCServer* self = new(ELeave) CMMRCServer;
    1.92 +	CleanupStack::PushL(self);
    1.93 +	self->ConstructL();
    1.94 +	
    1.95 +	DP0_RET(self, "self = 0x%x");
    1.96 +	}
    1.97 +
    1.98 +/**
    1.99 + 	CMMRCServer::ConstructL
   1.100 + 	Symbian 2nd phase constructor can leave.
   1.101 + */
   1.102 +void CMMRCServer::ConstructL()
   1.103 +	{
   1.104 +	DP_CONTEXT(----> CMMRCServer::ConstructL *CD1*, CtxDevSound, DPLOCAL);
   1.105 +	DP_IN();
   1.106 +	
   1.107 +	iMMRCServerController = CMMRCServerController::NewL();
   1.108 +	
   1.109 +	iFourCCConvertor = CFourCCConvertor::NewL();
   1.110 +	DP_OUT();
   1.111 +	}
   1.112 +
   1.113 +//------------------------------------------------------------------------------------
   1.114 +//
   1.115 +//------------------------------------------------------------------------------------
   1.116 +/**
   1.117 + * From CServer2. Creates a server-side client session object.
   1.118 + * Creates a new session.  Only one session may be created with the ControllerProxyServer.
   1.119 + * This function may leave with one of the system-wide error codes.
   1.120 + * @param const TVersion& aVersion	The version number of the session.
   1.121 + * @param const RMessage2& aMessage
   1.122 + * @return A pointer to the new session.
   1.123 + */
   1.124 +CSession2* CMMRCServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
   1.125 +	{
   1.126 +	DP_CONTEXT(----> CMMRCServer::NewSessionL *CD1*, CtxDevSound, DPLOCAL);
   1.127 +	DP_IN();
   1.128 +	
   1.129 +	TVersion version(KMMRCServerVersion,KMMRCServerMinorVersionNumber,KMMRCServerBuildVersionNumber);
   1.130 +	if(!User::QueryVersionSupported(version, aVersion))
   1.131 +		{
   1.132 +		User::Leave(KErrNotSupported);	   
   1.133 +		}
   1.134 +	CMMRCServerSession* mmrcSession = CMMRCServerSession::NewL(*iMMRCServerController, *iFourCCConvertor);
   1.135 +	
   1.136 +	DP0_RET(mmrcSession, "mmrcSession = 0x%x");
   1.137 +	}
   1.138 +
   1.139 +/**
   1.140 +A utility function to panic the server.
   1.141 +*/
   1.142 +void CMMRCServer::PanicServer(TInt aPanic)
   1.143 +	{
   1.144 +	_LIT(KMMRCServerPanic,"MMRC Server panic");
   1.145 +	User::Panic(KMMRCServerPanic, aPanic);
   1.146 +	}
   1.147 +
   1.148 +//------------------------------------------------------------------------------------
   1.149 +//
   1.150 +//------------------------------------------------------------------------------------
   1.151 +TInt CMMRCServer::ThreadFunctionL(TAny* /**aStarted*/)
   1.152 +	{
   1.153 +	DP_STATIC_CONTEXT(----> CMMRCServer::ThreadFunctionL *CD1*, CtxDevSound, DPLOCAL);
   1.154 +	DP_IN();
   1.155 +	
   1.156 +	// create an active scheduler and server
   1.157 +	CActiveScheduler* sched = new (ELeave) CActiveScheduler;
   1.158 +	CleanupStack::PushL(sched);
   1.159 +	
   1.160 +	//Install the active scheduler
   1.161 +	CActiveScheduler::Install(sched);
   1.162 +	
   1.163 +	CMMRCServer *server = CMMRCServer::NewLC();
   1.164 +		
   1.165 +
   1.166 +	// Start the server
   1.167 +	TInt err = server->Start(KMMRCServerName);
   1.168 +	if (err != KErrNone)
   1.169 +		{
   1.170 +		CMMRCServer::PanicServer(KErrNoMemory);
   1.171 +		}
   1.172 +
   1.173 +	// Let everyone know that we are ready to
   1.174 +	// deal with requests.
   1.175 +	RThread::Rendezvous(KErrNone);
   1.176 +
   1.177 +	// And start fielding requests from client(s).
   1.178 +	CActiveScheduler::Start();
   1.179 +
   1.180 +	// Tidy up...
   1.181 +	CleanupStack::PopAndDestroy(2, sched);
   1.182 +
   1.183 +	DP0_RET(KErrNone, "error = %d");
   1.184 +	}
   1.185 +
   1.186 +/**
   1.187 +Create the thread that will act as the server.
   1.188 +This function is exported from the DLL and called by the client.
   1.189 +
   1.190 +Note that a server can also be implemented as a separate
   1.191 +executable (i.e. as a separate process).
   1.192 +*/
   1.193 +TInt CMMRCServer::ThreadFunction(TAny* aStarted)
   1.194 +	{
   1.195 +	DP_STATIC_CONTEXT(----> CMMRCServer::ThreadFunction *CD1*, CtxDevSound, DPLOCAL);
   1.196 +	DP_IN();
   1.197 +
   1.198 +	// get clean-up stack
   1.199 +	CTrapCleanup* cleanup=CTrapCleanup::New();
   1.200 +	if (cleanup == NULL)
   1.201 +		{
   1.202 +		CMMRCServer::PanicServer(KErrNoMemory);
   1.203 +		}
   1.204 +	
   1.205 +	TRAPD( err, ThreadFunctionL(aStarted) );
   1.206 +
   1.207 +	delete cleanup; 
   1.208 +
   1.209 +	DP0_RET(err, "error = %d");
   1.210 +	}
   1.211 +
   1.212 +/**
   1.213 +Create the thread that will act as the server.
   1.214 +This function is exported from the DLL and called by the client.
   1.215 +
   1.216 +Note that a server can also be implemented as a separate
   1.217 +executable (i.e. as a separate process).
   1.218 +*/
   1.219 +EXPORT_C TInt StartMMRCServer(RThread& aServerThread)
   1.220 +	{
   1.221 +	TInt res = KErrNone;
   1.222 +	
   1.223 +	// Create the server, if one with this name does not already exist.
   1.224 +	TFindServer findCountServer(KMMRCServerName);
   1.225 +	TFullName   name;
   1.226 +	
   1.227 +	// Need to check that the server exists.
   1.228 +	if ( findCountServer.Next(name) != KErrNone )
   1.229 +		{
   1.230 +		  // Create the thread for the server.
   1.231 +		res = aServerThread.Create(KMMRCServerName,
   1.232 +			CMMRCServer::ThreadFunction,
   1.233 +			KMMRCServerStackSize,
   1.234 +			KMMRCServerInitHeapSize,
   1.235 +			KMMRCServerMaxHeapSize,
   1.236 +			NULL
   1.237 +			);
   1.238 +			
   1.239 +		// The thread has been created OK so get it started - however
   1.240 +		// we need to make sure that it has started before we continue.
   1.241 +		if (res==KErrNone)
   1.242 +			{
   1.243 +			TRequestStatus rendezvousStatus;
   1.244 +			
   1.245 +			aServerThread.SetPriority(EPriorityNormal);
   1.246 +			aServerThread.Rendezvous(rendezvousStatus);
   1.247 +			aServerThread.Resume();
   1.248 +			User::WaitForRequest(rendezvousStatus);
   1.249 +			}
   1.250 +			
   1.251 +		  // The thread has not been created - clearly there's been a problem.
   1.252 +		else
   1.253 +			{
   1.254 +			aServerThread.Close();
   1.255 +			}
   1.256 +		}	
   1.257 +	return res;
   1.258 +	}
   1.259 +
   1.260 +//EOF