sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // SCH_SVR.CPP sl@0: // sl@0: // sl@0: sl@0: // User includes sl@0: #include "SSCH_STD.H" sl@0: #include "SchLogger.h" sl@0: #include "SCHMAN.H" sl@0: #include "CSCHCODE.H" sl@0: #include "SCHEXE.H" sl@0: #include "SchSSAMan.h" sl@0: sl@0: extern const BSUL::TClientMessageServerData KServerData; sl@0: sl@0: CSchServer* CSchServer::NewLC() sl@0: { sl@0: CSchServer* self=new(ELeave) CSchServer(EPriority); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: CSchServer::CSchServer(TInt aPriority) sl@0: : CServer2(aPriority) sl@0: { sl@0: } sl@0: sl@0: CSchServer::~CSchServer() sl@0: { sl@0: delete iTaskScheduler; sl@0: delete iSSAMgr; sl@0: sl@0: #ifdef __SCHLOGGING__ sl@0: delete iTheLog; sl@0: #endif sl@0: } sl@0: sl@0: void CSchServer::ConstructL() sl@0: { sl@0: #ifdef __SCHLOGGING__ sl@0: iTheLog = CSheduleServerLog::NewL(_L("SchSvr")); sl@0: Dll::SetTls(iTheLog); sl@0: #endif sl@0: sl@0: // Create server storage path sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: TInt err = fs.CreatePrivatePath(RFs::GetSystemDrive()); sl@0: sl@0: if(err != KErrNone && err != KErrAlreadyExists) sl@0: User::Leave(err); sl@0: sl@0: fs.Close(); sl@0: sl@0: iTaskScheduler = CTaskScheduler::NewL(); sl@0: sl@0: #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT sl@0: iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KSM2OSServicesDomain3); sl@0: #else sl@0: iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KBaseServicesDomain3); sl@0: #endif //SYMBIAN_SYSTEM_STATE_MANAGEMENT sl@0: sl@0: iSSAMgr->RegisterObserverL(iTaskScheduler); sl@0: iSSAMgr->InitialiseL(); sl@0: sl@0: //Initialise message framework sl@0: BSUL::CClientMessage::InitialiseFrameworkL(KServerData); sl@0: sl@0: StartL(KSchSvrName); sl@0: } sl@0: sl@0: CSession2* CSchServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const sl@0: // sl@0: // Create a new client for this server. sl@0: // sl@0: { sl@0: TVersion v(KESchSvrMajorVersionNumber,KESchSvrMinorVersionNumber,KESchSvrBuildVersionNumber); sl@0: TBool r=User::QueryVersionSupported(v,aVersion); sl@0: if (r==EFalse) sl@0: User::Leave(KErrNotSupported); sl@0: return new(ELeave) CSchSession(*iTaskScheduler); sl@0: } sl@0: sl@0: // Perform all server initialisation, in particular creation of the sl@0: // scheduler and server and then run the scheduler sl@0: static void RunSchedulerL() sl@0: { sl@0: // naming the server thread after the server helps to debug panics sl@0: User::LeaveIfError(User::RenameThread(KSchSvrName)); sl@0: User::LeaveIfError(User::SetProcessCritical(User::ESystemCritical)); sl@0: RProcess().SetPriority(EPriorityHigh); sl@0: sl@0: // create and install the active scheduler we need sl@0: CActiveScheduler* s=new(ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(s); sl@0: CActiveScheduler::Install(s); sl@0: // sl@0: // create the server (leave it on the cleanup stack) sl@0: CSchServer::NewLC(); sl@0: // sl@0: // Initialisation complete, now signal the client sl@0: RProcess::Rendezvous(KErrNone); sl@0: // sl@0: // Ready to run sl@0: CActiveScheduler::Start(); sl@0: // sl@0: // Cleanup the server and scheduler sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: EXPORT_C TInt RunScheduler() sl@0: // sl@0: // Run the scheduler sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: // sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: TInt r=KErrNoMemory; sl@0: if (cleanup) sl@0: { sl@0: TRAP(r,RunSchedulerL()); sl@0: delete cleanup; sl@0: } sl@0: // sl@0: __UHEAP_MARKEND; sl@0: return r; sl@0: } sl@0: sl@0: