commsfwsupport/commselements/serverden/src/sd_server.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2008-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 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <e32base.h>
       
    22 #include "sd_log.h"
       
    23 #include "sd_std.h"
       
    24 #include "sd_roles.h"
       
    25 
       
    26 using namespace Den;
       
    27 using namespace CommsFW;
       
    28 
       
    29 EXPORT_C CCommonServer::CCommonServer(TInt aPriority, CCommonWorkerThread* aOwnerThread, const TPolicy& aPolicy,TServerType aType, const TDesC& aName)
       
    30 :	CPolicyServer(aPriority, aPolicy, aType), iOwnerThread(aOwnerThread),
       
    31 	iServerName(aName)
       
    32 	{
       
    33 	__DECLARE_NAME(_S("CCommonServer"));
       
    34 	}
       
    35 
       
    36 EXPORT_C CCommonServer::~CCommonServer()
       
    37 //
       
    38 // Destructor.
       
    39 //
       
    40 	{
       
    41 	COMMONLOG((WorkerId(), KECommonServerTag, _L8("CCommonServer %08x:\t~CCommonServer()"), this));
       
    42 	/* This part actually duplicated that of the CServer destructor, but we'd like a bit of logging
       
    43 	first if we delete sessions, in contrast to CServer which does it silently */
       
    44 	iSessionIter.SetToFirst();
       
    45 
       
    46 #ifdef SYMBIAN_TRACE_ENABLE
       
    47 	CSession2* pSession;
       
    48 	while((pSession=iSessionIter++)!=NULL)
       
    49 		{
       
    50 		COMMONLOG((WorkerId(), KECommonServerTag, _L8("CCommonServer %08x:\t~CCommonServer(): Session(%08x): Remaining. BAD."), this, pSession));
       
    51 		}
       
    52 #endif
       
    53 	}
       
    54 
       
    55 EXPORT_C TBool CCommonServer::CanShutdown()
       
    56 	{
       
    57 #ifdef SYMBIAN_TRACE_ENABLE
       
    58 	SessionIterator().SetToFirst();
       
    59 	CSession2* sess;
       
    60 	while((sess = iSessionIter++) != NULL)
       
    61 		{
       
    62 		COMMONLOG((WorkerId(), KECommonBootingTag, _L8("CCommonDealer::CanShutdown() - session(%08x) remains, containing:"), sess));
       
    63 		CWorkerSession* workerSess = static_cast<CWorkerSession*>(sess);
       
    64 
       
    65 		workerSess->SubSessions().Lock();
       
    66 		workerSess->ProcessSubSessions(TWorkerThreadPublicInfo::ENullWorkerId, CWorkerSession::LogSubSession, NULL);
       
    67 		workerSess->SubSessions().Unlock();
       
    68 		}
       
    69 #endif
       
    70 	return iNumSessions <= 0;
       
    71 	}
       
    72 
       
    73 EXPORT_C CSession2* CCommonServer::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const
       
    74 	{
       
    75 	if(WorkerThread().PitBoss().IsShuttingDown() || WorkerThread().ShuttingDown())
       
    76 		{
       
    77 	    User::Leave(KErrServerBusy);
       
    78 		}
       
    79 	TBool r=User::QueryVersionSupported(CurrentVersion(), aVersion);
       
    80 	if (r==EFalse)
       
    81 		{
       
    82 		User::Leave(KErrNotSupported);
       
    83 		}
       
    84 
       
    85 	/* Get PID and UID to check for eligibility id this is WorkerDealer and
       
    86 	to store in new session. */
       
    87 	RProcess process;
       
    88 	RThread thread;
       
    89 	User::LeaveIfError(aMessage.Client(thread));
       
    90 	TInt err=thread.Process(process);
       
    91 	thread.Close();
       
    92 	User::LeaveIfError(err);
       
    93 	TProcessId pid = process.Id();
       
    94 	TUidType uid = process.Type();
       
    95 	process.Close();
       
    96 
       
    97 	// Only eligible clients can create sessions on workerdealers, so if workerthread has a workerdealer
       
    98 	// make sure the client is eligible.
       
    99 	if(!WorkerThread().IsMainThread() && (WorkerThread().WorkerDealer() && !WorkerThread().WorkerDealer()->IsEligible(pid)))
       
   100 		{
       
   101 		User::Leave(KErrPermissionDenied);
       
   102 		}
       
   103 
       
   104 	CSession2* session = DoNewSessionL(pid, uid);
       
   105 	iNumSessions++;
       
   106 	COMMONLOG((WorkerId(), KECommonBootingTag, _L8("CCommonServer %08x:\tNewSessionL() iNumSessions=%d"), this, iNumSessions));
       
   107 
       
   108 	return session;
       
   109 	}
       
   110 
       
   111