dosservices/dosserver/src/dossession.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002 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 *    Implementation for the CDosSessionclass
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32svr.h>
       
    21 #include "dossession.h"
       
    22 #include "dosfactorybase.h"
       
    23 #include "dosextensionbase.h"
       
    24 #include "doseventrcvservice.h"
       
    25 #include "doseventsndservice.h"
       
    26 #include "doseventmanager.h"
       
    27 #include "dosshareddatabase.h"
       
    28 
       
    29 #include "dos_debug.h"
       
    30 
       
    31 //
       
    32 // ---------------------------------------------------------
       
    33 // CDosSession Constructor
       
    34 // ---------------------------------------------------------
       
    35 //  
       
    36 
       
    37 CDosSession::CDosSession()
       
    38 {
       
    39 	iServiceCon = NULL;
       
    40 	iServices = NULL;
       
    41 }
       
    42 
       
    43 //
       
    44 // ---------------------------------------------------------
       
    45 // CDosSession Destructor
       
    46 // ---------------------------------------------------------
       
    47 //  
       
    48 
       
    49 CDosSession::~CDosSession()
       
    50 {
       
    51 	COM_TRACE_( "CDosSession::~CDosSession()" );
       
    52 
       
    53 	if(iServices != NULL)
       
    54 	{
       
    55 		COM_TRACE_( "[DOSSERVER]\t Deleting services..." );
       
    56 		COM_TRACE_1( "[DOSSERVER]\t iServices : %d",iServices);
       
    57 		COM_TRACE_1( "[DOSSERVER]\t iServices count: %d", iServices->Count() );
       
    58 		delete iServices;
       
    59 	}
       
    60 
       
    61 	COM_TRACE_( "[DOSSERVER]\t Callback dropsession" );
       
    62 
       
    63 	Server().DropSession();
       
    64 
       
    65 	if(iServiceCon != NULL)
       
    66 	{
       
    67 		COM_TRACE_( "[DOSSERVER]\t iServiceCon - remove callback" );
       
    68 		COM_TRACE_1( "[DOSSERVER]\t iServiceCon : %d", iServiceCon );
       
    69 		COM_TRACE_1( "[DOSSERVER]\t iServiceCon count: %d", iServiceCon->Count() );
       
    70 		Server().ContainerIx()->Remove(iServiceCon);
       
    71 	}
       
    72 
       
    73 	COM_TRACE_( "CDosSession::~CDosSession() - end" );
       
    74 }
       
    75 
       
    76 
       
    77 //
       
    78 // ---------------------------------------------------------
       
    79 // CDosSession::CreateL
       
    80 //
       
    81 // 2nd phase construct for sessions - called by the CServer 
       
    82 // framework
       
    83 // ---------------------------------------------------------
       
    84 //  
       
    85  
       
    86 void CDosSession::CreateL()
       
    87 {
       
    88 	iServiceCon=Server().ContainerIx()->CreateL();
       
    89 	iServices = CObjectIx::NewL();
       
    90 	Server().AddSession();
       
    91 }
       
    92 
       
    93 //
       
    94 // ---------------------------------------------------------
       
    95 // CDosSession::ServiceL
       
    96 //
       
    97 // Handle a client request.
       
    98 // Leaving is handled by CServer::RunError() which reports 
       
    99 // the error code to the client.
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 void CDosSession::ServiceL(const RMessage2& aMessage)
       
   103 {
       
   104 	COM_TRACE_( "[DOSSERVER]\t CDosSession::ServiceL()" );
       
   105 	TInt err(KErrNone);
       
   106 	TInt retVal(KErrNone);
       
   107 
       
   108 	if((aMessage.Int2() & KAutoComplete) ||
       
   109 	 aMessage.Function() == EDosCloseSubSession ||
       
   110 	 aMessage.Function() == EDosEventFiring )
       
   111 	{
       
   112 		// Trap possible DSY-plugin leaves here and complete the message with
       
   113 		// the leave code.
       
   114 		TRAP(err, retVal = DispatchMessageL(aMessage));
       
   115 		if (err == KErrNone)
       
   116 		{
       
   117 			aMessage.Complete(retVal);
       
   118 		}
       
   119 		else
       
   120 		{
       
   121 			COM_TRACE_1( "[DOSSERVER]\t ERROR: Leave in DSY impl. (autocomplete set) (%d)", err);
       
   122 			aMessage.Complete(err);
       
   123 		}
       
   124 	}
       
   125 	else
       
   126 	{
       
   127 		//Requests with AutoComplete flag unset will be completed by themselves
       
   128 		COM_TRACE_( "[DOSSERVER]\t AutoComplete flag unset" );
       
   129 
       
   130 		// Trap possible DSY-plugin leaves here and complete the message with 
       
   131 		// the leave code.
       
   132 		// Since this call is asynchronous only leaves for the call to DSY 
       
   133 		// callback-function can be trapped here.
       
   134 		// After that callback function returns the possible leaves will be 
       
   135 		// trapped by active scheduler and error cases get eventually handled
       
   136 		// at CDosServer::RunError(). 
       
   137 		TRAP(err, DispatchMessageL(aMessage));		
       
   138 		if (err != KErrNone)
       
   139 		{
       
   140 			COM_TRACE_1( "[DOSSERVER]\t ERROR: Leave in DSY impl. (%d)", err );
       
   141 			aMessage.Complete(err);
       
   142 		}
       
   143 	}
       
   144 }
       
   145 
       
   146 //
       
   147 // ---------------------------------------------------------
       
   148 // CDosSession::DispatchMessageL
       
   149 // ---------------------------------------------------------
       
   150 //  
       
   151 TInt CDosSession::DispatchMessageL(const RMessage2& aMessage)
       
   152 {
       
   153 	COM_TRACE_( "[DOSSERVER]\t CDosSession::DispatchMessageL()" );
       
   154 
       
   155 	CDosService* dosService=NULL;
       
   156 
       
   157 	switch (aMessage.Function())
       
   158 		{
       
   159 		case EDosCreateExtensionSubSession:
       
   160 			COM_TRACE_( "[DOSSERVER]\t EDosCreateExtensionSubSession" );
       
   161 			dosService = Server().DosFactory()->NewExtensionServiceL();
       
   162 			break;
       
   163 
       
   164 		case EDosCreateEventRcvSubSession:
       
   165 			COM_TRACE_( "[DOSSERVER]\t EDosCreateEventRcvSubSession" );
       
   166 			dosService = CDosEventRcvService::NewL(Server().EventManager());
       
   167 			break;
       
   168 
       
   169 		case EDosCreateEventSndSubSession:
       
   170 			COM_TRACE_( "[DOSSERVER]\t EDosCreateEventSndSubSession" );
       
   171 			dosService = CDosEventSndService::NewL(Server().EventManager());
       
   172 			break;
       
   173 		
       
   174 		case EDosCloseSubSession:
       
   175 			COM_TRACE_( "[DOSSERVER]\t EDosCloseSubSession" );
       
   176 			CloseSubSession(aMessage);
       
   177 			return KErrNone;
       
   178 
       
   179 		case EServerShutdown: 
       
   180 			COM_TRACE_( "[DOSSERVER]\t EServerShutdown" );
       
   181 			CActiveScheduler::Stop();
       
   182 			return KErrNone;
       
   183 		case EDosCreateSharedDataSubSession: 
       
   184 			COM_TRACE_( "[DOSSERVER]\t EDosCreateSharedDataSubSession" );
       
   185 			iSDCounter++;
       
   186 			COM_TRACE_1( "CDosSession::DispatchMessageL() calling CDosSharedDataBase::NewL(0x%x)", Server().iFileSystemNotifier );
       
   187 			COM_TRACE_1( "CDosSession::DispatchMessageL() iSDCounter = %d", iSDCounter);
       
   188 			dosService = CDosSharedDataBase::NewL(Server().iFileSystemNotifier);
       
   189 			break;
       
   190 		}
       
   191 
       
   192 	COM_TRACE_( "[DOSSERVER]\t dosService created, continuing..." );
       
   193 	
       
   194 	if(dosService)
       
   195 	{
       
   196 		CleanupStack::PushL(dosService);
       
   197 		SetupSubSessionL(aMessage,dosService);
       
   198 		CleanupStack::Pop();
       
   199 		return KErrNone;
       
   200 	}
       
   201 
       
   202 	dosService = ServiceFromHandle(aMessage.Int3());
       
   203 	if (dosService)
       
   204 	{
       
   205 		COM_TRACE_( "[DOSSERVER]\t Calling ExecuteMessageL..." );
       
   206 		return dosService->ExecuteMessageL(aMessage);
       
   207 	}
       
   208 
       
   209 	COM_TRACE_( "[DOSSERVER]\t DOSSESSION Planning to panic..." );
       
   210 	PanicClient(aMessage,EPanicBadHandle);
       
   211 	return KErrNone;
       
   212 }
       
   213 
       
   214 //
       
   215 // ---------------------------------------------------------
       
   216 // CDosSession::CloseSubSession
       
   217 // ---------------------------------------------------------
       
   218 //  
       
   219 
       
   220 void CDosSession::CloseSubSession(const RMessage2& aMessage)
       
   221 {
       
   222 	COM_TRACE_( "[DOSSERVER]\t CDosSession::CloseSubSession()" );
       
   223 
       
   224 	iServices->Remove(aMessage.Int3());
       
   225 }
       
   226 
       
   227 //
       
   228 // ---------------------------------------------------------
       
   229 // CDosSession::SetupSubSession
       
   230 // ---------------------------------------------------------
       
   231 //  
       
   232 void CDosSession::SetupSubSessionL(const RMessage2& aMessage,CDosService* aService)
       
   233 {
       
   234 	COM_TRACE_( "[DOSSERVER]\t CDosSession::SetupSubSessionL()" );
       
   235 
       
   236 	if(aService)
       
   237 	{
       
   238 		COM_TRACE_( "[DOSSERVER]\t CDosSession::SetupSubSessionL() - aService valid" );
       
   239 		iServiceCon->AddL(aService);
       
   240 		TInt handle=iServices->AddL(aService);
       
   241 		TPckg<TInt> handlePckg(handle);
       
   242 		TRAPD(res,aMessage.WriteL(3, handlePckg))
       
   243 		if (res!=KErrNone)
       
   244 		{
       
   245 			COM_TRACE_( "[DOSSERVER]\t CDosSession::SetupSubSessionL() - EPanicBadDescriptor" );
       
   246 
       
   247 			iServices->Remove(handle);
       
   248 			PanicClient(aMessage,EPanicBadDescriptor);
       
   249 		}
       
   250 		// Every Service has a reference to the Event Manager in case it wants to produce
       
   251 		// events
       
   252 		aService->iEventManager = Server().EventManager();
       
   253 	}
       
   254 	COM_TRACE_( "[DOSSERVER]\t CDosSession::SetupSubSessionL() completed" );
       
   255 }
       
   256 
       
   257