sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32base.h>
|
sl@0
|
17 |
#include <e32base_private.h>
|
sl@0
|
18 |
#include "usbmsshared.h"
|
sl@0
|
19 |
#include "cusbmassstoragescheduler.h"
|
sl@0
|
20 |
#include "t_cusbmassstoragecontroller.h"
|
sl@0
|
21 |
#include "cusbmassstorageserver.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
LOCAL_C void RunServerL();
|
sl@0
|
24 |
|
sl@0
|
25 |
GLDEF_C TInt E32Main()
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
* Entry-point for the USB Manager server.
|
sl@0
|
28 |
*
|
sl@0
|
29 |
* @return The result of UsbMan::Run
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
{
|
sl@0
|
32 |
__UHEAP_MARK;
|
sl@0
|
33 |
|
sl@0
|
34 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
35 |
|
sl@0
|
36 |
TInt ret = KErrNoMemory;
|
sl@0
|
37 |
|
sl@0
|
38 |
if (cleanup)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
TRAP(ret, RunServerL());
|
sl@0
|
41 |
delete cleanup;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
__UHEAP_MARKEND;
|
sl@0
|
45 |
|
sl@0
|
46 |
return ret;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
static void RunServerL()
|
sl@0
|
50 |
//
|
sl@0
|
51 |
// Perform all server initialisation, in particular creation of the
|
sl@0
|
52 |
// scheduler and server and then run the scheduler
|
sl@0
|
53 |
//
|
sl@0
|
54 |
{
|
sl@0
|
55 |
// naming the server thread after the server helps to debug panics
|
sl@0
|
56 |
User::LeaveIfError(RThread().RenameMe(KUsbMsServerName));
|
sl@0
|
57 |
//
|
sl@0
|
58 |
// create and install the active scheduler we need
|
sl@0
|
59 |
CUsbMassStorageScheduler* scheduler = CUsbMassStorageScheduler::NewL();
|
sl@0
|
60 |
CleanupStack::PushL(scheduler);
|
sl@0
|
61 |
CUsbMassStorageScheduler::Install(scheduler);
|
sl@0
|
62 |
//
|
sl@0
|
63 |
// create the server (leave it on the cleanup stack)
|
sl@0
|
64 |
CUsbMassStorageController* msController = CUsbMassStorageController::NewL();
|
sl@0
|
65 |
CleanupStack::PushL(msController);
|
sl@0
|
66 |
|
sl@0
|
67 |
CUsbMassStorageServer* server = CUsbMassStorageServer::NewLC(*msController);
|
sl@0
|
68 |
scheduler->SetServer(*server);
|
sl@0
|
69 |
//
|
sl@0
|
70 |
// Initialisation complete, now signal the client
|
sl@0
|
71 |
#ifdef __USBMS_NO_PROCESSES__
|
sl@0
|
72 |
RThread::Rendezvous(KErrNone);
|
sl@0
|
73 |
#else
|
sl@0
|
74 |
RProcess::Rendezvous(KErrNone);
|
sl@0
|
75 |
#endif
|
sl@0
|
76 |
|
sl@0
|
77 |
//
|
sl@0
|
78 |
// Ready to run
|
sl@0
|
79 |
CActiveScheduler::Start();
|
sl@0
|
80 |
//
|
sl@0
|
81 |
// Cleanup the server, mscontroller and scheduler
|
sl@0
|
82 |
CleanupStack::PopAndDestroy(3, scheduler);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
#ifdef __USBMS_NO_PROCESSES__
|
sl@0
|
86 |
|
sl@0
|
87 |
// The server binary is an "EPOCEXE" target type
|
sl@0
|
88 |
// Thus the server parameter passing and startup code for WINS and EPOC are
|
sl@0
|
89 |
// significantly different.
|
sl@0
|
90 |
//
|
sl@0
|
91 |
// In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain,
|
sl@0
|
92 |
// taking no parameters and returning TInt. This is not really valid as a thread
|
sl@0
|
93 |
// function which takes a TAny* parameter which we need.
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// So the DLL entry-point WinsMain() is used to return a TInt representing the
|
sl@0
|
96 |
// real thread function within the DLL. This is good as long as
|
sl@0
|
97 |
// sizeof(TInt)>=sizeof(TThreadFunction).
|
sl@0
|
98 |
//
|
sl@0
|
99 |
|
sl@0
|
100 |
static TInt ThreadFunction(TAny* /*aPtr*/)
|
sl@0
|
101 |
//
|
sl@0
|
102 |
// WINS thread entry-point function.
|
sl@0
|
103 |
//
|
sl@0
|
104 |
{
|
sl@0
|
105 |
return E32Main();
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
IMPORT_C TInt WinsMain();
|
sl@0
|
109 |
EXPORT_C TInt WinsMain()
|
sl@0
|
110 |
//
|
sl@0
|
111 |
// WINS DLL entry-point. Just return the real thread function
|
sl@0
|
112 |
// cast to TInt
|
sl@0
|
113 |
//
|
sl@0
|
114 |
{
|
sl@0
|
115 |
return reinterpret_cast<TInt>(&ThreadFunction);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
TInt E32Dll(TDllReason)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
return KErrNone;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
#endif
|
sl@0
|
124 |
|
sl@0
|
125 |
//
|
sl@0
|
126 |
// End of file
|
sl@0
|
127 |
|