resourcemgmt/powerandmemorynotificationservice/src/shutdownsrvs.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    17 #include "shutdownsrv.h"
       
    18 #else //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include "shutdownsess.h"
       
    20 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    21 #include "savepriv.h"
       
    22 #include <w32std.h>
       
    23 #include <e32std.h>
       
    24 #include <e32svr.h>
       
    25 
       
    26 #ifdef SYMBIAN_SSM_GRACEFUL_SHUTDOWN
       
    27 #include <ssm/ssmpatchableconstants.h>
       
    28 #endif
       
    29 
       
    30 _LIT(KRomPath,"Z:\\System\\Libs\\");
       
    31 _LIT(KFullShutDownServer,"eikshtsrv.dll");
       
    32 
       
    33 void LoadServerL(CServShutdownServer*& aServer, RLibrary& aLibrary)
       
    34 	{
       
    35 	TFullName threadName(_L("*"));
       
    36 	threadName.Append(KWSERVThreadName);
       
    37 	TFindThread findWserv(threadName);
       
    38 	TFullName name;
       
    39 	if (findWserv.Next(name)!=KErrNone)
       
    40 		{
       
    41 		aServer=CServShutdownServer::NewL();
       
    42 		}
       
    43 	else
       
    44 		{
       
    45 		User::LeaveIfError(aLibrary.Load(KFullShutDownServer, KRomPath));
       
    46 		TLibraryFunction loadServer = aLibrary.Lookup(1);
       
    47 		aServer=reinterpret_cast<CServShutdownServer*>((*loadServer)());
       
    48 		}
       
    49 	}
       
    50 static void RunServerL()
       
    51 	{
       
    52 	RThread thread;
       
    53 	User::LeaveIfError(User::RenameThread(__SHUTDOWN_SERVER_NAME));
       
    54 	thread.SetPriority(EPriorityRealTime);
       
    55 	thread.Close();
       
    56 
       
    57 
       
    58 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
    59 	CleanupStack::PushL(scheduler);
       
    60 	CActiveScheduler::Install(scheduler);
       
    61 
       
    62 	CServShutdownServer* server = NULL;
       
    63 	RLibrary library;
       
    64 	CleanupClosePushL(library);
       
    65 
       
    66 #ifdef SYMBIAN_SSM_GRACEFUL_SHUTDOWN
       
    67 	if (IsSsmGracefulShutdown())	// SSM should be used for device shutdown
       
    68 		{
       
    69 		server = CServShutdownServer::NewL();
       
    70 		}
       
    71 	else// continue using eikshtsrv.dll
       
    72 		{
       
    73 		LoadServerL(server,library);
       
    74 		}
       
    75 #else
       
    76 	// use eikshtsrv.dll not SSM
       
    77 	LoadServerL(server,library);
       
    78 #endif // SYMBIAN_SSM_GRACEFUL_SHUTDOWN
       
    79 
       
    80 	CleanupStack::PushL(server);
       
    81 	server->ConstructL();
       
    82 
       
    83 	RProcess::Rendezvous(KErrNone);
       
    84 	CActiveScheduler::Start();
       
    85 
       
    86 	CleanupStack::PopAndDestroy(3,scheduler);
       
    87 	}
       
    88 
       
    89 TInt E32Main()
       
    90 	{
       
    91 	__UHEAP_MARK;
       
    92 	//
       
    93 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    94 	TInt r=KErrNoMemory;
       
    95 	if (cleanup)
       
    96 		{
       
    97 		TRAP(r,RunServerL());
       
    98 		delete cleanup;
       
    99 		}
       
   100 	//
       
   101 	__UHEAP_MARKEND;
       
   102 	return r;
       
   103 	}
       
   104 
       
   105