1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_cusbmassstoragemain.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,127 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32base.h>
1.20 +#include <e32base_private.h>
1.21 +#include "usbmsshared.h"
1.22 +#include "cusbmassstoragescheduler.h"
1.23 +#include "t_cusbmassstoragecontroller.h"
1.24 +#include "cusbmassstorageserver.h"
1.25 +
1.26 +LOCAL_C void RunServerL();
1.27 +
1.28 +GLDEF_C TInt E32Main()
1.29 +/**
1.30 + * Entry-point for the USB Manager server.
1.31 + *
1.32 + * @return The result of UsbMan::Run
1.33 + */
1.34 + {
1.35 + __UHEAP_MARK;
1.36 +
1.37 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.38 +
1.39 + TInt ret = KErrNoMemory;
1.40 +
1.41 + if (cleanup)
1.42 + {
1.43 + TRAP(ret, RunServerL());
1.44 + delete cleanup;
1.45 + }
1.46 +
1.47 + __UHEAP_MARKEND;
1.48 +
1.49 + return ret;
1.50 + }
1.51 +
1.52 +static void RunServerL()
1.53 +//
1.54 +// Perform all server initialisation, in particular creation of the
1.55 +// scheduler and server and then run the scheduler
1.56 +//
1.57 + {
1.58 + // naming the server thread after the server helps to debug panics
1.59 + User::LeaveIfError(RThread().RenameMe(KUsbMsServerName));
1.60 + //
1.61 + // create and install the active scheduler we need
1.62 + CUsbMassStorageScheduler* scheduler = CUsbMassStorageScheduler::NewL();
1.63 + CleanupStack::PushL(scheduler);
1.64 + CUsbMassStorageScheduler::Install(scheduler);
1.65 + //
1.66 + // create the server (leave it on the cleanup stack)
1.67 + CUsbMassStorageController* msController = CUsbMassStorageController::NewL();
1.68 + CleanupStack::PushL(msController);
1.69 +
1.70 + CUsbMassStorageServer* server = CUsbMassStorageServer::NewLC(*msController);
1.71 + scheduler->SetServer(*server);
1.72 + //
1.73 + // Initialisation complete, now signal the client
1.74 +#ifdef __USBMS_NO_PROCESSES__
1.75 + RThread::Rendezvous(KErrNone);
1.76 +#else
1.77 + RProcess::Rendezvous(KErrNone);
1.78 +#endif
1.79 +
1.80 + //
1.81 + // Ready to run
1.82 + CActiveScheduler::Start();
1.83 + //
1.84 + // Cleanup the server, mscontroller and scheduler
1.85 + CleanupStack::PopAndDestroy(3, scheduler);
1.86 + }
1.87 +
1.88 +#ifdef __USBMS_NO_PROCESSES__
1.89 +
1.90 +// The server binary is an "EPOCEXE" target type
1.91 +// Thus the server parameter passing and startup code for WINS and EPOC are
1.92 +// significantly different.
1.93 +//
1.94 +// In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain,
1.95 +// taking no parameters and returning TInt. This is not really valid as a thread
1.96 +// function which takes a TAny* parameter which we need.
1.97 +//
1.98 +// So the DLL entry-point WinsMain() is used to return a TInt representing the
1.99 +// real thread function within the DLL. This is good as long as
1.100 +// sizeof(TInt)>=sizeof(TThreadFunction).
1.101 +//
1.102 +
1.103 +static TInt ThreadFunction(TAny* /*aPtr*/)
1.104 +//
1.105 +// WINS thread entry-point function.
1.106 +//
1.107 + {
1.108 + return E32Main();
1.109 + }
1.110 +
1.111 +IMPORT_C TInt WinsMain();
1.112 +EXPORT_C TInt WinsMain()
1.113 +//
1.114 +// WINS DLL entry-point. Just return the real thread function
1.115 +// cast to TInt
1.116 +//
1.117 + {
1.118 + return reinterpret_cast<TInt>(&ThreadFunction);
1.119 + }
1.120 +
1.121 +TInt E32Dll(TDllReason)
1.122 + {
1.123 + return KErrNone;
1.124 + }
1.125 +
1.126 +#endif
1.127 +
1.128 +//
1.129 +// End of file
1.130 +