realtimenetprots/sipfw/ClientResolver/Server/src/SipCRServerMain.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-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 // Name          : SipCRServerMain.cpp
       
    15 // Part of       : SIP Client Resolver
       
    16 // Version       : 1.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "sipCRclientserver.h"
       
    23 #include "SipCRServerMain.h"
       
    24 #include "CSipCRServer.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // SipCRServerMain::ThreadFunction
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 TInt SipCRServerMain::ThreadFunction (TAny* /*aNone*/)
       
    31 	{
       
    32     TInt err = KErrNone;
       
    33     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
    34 	if (!cleanupStack) 
       
    35         {
       
    36         PanicServer(ECreateTrapCleanup);
       
    37         }
       
    38 	RSemaphore semaphore;
       
    39 	err = semaphore.OpenGlobal(KSipClientResolverServerSemaphoreName);
       
    40     if (err != KErrNone)
       
    41         {
       
    42         PanicServer(ESrvCreateServer);
       
    43         }
       
    44     TRAP(err, ThreadFunctionL(semaphore));
       
    45     if (err != KErrNone)
       
    46         {
       
    47         semaphore.Signal();
       
    48         semaphore.Close();
       
    49         }
       
    50 
       
    51     delete cleanupStack;
       
    52     return err;
       
    53 	}
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // SipCRServerMain::ThreadFunctionL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void SipCRServerMain::ThreadFunctionL (RSemaphore& aSemaphore)
       
    60 	{
       
    61 	// Give a name to this thread
       
    62     User::LeaveIfError(User::RenameThread(KSipClientResolverServerName));
       
    63 
       
    64     // Construct server
       
    65     CSIPCRServer::NewLC();
       
    66 
       
    67 	// Server created ok
       
    68 	aSemaphore.Signal();
       
    69 	aSemaphore.Close();
       
    70 
       
    71 	// Start handling requests
       
    72 	CActiveScheduler::Start();
       
    73 
       
    74     // This will be executed after the active scheduler has been stopped:
       
    75     CleanupStack::PopAndDestroy(1); // server
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // SipCRServerMain::PanicServer
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void SipCRServerMain::PanicServer (TSipCRServerPanic aPanic)
       
    83 	{
       
    84     User::Panic(KSipCRServerPanic, aPanic);
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // E32Main
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TInt E32Main() 
       
    92     { 
       
    93     return SipCRServerMain::ThreadFunction(NULL);
       
    94     }
       
    95 
       
    96 //  End of File