realtimenetprots/sipfw/SIP/Server/src/SipServerMain.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-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          : SipServerMain.cpp
       
    15 // Part of       : SIPServerCore
       
    16 // Version       : SIP/3.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "sipclientserver.h"
       
    23 #include "SipServerMain.h"
       
    24 #include "CSipServerCore.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // SipServerMain::ThreadFunction
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 TInt SipServerMain::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(KSipServerSemaphoreName);
       
    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 // SipServerMain::ThreadFunctionL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void SipServerMain::ThreadFunctionL (RSemaphore& aSemaphore)
       
    60 	{
       
    61 	// Give a name to this thread
       
    62     User::LeaveIfError(User::RenameThread(KSipServerName));
       
    63 
       
    64     // Construct server
       
    65     CSipServerCore::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 // SipServerMain::PanicServer
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void SipServerMain::PanicServer (TSipCSServerPanic aPanic)
       
    83 	{
       
    84     User::Panic(KSipCSServerPanic, aPanic);
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // E32Main
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TInt E32Main() 
       
    92     { 
       
    93     return SipServerMain::ThreadFunction(NULL);
       
    94     }