persistentstorage/centralrepository/cenrepsrv/main.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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 //
       
    15 
       
    16 #include "sessmgr.h"   // CSessionManager
       
    17 #include "srvparams.h" // KServerName
       
    18 #include "srvres.h"	   // TServerResources
       
    19 #include "srvrepos_noc.h" // CServerRepository
       
    20 #include <bacline.h>   // CCommandLineArguments
       
    21 #include "backup.h"	   // CRepositoryBackupClient
       
    22 #include "install.h"   // SWI watcher
       
    23 
       
    24 enum
       
    25 	{
       
    26 	ESoftReset = 0x01,
       
    27 	} TStartupOptions;
       
    28 
       
    29 _LIT(KSoftReset, "--SoftReset");
       
    30 
       
    31 static void ParseCmdLineOptionsL(TInt& aOptions)
       
    32 	{
       
    33 	CCommandLineArguments* args = CCommandLineArguments::NewLC();
       
    34 
       
    35 	for (TInt i = 1; i < args->Count(); ++i)
       
    36 		{
       
    37 		if (args->Arg(i).Compare(KSoftReset) == 0)
       
    38 			{
       
    39 			aOptions |= ESoftReset;
       
    40 			}
       
    41 		}
       
    42 
       
    43 	CleanupStack::PopAndDestroy(args);
       
    44 	}
       
    45 
       
    46 static void CloseTServerResources(TAny*)
       
    47 	{
       
    48 	// Ready to exit.
       
    49 	TServerResources::Close();
       
    50 	}
       
    51 
       
    52 //
       
    53 // Perform all server initialisation, in particular creation of the
       
    54 // scheduler and server and then run the scheduler
       
    55 //
       
    56 static void RunServerL()
       
    57 	{
       
    58 	TInt options = 0;
       
    59 
       
    60 #ifndef SYSLIBS_TEST
       
    61     // Set the server as a system critical thread.
       
    62 	User::LeaveIfError(User::SetCritical(User::ESystemCritical));
       
    63 #endif
       
    64 
       
    65 	ParseCmdLineOptionsL(options);
       
    66 
       
    67 	// NOTE: Insert TraceHeap install here,
       
    68 	//		 when RAllocator is available.
       
    69 	//
       
    70 	// naming the server thread after the server helps to debug panics
       
    71 	User::LeaveIfError(User::RenameThread(KServerName));
       
    72 
       
    73 	// create and install the active scheduler we need
       
    74 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
    75 	CleanupStack::PushL(s);
       
    76 	CActiveScheduler::Install(s);
       
    77 
       
    78 	CleanupStack::PushL(TCleanupItem(CloseTServerResources, 0));
       
    79 	TServerResources::InitialiseL();
       
    80 
       
    81 	CSessionManager::NewLC();
       
    82 
       
    83 	CCentRepSWIWatcher* swiWatcher = 0;
       
    84 
       
    85 		
       
    86 	if( TServerResources::iInstallDirectory)
       
    87 		{
       
    88 		swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);	
       
    89 		CleanupStack::PushL(swiWatcher) ;
       
    90 		swiWatcher->Start();
       
    91 		}
       
    92 
       
    93 	CRepositoryBackupClient* backupClient =
       
    94 			CRepositoryBackupClient::NewL(TServerResources::iFs);
       
    95 
       
    96 	CleanupStack::PushL(backupClient) ;
       
    97 
       
    98 	backupClient->StartL();
       
    99 #ifdef SYMBIAN_BAFL_SYSUTIL
       
   100 	PERF_TEST_SERVER_START();
       
   101 
       
   102 	TRAPD(err, CServerRepository::CheckROMReflashL());
       
   103 	if(err != KErrNone)
       
   104 		{
       
   105 		if(err == KErrNoMemory)
       
   106 			{
       
   107 			User::LeaveNoMemory();
       
   108 			}
       
   109 		else
       
   110 			{//Dont stop the centrep from starting up from any other error.
       
   111 			__CENTREP_TRACE1("CENTREP: CServerRepository::CheckROMReflashL - Error = %d", err);
       
   112 			}
       
   113 		}
       
   114 	PERF_TEST_SERVER_END();	
       
   115 #endif
       
   116 
       
   117 	// check command line options
       
   118 	if (options & ESoftReset)
       
   119 		{
       
   120 		CServerRepository::RFSAllRepositoriesL();
       
   121 		}
       
   122 
       
   123 	// Initialisation complete, now signal the client
       
   124 	RProcess::Rendezvous(KErrNone);
       
   125 
       
   126 	// Ready to run
       
   127 	CActiveScheduler::Start();
       
   128 
       
   129 	// Delete backup client if it exists
       
   130 	if(backupClient)
       
   131 		CleanupStack::PopAndDestroy(backupClient);
       
   132 
       
   133 	// Delete file watcher if it exists
       
   134 	if(swiWatcher)
       
   135 		CleanupStack::PopAndDestroy(swiWatcher);
       
   136 
       
   137 	// Ready to exit.
       
   138 
       
   139 	TServerResources::Close();
       
   140 
       
   141 	// Cleanup the server and scheduler
       
   142 	CleanupStack::PopAndDestroy(2);//CSessionManager, s
       
   143 	}
       
   144 
       
   145 // Entry point for the server
       
   146 TInt E32Main()
       
   147 	{
       
   148 	__UHEAP_MARK;
       
   149 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   150 	TInt r = KErrNoMemory;
       
   151 	if(cleanup)
       
   152 		{
       
   153 		TRAP(r, RunServerL());
       
   154 		delete cleanup;
       
   155 		}
       
   156 
       
   157 	__UHEAP_MARKEND;
       
   158 
       
   159 	return r;
       
   160 	}
       
   161