usbmgmt/usbmgr/usbman/server/SRC/UsbSvr.cpp
changeset 0 c9bc50fca66e
child 15 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <usb/usbshared.h>
       
    20 #include "CUsbScheduler.h"
       
    21 #include "CUsbServer.h"
       
    22 #include <usb/usblogger.h>
       
    23 #include "rusb.h"
       
    24 
       
    25 static void RunServerL();
       
    26 
       
    27 #ifdef __FLOG_ACTIVE
       
    28 _LIT8(KLogComponent, "USBSVR");
       
    29 #endif
       
    30 
       
    31 
       
    32 GLDEF_C TInt E32Main()
       
    33 /**
       
    34  * Entry-point for the USB Manager server.
       
    35  *
       
    36  * @return The result of UsbMan::Run
       
    37  */
       
    38 	{
       
    39 	__UHEAP_MARK;
       
    40 
       
    41 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    42 
       
    43 	TInt ret = KErrNoMemory;
       
    44 
       
    45 	if (cleanup)
       
    46 		{
       
    47 		TRAP(ret, RunServerL());
       
    48 		delete cleanup;
       
    49 		}
       
    50 
       
    51 	__UHEAP_MARKEND;
       
    52 
       
    53 	return ret;
       
    54 	}
       
    55 
       
    56 static void RunServerL()
       
    57 //
       
    58 // Perform all server initialisation, in particular creation of the
       
    59 // scheduler and server and then run the scheduler
       
    60 //
       
    61 	{
       
    62 	// naming the server thread after the server helps to debug panics
       
    63 	LEAVEIFERRORL(User::RenameThread(KUsbServerName));
       
    64 	//
       
    65 	// create and install the active scheduler we need
       
    66 	CUsbScheduler* scheduler = CUsbScheduler::NewL();
       
    67 	CleanupStack::PushL(scheduler);
       
    68 	CUsbScheduler::Install(scheduler);
       
    69 	//
       
    70 	// create the server (leave it on the cleanup stack)
       
    71 	CUsbServer* server = CUsbServer::NewLC();
       
    72 	scheduler->SetServer(*server);
       
    73 	//
       
    74 	// Initialisation complete, now signal the client
       
    75 #ifdef __USBMAN_NO_PROCESSES__
       
    76 	RThread::Rendezvous(KErrNone);
       
    77 #else
       
    78 	RProcess::Rendezvous(KErrNone);
       
    79 #endif
       
    80 
       
    81 	//
       
    82 	// Ready to run
       
    83 	CActiveScheduler::Start();
       
    84 
       
    85 	//
       
    86 	// Cleanup the server and scheduler
       
    87 	CleanupStack::PopAndDestroy(2, scheduler);
       
    88 	}
       
    89 
       
    90 #ifdef __USBMAN_NO_PROCESSES__
       
    91 
       
    92 // The server binary is an "EPOCEXE" target type
       
    93 // Thus the server parameter passing and startup code for WINS and EPOC are
       
    94 // significantly different.
       
    95 //
       
    96 // In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain,
       
    97 // taking no parameters and returning TInt. This is not really valid as a thread
       
    98 // function which takes a TAny* parameter which we need.
       
    99 //
       
   100 // So the DLL entry-point WinsMain() is used to return a TInt representing the
       
   101 // real thread function within the DLL. This is good as long as
       
   102 // sizeof(TInt)>=sizeof(TThreadFunction).
       
   103 //
       
   104 
       
   105 static TInt ThreadFunction(TAny* /*aPtr*/)
       
   106 //
       
   107 // WINS thread entry-point function.
       
   108 //
       
   109 	{
       
   110 	return E32Main();
       
   111 	}
       
   112 
       
   113 IMPORT_C TInt WinsMain();
       
   114 EXPORT_C TInt WinsMain()
       
   115 //
       
   116 // WINS DLL entry-point. Just return the real thread function 
       
   117 // cast to TInt
       
   118 //
       
   119 	{
       
   120 	return reinterpret_cast<TInt>(&ThreadFunction);
       
   121 	}
       
   122 
       
   123 
       
   124 #endif
       
   125 
       
   126 //
       
   127 // End of file