Msrp/MsrpServer/src/MSRPmain.cpp
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
equal deleted inserted replaced
22:f1578314b8da 25:505ad3f0ce5c
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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 * Initial Contributors:
       
     9 * Nokia Corporation - initial contribution.
       
    10 * Contributors:
       
    11 *
       
    12 * Description:
       
    13 * MSRP Implementation
       
    14 *
       
    15 */
       
    16 
       
    17 // INTERNAL INCLUDES
       
    18 #include "MsrpCommon.h"
       
    19 #include "MSRPServerCommon.h"
       
    20 #include "CMSRPScheduler.h"
       
    21 #include "CMSRPServer.h"
       
    22 
       
    23 
       
    24 // ============================= LOCAL FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // PanicServer
       
    28 // Panics the MSRP Server
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 void PanicServer(
       
    32     TMSRPPanicCodes aPanicCode ) // Panic code
       
    33     {
       
    34     MSRPLOG( "MSRPServer: PanicServer enter" );
       
    35     User::Panic( KMSRPServerName, aPanicCode );
       
    36     MSRPLOG( "MSRPServer: PanicServer exit" );
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // StartServerL
       
    41 // Starts the MSRPServer
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 LOCAL_C void StartServerL()
       
    45     {
       
    46     MSRPLOG( "MSRPServer: StartServerL enter" )
       
    47 
       
    48     // create server
       
    49     TFindServer findMsrpServer( KMSRPServerName );
       
    50     TFullName pathName;
       
    51 
       
    52     // Search for the server.
       
    53     if ( findMsrpServer.Next( pathName ) != KErrNone )
       
    54         {
       
    55 		// Start scheduler and server.
       
    56 		CMSRPScheduler* scheduler = new (ELeave) CMSRPScheduler;
       
    57 		__ASSERT_ALWAYS( scheduler !=
       
    58 			NULL, PanicServer( EMSRPServerSchedulerError ) );
       
    59 
       
    60 		CleanupStack::PushL( scheduler );
       
    61 		CActiveScheduler::Install( scheduler );
       
    62 
       
    63 		// Rename the thread.
       
    64 		User::RenameThread( KMSRPServerName );
       
    65 
       
    66 		// Create the server
       
    67 		CMSRPServer* server = CMSRPServer::NewLC();
       
    68 
       
    69 		// The scheduler needs access to the server instance.
       
    70 		//lint -e{613} scheduler cannot be null, due assertion in creation.
       
    71 		scheduler->SetServer( server );
       
    72 
       
    73 		// client alert
       
    74 		RProcess::Rendezvous( KErrNone );
       
    75 
       
    76 		// start fielding requests from clients
       
    77 		CActiveScheduler::Start(); // codescanner::activestart
       
    78 
       
    79 		// finished when the scheduler stops
       
    80 		CleanupStack::PopAndDestroy( 2 ); // scheduler, server, codescanner::cleanup
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		// already exists
       
    85 	    MSRPLOG( "MSRPServer: MSRPServer already running" )
       
    86 	    User::Leave( KErrAlreadyExists );
       
    87 		}
       
    88 
       
    89     MSRPLOG( "MSRPServer: StartServerL exit" )
       
    90     }
       
    91 
       
    92 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // E32Main implements the executable entry function.
       
    96 // Target type of the is EXE.
       
    97 // Creates a cleanup stack and runs the server.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 GLDEF_C TInt E32Main()
       
   101     {
       
   102     __UHEAP_MARK;
       
   103 
       
   104     // Get a new clean-up stack.
       
   105     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   106     TRAPD( error, StartServerL() );
       
   107     delete cleanup;
       
   108     __UHEAP_MARKEND;
       
   109     return error;
       
   110     }
       
   111 
       
   112 //  End of File