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