networkprotocolmodules/networkprotocolmodule/LbsNetSim/src/lbsnetsimsession.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2006-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
       
    17 #include "lbsnetsimserver.h"
       
    18 #include "lbsnetsimhandlerretriever.h"
       
    19 #include "lbsnetsimsessionhandler.h"
       
    20 #include "lbsnetsimsession.h"
       
    21 
       
    22 /**
       
    23 */
       
    24 CLbsNetSimSession::CLbsNetSimSession(MLbsNetSimHandlerRetriever* aRetriever) :
       
    25 	iHandler(NULL), iRetriever(aRetriever)
       
    26 	{
       
    27 	}
       
    28 
       
    29 
       
    30 /**
       
    31 */
       
    32 CLbsNetSimSession::~CLbsNetSimSession()
       
    33 	{
       
    34 	}
       
    35 
       
    36 /**
       
    37 */
       
    38 CLbsNetSimServer* CLbsNetSimSession::Server()
       
    39 	{
       
    40 	return static_cast<CLbsNetSimServer*>(const_cast<CServer2*>(CSession2::Server()));
       
    41 	}
       
    42 
       
    43 /**
       
    44 */
       
    45 void CLbsNetSimSession::ServiceL(const RMessage2& aMessage)
       
    46 	{
       
    47 	switch (aMessage.Function())
       
    48 		{
       
    49 		case EInitialise:
       
    50 			{
       
    51 			if (aMessage.Int0() == ETestHandler)
       
    52 				{
       
    53 #ifdef _DEBUG
       
    54 				_LIT(KTestName, "__TEST_HANDLER__");
       
    55 				iWhich = KTestName;
       
    56 #endif			
       
    57 				RetrieveTestHandler();
       
    58 				}
       
    59 			else if (aMessage.Int0() == EGatewayHandler)
       
    60 				{
       
    61 #ifdef _DEBUG
       
    62 				_LIT(KGatewayName, "__GATEWAY_HANDLER__");
       
    63 				iWhich = KGatewayName;
       
    64 #endif			
       
    65 				RetrieveGatewayHandler();
       
    66 				}
       
    67 			else
       
    68 				{
       
    69 				User::Leave(KErrNotSupported);
       
    70 				}
       
    71 				
       
    72 			// Complete the message
       
    73 			aMessage.Complete(KErrNone);
       
    74 				
       
    75 			break;
       
    76 			} // case
       
    77 		default:
       
    78 			{
       
    79 			ForwardToHandlerL(aMessage);
       
    80 			}
       
    81 		} // switch
       
    82 	}
       
    83 	
       
    84 void CLbsNetSimSession::Disconnect(const RMessage2& aMessage)
       
    85 	{
       
    86 	iHandler->Disconnected();
       
    87 	
       
    88 	iHandler = NULL;
       
    89 	
       
    90 	Server()->DecClientCount();
       
    91 	
       
    92 	CSession2::Disconnect(aMessage);
       
    93 	}
       
    94 	
       
    95 //
       
    96 // Private methods
       
    97 
       
    98 /**
       
    99 */
       
   100 void CLbsNetSimSession::RetrieveTestHandler()
       
   101 	{
       
   102 	iHandler = iRetriever->GetTestHandler();
       
   103 	iHandler->Connected();
       
   104 	}
       
   105 
       
   106 
       
   107 /**
       
   108 */
       
   109 void CLbsNetSimSession::RetrieveGatewayHandler()
       
   110 	{
       
   111 	iHandler = iRetriever->GetGatewayHandler();
       
   112 	iHandler->Connected();
       
   113 	}
       
   114 
       
   115 
       
   116 /**
       
   117 */
       
   118 void CLbsNetSimSession::ForwardToHandlerL(const RMessage2& aMessage)
       
   119 	{
       
   120 	ASSERT(iHandler != NULL);
       
   121 	
       
   122 	if (iHandler == NULL)
       
   123 		{
       
   124 		User::Leave(KErrNotReady);
       
   125 		}
       
   126 		
       
   127 	iHandler->ServiceL(aMessage);
       
   128 	}