sysstatemgmt/systemstatemgr/sus/src/main.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 <e32base.h>
       
    17 #include "ssmdebug.h"
       
    18 #include "susutilserver.h"
       
    19 #include "susadaptionserver.h"
       
    20 #include "susadaptionclisrv.h"
       
    21 
       
    22 
       
    23 //
       
    24 // Functions run in the Adaption Server's thread
       
    25 //
       
    26 
       
    27 /**
       
    28  This function is creating the AdaptionServer and starting its scheduler.
       
    29  */
       
    30 static void RunAdaptionSrvL()
       
    31 	{
       
    32 	CActiveScheduler* sched = new(ELeave) CActiveScheduler();
       
    33     CleanupStack::PushL( sched );
       
    34     CActiveScheduler::Install( sched );
       
    35 
       
    36     CSsmAdaptationServer* server = CSsmAdaptationServer::NewLC();
       
    37     RThread::Rendezvous( KErrNone );
       
    38     
       
    39     CActiveScheduler::Start();
       
    40 
       
    41     CleanupStack::PopAndDestroy( server );
       
    42     CleanupStack::PopAndDestroy( sched );
       
    43 	}
       
    44 
       
    45 /**
       
    46  This function is called when the AdaptionServer's thread is resumed.
       
    47  */
       
    48 static TInt AdaptionSrvInitFunction( TAny* /*aNull*/ )
       
    49 	{
       
    50     CTrapCleanup* cleanup=CTrapCleanup::New();
       
    51 	TInt err = KErrNoMemory;
       
    52 	if (cleanup)
       
    53 		{
       
    54 	    TRAP( err, RunAdaptionSrvL());
       
    55 	    delete cleanup;
       
    56 		}
       
    57     return err;
       
    58 	}
       
    59 
       
    60 //
       
    61 // Functions to launch the servers (these will run in the main thread)
       
    62 //
       
    63 
       
    64 /**
       
    65 Function to launch the AdaptionServer in a new thread.
       
    66  */
       
    67 static TInt StartAdaptionSrv()
       
    68 	{
       
    69 	DEBUGPRINT1( _L("Starting SusAdaptionServer") );
       
    70 
       
    71 	RThread server;
       
    72 	const TInt KMinHeapSize =  0x1000; // 4kB
       
    73 	const TInt KMaxHeapSize = 0x100000;// 1MB
       
    74 
       
    75 	TInt err = server.Create( KSusAdaptionServerName, &AdaptionSrvInitFunction, 
       
    76 								 KDefaultStackSize, KMinHeapSize, KMaxHeapSize, 
       
    77 								 NULL );
       
    78 
       
    79 	if( KErrNone == err )
       
    80 		{
       
    81 		TRequestStatus trs;
       
    82 		server.Rendezvous( trs );
       
    83 		server.Resume();
       
    84 		
       
    85 		User::WaitForRequest( trs );	
       
    86 		
       
    87 		//We can't use the 'exit reason' if the server panicked as this is the 
       
    88 		//panic 'reason' and may be '0' which cannot be distinguished from KErrNone
       
    89 		err = (server.ExitType()==EExitPanic) ? KErrGeneral : trs.Int();
       
    90 		server.Close();
       
    91 		}
       
    92 
       
    93 	return err;
       
    94 	}
       
    95 
       
    96 /**
       
    97 Function to launch the UtilServer in this thread.
       
    98  */
       
    99 static void StartUtilSrvL()
       
   100 	{
       
   101 	DEBUGPRINT1( _L("Starting SusUtilServer") );
       
   102 	
       
   103 	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
       
   104 	CleanupStack::PushL(sched);	
       
   105 	CActiveScheduler::Install(sched);
       
   106 
       
   107 	CSusUtilServer* server = CSusUtilServer::NewLC();
       
   108 	RProcess::Rendezvous(KErrNone);
       
   109 	sched->Start();
       
   110 
       
   111 	CleanupStack::PopAndDestroy(server);
       
   112 	CleanupStack::PopAndDestroy(sched);
       
   113 	}
       
   114 
       
   115 //
       
   116 // The main() function itself
       
   117 //
       
   118 /**
       
   119 Process entry point. Called by client using RProcess API
       
   120 @return - Standard Epoc error code on process exit
       
   121 */
       
   122 TInt E32Main() //lint -e765 -e714 Suppress 'not referenced' and 'could be static'
       
   123 	{
       
   124 	__UHEAP_MARK;
       
   125 	TInt err = StartAdaptionSrv(); //started in a new thread
       
   126 	if(KErrNone == err)
       
   127 		{
       
   128 		CTrapCleanup* cleanup = CTrapCleanup::New();
       
   129 		err = KErrNoMemory;
       
   130 		if(cleanup)
       
   131 			{
       
   132 			TRAP(err, StartUtilSrvL()); //started in this thread
       
   133 			delete cleanup;
       
   134 			}
       
   135 		}
       
   136 	__UHEAP_MARKEND;
       
   137 	return err;
       
   138 	}
       
   139