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