lowlevellibsandfws/apputils/src/Baksrvs.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 "Baksrvs.h"
       
    17 #include <baksrv.h>
       
    18 #include <bafl/backup_std.h>
       
    19 #include <basched.h>
       
    20 #include <w32std.h>
       
    21 
       
    22 _LIT(KRomPath,"Z:\\System\\Libs\\");
       
    23 _LIT(KFullBackUpServer,"eikbackupsrv.dll");
       
    24 
       
    25 static void RunServerL()
       
    26 	{
       
    27 
       
    28 	RThread thread;
       
    29 	User::LeaveIfError(User::RenameThread(__BACKUP_SERVER_NAME_V2));
       
    30     thread.SetPriority(EPriorityRealTime);
       
    31     thread.Close();
       
    32 	
       
    33 	RLibrary library;
       
    34 
       
    35 	CBaServBackupScheduler* scheduler = new (ELeave) CBaServBackupScheduler;
       
    36 	CleanupStack::PushL(scheduler);
       
    37 	CActiveScheduler::Install(scheduler);
       
    38 
       
    39 	CBaBackupServer* server = NULL;
       
    40 
       
    41 	TFullName threadName(_L("*"));
       
    42 	threadName.Append(KWSERVThreadName);
       
    43 	TFindThread findWserv(threadName);
       
    44 	TFullName name;
       
    45 	TBool wservLoaded = EFalse;
       
    46 	if (findWserv.Next(name) != KErrNone)
       
    47 		server = CBaBackupServer::NewL();
       
    48 	else
       
    49 		{
       
    50 		User::LeaveIfError(library.Load(KFullBackUpServer, KRomPath));
       
    51 		CleanupClosePushL(library);
       
    52 		TLibraryFunction loadServer = library.Lookup(1);
       
    53 		server = reinterpret_cast<CBaBackupServer*>((*loadServer)());
       
    54 		User::LeaveIfNull(server);
       
    55 		wservLoaded = ETrue;
       
    56 		}
       
    57 	CleanupStack::PushL(server);
       
    58 	server->ConstructL();
       
    59 
       
    60 	RProcess::Rendezvous(KErrNone);
       
    61 
       
    62 	CActiveScheduler::Start();
       
    63 
       
    64 	CleanupStack::PopAndDestroy(server);
       
    65 	if (wservLoaded)
       
    66 		CleanupStack::PopAndDestroy(); //library
       
    67 	CleanupStack::PopAndDestroy(scheduler);
       
    68 	}
       
    69 
       
    70 
       
    71 TInt E32Main()
       
    72    //
       
    73    // Server process entry-point
       
    74    //
       
    75    	{
       
    76    	__UHEAP_MARK;
       
    77    	//
       
    78    	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    79    	TInt r=KErrNoMemory;
       
    80    	if (cleanup)
       
    81    		{
       
    82  		TRAP(r,RunServerL());
       
    83    		delete cleanup;
       
    84    		}
       
    85    	//
       
    86    	__UHEAP_MARKEND;
       
    87    	return r;
       
    88    	}
       
    89