supl/locationsuplfw/gateway/src/epos_suplserverstartup.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Server startup code
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <centralrepository.h>
       
    23 
       
    24 #include "epos_startsuplserver.h"
       
    25 #include "epos_csuplserver.h"
       
    26 
       
    27 //#ifdef _DEBUG
       
    28 #include "epos_csuplglobal.h"
       
    29 //#endif
       
    30 
       
    31 _LIT(KSuplServerStartupSemaphoreName, "SuplServerStartupSem");
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // StartSuplServerL
       
    36 // Server startup routine
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 void StartSuplServerL()
       
    40 	{
       
    41 	// Rename thread to aid debugging
       
    42 	User::LeaveIfError(RThread().RenameMe(KSuplServerName));
       
    43 
       
    44 	RSemaphore startupSemaphore;
       
    45 	// Start scheduler and server
       
    46 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
    47 	CleanupStack::PushL(scheduler);
       
    48 	CActiveScheduler::Install(scheduler);
       
    49 
       
    50 //#ifdef _DEBUG
       
    51     SuplGlobal::SetupTraceL();
       
    52     _LIT(KTraceFileName, "SUPL_GW::epos_suplserverstartup.cpp");
       
    53     _LIT(KTracePointStart, "SuplServerStartup");
       
    54     SuplGlobal::Trace(KTracePointStart, KTraceFileName, __LINE__);
       
    55 //#endif
       
    56     CSuplServer* server = NULL;
       
    57 	//TInt err;
       
    58 	TRAPD(err, server = CSuplServer::NewL());
       
    59 	
       
    60 	if (err != KErrNone)
       
    61 	{
       
    62 		if ( startupSemaphore.OpenGlobal( KSuplServerStartupSemaphoreName ) == KErrNone 
       
    63        )
       
    64         {
       
    65         //Signal the client:The server might have started up successfully or not
       
    66         startupSemaphore.Signal(KMaxClients);
       
    67         }
       
    68 
       
    69     startupSemaphore.Close();
       
    70     
       
    71     _LIT(KTracePointStop, "SuplServerShutdown");
       
    72     SuplGlobal::Trace(KTracePointStop, KTraceFileName, __LINE__);
       
    73     SuplGlobal::TearDownTrace();
       
    74 		
       
    75 		User::Leave(err);
       
    76 	}
       
    77 	CleanupStack::PushL(server);
       
    78 
       
    79 	// Signal that we've started
       
    80 	RProcess::Rendezvous(KErrNone);
       
    81 	
       
    82 	CleanupStack::Pop(server);
       
    83 	CleanupStack::Pop(scheduler);
       
    84 
       
    85 	// Close semaphore since the startup is now ready
       
    86 	//CleanupStack::PopAndDestroy(&startingSemaphore);
       
    87    
       
    88     // Signal to semaphore that server startup is completed
       
    89 	
       
    90     if ( startupSemaphore.OpenGlobal( KSuplServerStartupSemaphoreName ) == KErrNone 
       
    91        )
       
    92         {
       
    93         //Signal the client:The server might have started up successfully or not
       
    94         startupSemaphore.Signal(KMaxClients);
       
    95         }
       
    96 
       
    97     startupSemaphore.Close();
       
    98     
       
    99     CActiveScheduler::Start();
       
   100 	delete server;
       
   101 	delete scheduler;
       
   102 	
       
   103 //#ifdef _DEBUG
       
   104     _LIT(KTracePointStop, "SuplServerShutdown");
       
   105     SuplGlobal::Trace(KTracePointStop, KTraceFileName, __LINE__);
       
   106     SuplGlobal::TearDownTrace();
       
   107 //#endif
       
   108 
       
   109 	}
       
   110 
       
   111 //
       
   112 // ---------------------------------------------------------
       
   113 // E32Dll
       
   114 // Server process entry-point
       
   115 // Recover the startup parameters and run the server
       
   116 // ---------------------------------------------------------
       
   117 TInt E32Main()
       
   118 	{
       
   119 	__UHEAP_MARK;
       
   120 
       
   121 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   122 
       
   123 	TInt ret = KErrNoMemory;
       
   124 	if (cleanupStack)
       
   125 		{
       
   126 		TRAP(ret, StartSuplServerL());
       
   127 		delete cleanupStack;
       
   128 		}
       
   129 
       
   130 	__UHEAP_MARKEND;
       
   131 
       
   132 	return ret;
       
   133 	}
       
   134 
       
   135 //  End of File