usbmgmt/usbmgrtest/ObexClassController/ObexUsbClassController/ClassControllerServerSession/src/classContServer.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 
       
    19 
       
    20 #include <e32debug.h>
       
    21 
       
    22 #include "../../public/clientServerShared.h"
       
    23 #include "classContServer.h"
       
    24 #include "classContServerSession.h"
       
    25 
       
    26 /**
       
    27  * Creates a new instance of CClassContServer, a CServer2
       
    28  * derived class.
       
    29  */
       
    30 CClassContServer* CClassContServer::NewLC()
       
    31 	{
       
    32 	CClassContServer* s = new(ELeave) CClassContServer;
       
    33 	CleanupStack::PushL(s);
       
    34 	s->ConstructL();
       
    35 	s->StartL(KServerName);
       
    36 	return s;	
       
    37 	}
       
    38 /**
       
    39  * Destructor
       
    40  */
       
    41 CClassContServer::~CClassContServer()
       
    42 	{
       
    43 	delete iShutdownTimer;
       
    44 	}
       
    45 
       
    46 /**
       
    47  * Constructor
       
    48  */	
       
    49 CClassContServer::CClassContServer() : CServer2(EPriorityStandard)
       
    50 	{
       
    51 	}
       
    52 
       
    53 
       
    54 /**
       
    55  * 2nd phase construction. This exists to create a new timer and start a 5 second 
       
    56  * timing period.
       
    57  */	
       
    58 void CClassContServer::ConstructL()
       
    59 	{
       
    60 	iShutdownTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    61 	StartShutdownTimer();	
       
    62 	}
       
    63 
       
    64 
       
    65 /**
       
    66  * This function is called by the session object when a session has been terminated.
       
    67  * It creates a new timer of 5 seconds, this time the 5 seconds will run to 
       
    68  * completion and the timers RunL function will be called, stopping the active scheduler.
       
    69  */	
       
    70 
       
    71 void CClassContServer::SessionRemoved()
       
    72 	{
       
    73 	iSession = NULL;
       
    74 	StartShutdownTimer();
       
    75 	}
       
    76 
       
    77 
       
    78 /**
       
    79  * Function to instansiate a new CSession2 object, function leaves if a session
       
    80  * already exists. After a session has been created the CServerTimer object
       
    81  * gets cancelled.
       
    82  */	
       
    83 CSession2* CClassContServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& aMessage) const
       
    84 	{
       
    85 	// before we continue check the secure ID of the send of aMessage
       
    86 	if (aMessage.SecureId() != KUsbSvrSecureId)
       
    87 		User::Leave(KErrPermissionDenied);
       
    88 
       
    89 	CClassContServer* ncthis = const_cast<CClassContServer*>(this);
       
    90 	// Only allow one session
       
    91 	if (iSession)
       
    92 		User::Leave(KErrAlreadyExists);	
       
    93 	ncthis->iSession = CClassContServerSession::NewL(*ncthis);
       
    94 	ncthis->CancelShutdownTimer();
       
    95 	return iSession;
       
    96 	}
       
    97 
       
    98 
       
    99 
       
   100 	
       
   101 void CClassContServer::StartShutdownTimer()
       
   102 	{
       
   103 	if ( !iShutdownTimer->IsActive() )
       
   104 		{
       
   105 		// Start the timer, delay events for 5 seconds, subsequent
       
   106 		// firings will not occur.
       
   107 		iShutdownTimer->Start(KShutdownDelay, KShutdownInterval, 
       
   108 								TCallBack(CClassContServer::ShutdownTimerFired, this));
       
   109 		}	
       
   110 	}
       
   111 	
       
   112 void CClassContServer::CancelShutdownTimer()
       
   113 	{
       
   114 	iShutdownTimer->Cancel();
       
   115 	}
       
   116 	
       
   117 TInt CClassContServer::ShutdownTimerFired(TAny* /*aThis*/)
       
   118 	{
       
   119 	CActiveScheduler::Stop();
       
   120 	return KErrNone;
       
   121 	}