genericservices/taskscheduler/SCHSVR/SSCH_SVR.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-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 // SCH_SVR.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 // User includes
       
    19 #include "SSCH_STD.H"
       
    20 #include "SchLogger.h"
       
    21 #include "SCHMAN.H"
       
    22 #include "CSCHCODE.H"
       
    23 #include "SCHEXE.H"
       
    24 #include "SchSSAMan.h"
       
    25 
       
    26 extern const BSUL::TClientMessageServerData KServerData;
       
    27 
       
    28 CSchServer* CSchServer::NewLC()
       
    29 	{
       
    30 	CSchServer* self=new(ELeave) CSchServer(EPriority);
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL();
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CSchServer::CSchServer(TInt aPriority)
       
    37 	: CServer2(aPriority)
       
    38 	{
       
    39 	}
       
    40 
       
    41 CSchServer::~CSchServer()
       
    42 	{
       
    43 	delete iTaskScheduler;
       
    44 	delete iSSAMgr;
       
    45 
       
    46 #ifdef __SCHLOGGING__
       
    47 	delete iTheLog;
       
    48 #endif
       
    49 	}
       
    50 
       
    51 void CSchServer::ConstructL()
       
    52 	{
       
    53 #ifdef __SCHLOGGING__
       
    54 	iTheLog = CSheduleServerLog::NewL(_L("SchSvr"));
       
    55 	Dll::SetTls(iTheLog);
       
    56 #endif
       
    57 
       
    58  	// Create server storage path
       
    59  	RFs fs;
       
    60  	User::LeaveIfError(fs.Connect());
       
    61 
       
    62 	TInt err = fs.CreatePrivatePath(RFs::GetSystemDrive());
       
    63 
       
    64 	if(err != KErrNone && err != KErrAlreadyExists)
       
    65 		User::Leave(err);
       
    66 	
       
    67 	fs.Close();
       
    68 
       
    69 	iTaskScheduler = CTaskScheduler::NewL();
       
    70 
       
    71 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    72 	iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KSM2OSServicesDomain3);
       
    73 #else
       
    74 	iSSAMgr = new(ELeave) CSchStartupStateMgr(KDmHierarchyIdStartup, KBaseServicesDomain3);
       
    75 #endif //SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    76 
       
    77 	iSSAMgr->RegisterObserverL(iTaskScheduler);
       
    78 	iSSAMgr->InitialiseL();
       
    79 	
       
    80 	//Initialise message framework
       
    81 	BSUL::CClientMessage::InitialiseFrameworkL(KServerData);
       
    82 
       
    83 	StartL(KSchSvrName);
       
    84 	}
       
    85 
       
    86 CSession2* CSchServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
       
    87 //
       
    88 // Create a new client for this server.
       
    89 //
       
    90 	{
       
    91 	TVersion v(KESchSvrMajorVersionNumber,KESchSvrMinorVersionNumber,KESchSvrBuildVersionNumber);
       
    92 	TBool r=User::QueryVersionSupported(v,aVersion);
       
    93 	if (r==EFalse)
       
    94 		User::Leave(KErrNotSupported);
       
    95 	return new(ELeave) CSchSession(*iTaskScheduler);
       
    96 	}
       
    97 
       
    98 // Perform all server initialisation, in particular creation of the
       
    99 // scheduler and server and then run the scheduler
       
   100 static void RunSchedulerL()
       
   101 	{
       
   102 	// naming the server thread after the server helps to debug panics
       
   103 	User::LeaveIfError(User::RenameThread(KSchSvrName));
       
   104 	User::LeaveIfError(User::SetProcessCritical(User::ESystemCritical));
       
   105 	RProcess().SetPriority(EPriorityHigh);
       
   106 
       
   107 	// create and install the active scheduler we need
       
   108 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
   109 	CleanupStack::PushL(s);
       
   110 	CActiveScheduler::Install(s);
       
   111 	//
       
   112 	// create the server (leave it on the cleanup stack)
       
   113 	CSchServer::NewLC();
       
   114 	//
       
   115 	// Initialisation complete, now signal the client
       
   116 	RProcess::Rendezvous(KErrNone);
       
   117 	//
       
   118 	// Ready to run
       
   119 	CActiveScheduler::Start();
       
   120 	//
       
   121 	// Cleanup the server and scheduler
       
   122 	CleanupStack::PopAndDestroy(2);
       
   123 	}
       
   124 
       
   125 EXPORT_C TInt RunScheduler()
       
   126 //
       
   127 // Run the scheduler
       
   128 //
       
   129 	{
       
   130 	__UHEAP_MARK;
       
   131 	//
       
   132 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   133 	TInt r=KErrNoMemory;
       
   134 	if (cleanup)
       
   135 		{
       
   136 		TRAP(r,RunSchedulerL());
       
   137 		delete cleanup;
       
   138 		}
       
   139 	//
       
   140 	__UHEAP_MARKEND;
       
   141 	return r;
       
   142 	}
       
   143 
       
   144