usbmgmt/usbmgrtest/ObexClassController/ObexUsbClassController/ClassControllerServerSession/src/classContServerSession.cpp
changeset 0 c9bc50fca66e
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32def.h>
       
    19 #include <e32debug.h> 
       
    20 #include <obexserver.h>
       
    21 #include <obex.h>
       
    22 
       
    23 #include "../../public/clientServerShared.h"
       
    24 #include "classContServer.h"
       
    25 #include "classContServerSession.h"
       
    26 #include "obexInitiator.h"
       
    27 
       
    28 
       
    29 
       
    30 /**
       
    31  * Creates a new CSession2 derived object
       
    32  */
       
    33 CClassContServerSession* CClassContServerSession::NewL(CClassContServer& aServer)
       
    34 	{
       
    35 	CClassContServerSession* s = new(ELeave) CClassContServerSession(aServer);
       
    36 	CleanupStack::PushL(s);
       
    37 	s->ConstructL();
       
    38 	CleanupStack::Pop();
       
    39 	return s;
       
    40 	}
       
    41 
       
    42 	
       
    43 /**
       
    44  * Desctructor, delete the CObexInitiator object and set to NULL
       
    45  * to avaiod dereferencing freed memory
       
    46  */	
       
    47 CClassContServerSession::~CClassContServerSession()
       
    48 	{
       
    49 
       
    50 	delete iObexInitiator;
       
    51 	iObexInitiator = NULL;
       
    52 	// tell server im gonna die
       
    53 	iServer.SessionRemoved();
       
    54 	}
       
    55 
       
    56 	
       
    57 /**
       
    58  * Constructor, CServer2 object is passed
       
    59  */
       
    60 CClassContServerSession::CClassContServerSession(CClassContServer& aServer) :
       
    61 	iServer(aServer)
       
    62 	{	
       
    63 	}
       
    64 
       
    65 
       
    66 /**
       
    67  * 2nd phase constructor, new CObexIntiiator object is created under a Trap harness
       
    68  * this allows for RMessage2 to complete with the appropriate error code before leaving.
       
    69  */	
       
    70 void CClassContServerSession::ConstructL()
       
    71 	{
       
    72 	iObexInitiator = CObexInitiator::NewL(); // Create new CObexServer object
       
    73 	}
       
    74 
       
    75 
       
    76 /**
       
    77  * This is the function that deals with an incoming request from 
       
    78  * the client and then routes to the necessary function call.
       
    79  */
       
    80 void CClassContServerSession::ServiceL(const RMessage2& aMessage)
       
    81 	{
       
    82 	TRAPD(err, ForwardMessageL(aMessage));
       
    83 	if (!iBadMessage)
       
    84 		aMessage.Complete(err);
       
    85 	}
       
    86 
       
    87 /**
       
    88  * This is the function that maps the message from the client to
       
    89  * the appropriate call onto the OBEX server.
       
    90  */
       
    91 void CClassContServerSession::ForwardMessageL(const RMessage2& aMessage)
       
    92 	{
       
    93 	switch(aMessage.Function())
       
    94 		{
       
    95 		case EStartClassContServer:
       
    96 			StartServiceL();
       
    97 			break;
       
    98 		case EStopClassContServer:
       
    99 			StopService();
       
   100 			break;
       
   101 		default:
       
   102 			iBadMessage = ETrue;
       
   103 			aMessage.Panic(KClientPanicCategory, EClientPanicBadMessage);
       
   104 			break;
       
   105 		}
       
   106 	}
       
   107 
       
   108 /**
       
   109  * This is the function that is called by the server when the client has
       
   110  * requested to start the Obex Server, CObexInitiator::StartObexServerL 
       
   111  * is responsible for calling CObexServer::Start, implementing an Obex Server.		
       
   112  */	
       
   113 void CClassContServerSession::StartServiceL()
       
   114 	{
       
   115 	iObexInitiator->StartObexServerL(); // Call Start on the Obex Server
       
   116 	}
       
   117 
       
   118 
       
   119 /**
       
   120  * This is the function called by the server when the client has requested
       
   121  * to stop the Obex server, CObexInitiator::StopObexServer is esponsible
       
   122  * for calling CObexServer::Stop.
       
   123  *
       
   124  */
       
   125 void CClassContServerSession::StopService()
       
   126 	{
       
   127 	iObexInitiator->StopObexServer(); //Stop the Obex server
       
   128 	}
       
   129 
       
   130 
       
   131 
       
   132 
       
   133     
       
   134   
       
   135