os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_cusbmassstoragemain.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 the License "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 //
    15 
    16 #include <e32base.h>
    17 #include <e32base_private.h>
    18 #include "usbmsshared.h"
    19 #include "cusbmassstoragescheduler.h"
    20 #include "t_cusbmassstoragecontroller.h"
    21 #include "cusbmassstorageserver.h"
    22 
    23 LOCAL_C void RunServerL();
    24 
    25 GLDEF_C TInt E32Main()
    26 /**
    27  * Entry-point for the USB Manager server.
    28  *
    29  * @return The result of UsbMan::Run
    30  */
    31 	{
    32 	__UHEAP_MARK;
    33 
    34 	CTrapCleanup* cleanup = CTrapCleanup::New();
    35 
    36 	TInt ret = KErrNoMemory;
    37 
    38 	if (cleanup)
    39 		{
    40 		TRAP(ret, RunServerL());
    41 		delete cleanup;
    42 		}
    43 
    44 	__UHEAP_MARKEND;
    45 
    46 	return ret;
    47 	}
    48 
    49 static void RunServerL()
    50 //
    51 // Perform all server initialisation, in particular creation of the
    52 // scheduler and server and then run the scheduler
    53 //
    54 	{
    55 	// naming the server thread after the server helps to debug panics
    56 	User::LeaveIfError(RThread().RenameMe(KUsbMsServerName));
    57 	//
    58 	// create and install the active scheduler we need
    59 	CUsbMassStorageScheduler* scheduler = CUsbMassStorageScheduler::NewL();
    60 	CleanupStack::PushL(scheduler);
    61 	CUsbMassStorageScheduler::Install(scheduler);
    62 	//
    63 	// create the server (leave it on the cleanup stack)
    64     CUsbMassStorageController* msController = CUsbMassStorageController::NewL();
    65     CleanupStack::PushL(msController);
    66     
    67 	CUsbMassStorageServer* server = CUsbMassStorageServer::NewLC(*msController);
    68 	scheduler->SetServer(*server);
    69 	//
    70 	// Initialisation complete, now signal the client
    71 #ifdef __USBMS_NO_PROCESSES__
    72 	RThread::Rendezvous(KErrNone);
    73 #else
    74 	RProcess::Rendezvous(KErrNone);
    75 #endif
    76 
    77 	//
    78 	// Ready to run
    79 	CActiveScheduler::Start();
    80 	//
    81 	// Cleanup the server, mscontroller and scheduler
    82 	CleanupStack::PopAndDestroy(3, scheduler);
    83 	}
    84 
    85 #ifdef __USBMS_NO_PROCESSES__
    86 
    87 // The server binary is an "EPOCEXE" target type
    88 // Thus the server parameter passing and startup code for WINS and EPOC are
    89 // significantly different.
    90 //
    91 // In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain,
    92 // taking no parameters and returning TInt. This is not really valid as a thread
    93 // function which takes a TAny* parameter which we need.
    94 //
    95 // So the DLL entry-point WinsMain() is used to return a TInt representing the
    96 // real thread function within the DLL. This is good as long as
    97 // sizeof(TInt)>=sizeof(TThreadFunction).
    98 //
    99 
   100 static TInt ThreadFunction(TAny* /*aPtr*/)
   101 //
   102 // WINS thread entry-point function.
   103 //
   104 	{
   105 	return E32Main();
   106 	}
   107 
   108 IMPORT_C TInt WinsMain();
   109 EXPORT_C TInt WinsMain()
   110 //
   111 // WINS DLL entry-point. Just return the real thread function 
   112 // cast to TInt
   113 //
   114 	{
   115 	return reinterpret_cast<TInt>(&ThreadFunction);
   116 	}
   117 
   118 TInt E32Dll(TDllReason)
   119 	{
   120 	return KErrNone;
   121 	}
   122 
   123 #endif
   124 
   125 //
   126 // End of file
   127