sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "usbmsshared.h" sl@0: #include "cusbmassstoragescheduler.h" sl@0: #include "t_cusbmassstoragecontroller.h" sl@0: #include "cusbmassstorageserver.h" sl@0: sl@0: LOCAL_C void RunServerL(); sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: /** sl@0: * Entry-point for the USB Manager server. sl@0: * sl@0: * @return The result of UsbMan::Run sl@0: */ sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: TInt ret = KErrNoMemory; sl@0: sl@0: if (cleanup) sl@0: { sl@0: TRAP(ret, RunServerL()); sl@0: delete cleanup; sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: static void RunServerL() sl@0: // sl@0: // Perform all server initialisation, in particular creation of the sl@0: // scheduler and server and then run the scheduler sl@0: // sl@0: { sl@0: // naming the server thread after the server helps to debug panics sl@0: User::LeaveIfError(RThread().RenameMe(KUsbMsServerName)); sl@0: // sl@0: // create and install the active scheduler we need sl@0: CUsbMassStorageScheduler* scheduler = CUsbMassStorageScheduler::NewL(); sl@0: CleanupStack::PushL(scheduler); sl@0: CUsbMassStorageScheduler::Install(scheduler); sl@0: // sl@0: // create the server (leave it on the cleanup stack) sl@0: CUsbMassStorageController* msController = CUsbMassStorageController::NewL(); sl@0: CleanupStack::PushL(msController); sl@0: sl@0: CUsbMassStorageServer* server = CUsbMassStorageServer::NewLC(*msController); sl@0: scheduler->SetServer(*server); sl@0: // sl@0: // Initialisation complete, now signal the client sl@0: #ifdef __USBMS_NO_PROCESSES__ sl@0: RThread::Rendezvous(KErrNone); sl@0: #else sl@0: RProcess::Rendezvous(KErrNone); sl@0: #endif sl@0: sl@0: // sl@0: // Ready to run sl@0: CActiveScheduler::Start(); sl@0: // sl@0: // Cleanup the server, mscontroller and scheduler sl@0: CleanupStack::PopAndDestroy(3, scheduler); sl@0: } sl@0: sl@0: #ifdef __USBMS_NO_PROCESSES__ sl@0: sl@0: // The server binary is an "EPOCEXE" target type sl@0: // Thus the server parameter passing and startup code for WINS and EPOC are sl@0: // significantly different. sl@0: // sl@0: // In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain, sl@0: // taking no parameters and returning TInt. This is not really valid as a thread sl@0: // function which takes a TAny* parameter which we need. sl@0: // sl@0: // So the DLL entry-point WinsMain() is used to return a TInt representing the sl@0: // real thread function within the DLL. This is good as long as sl@0: // sizeof(TInt)>=sizeof(TThreadFunction). sl@0: // sl@0: sl@0: static TInt ThreadFunction(TAny* /*aPtr*/) sl@0: // sl@0: // WINS thread entry-point function. sl@0: // sl@0: { sl@0: return E32Main(); sl@0: } sl@0: sl@0: IMPORT_C TInt WinsMain(); sl@0: EXPORT_C TInt WinsMain() sl@0: // sl@0: // WINS DLL entry-point. Just return the real thread function sl@0: // cast to TInt sl@0: // sl@0: { sl@0: return reinterpret_cast(&ThreadFunction); sl@0: } sl@0: sl@0: TInt E32Dll(TDllReason) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: #endif sl@0: sl@0: // sl@0: // End of file sl@0: