author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 27 Apr 2010 18:02:57 +0300 | |
branch | RCL_3 |
changeset 97 | 41f0cfe18c80 |
parent 33 | 0173bcd7697c |
child 176 | af6ec97d9189 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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 |
/** |
|
17 |
@file |
|
18 |
@internalTechnology |
|
19 |
*/ |
|
20 |
||
21 |
#include <e32base.h> |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
|
0 | 23 |
#include "msctypes.h" |
24 |
#include "shared.h" |
|
25 |
#include "msgservice.h" |
|
26 |
#include "cusbhostmslogicalunit.h" |
|
27 |
#include "cusbhostmsdevice.h" |
|
28 |
#include "cusbhostmsserver.h" |
|
29 |
#include "usbmshostpanic.h" |
|
30 |
#include "cusbhostmsdevicethread.h" |
|
31 |
#include "cusbhostmssession.h" |
|
32 |
#include "msdebug.h" |
|
33 |
#include "debug.h" |
|
34 |
||
35 |
/** Construct a Symbian OS session object. |
|
36 |
||
37 |
param aServer Service the session will be a member of |
|
38 |
param aMessage The message from the client. |
|
39 |
return A new CUsbHostMsSession object |
|
40 |
*/ |
|
41 |
CUsbHostMsSession* CUsbHostMsSession::NewL(CUsbHostMsServer& aServer) |
|
42 |
{ |
|
43 |
__MSFNSLOG |
|
44 |
CUsbHostMsSession* r = new (ELeave) CUsbHostMsSession(aServer); |
|
45 |
CleanupStack::PushL(r); |
|
46 |
r->ConstructL(); |
|
47 |
CleanupStack::Pop(); |
|
48 |
return r; |
|
49 |
} |
|
50 |
||
51 |
/** |
|
52 |
Constructor. |
|
53 |
||
54 |
param aServer Service the session will be a member of |
|
55 |
*/ |
|
56 |
CUsbHostMsSession::CUsbHostMsSession(CUsbHostMsServer& aServer) |
|
57 |
: iUsbHostMsServer(aServer) |
|
58 |
{ |
|
59 |
__MSFNLOG |
|
60 |
} |
|
61 |
||
62 |
||
63 |
/** |
|
64 |
2nd Phase Construction. |
|
65 |
*/ |
|
66 |
void CUsbHostMsSession::ConstructL() |
|
67 |
{ |
|
68 |
__MSFNLOG |
|
69 |
iUsbHostMsServer.IncrementSessionCount(); |
|
70 |
__HOSTPRINT1(_L("\tiSessionCount: %d\n"), iUsbHostMsServer.SessionCount()); |
|
71 |
} |
|
72 |
||
73 |
||
74 |
/** |
|
75 |
Destructor. |
|
76 |
*/ |
|
77 |
CUsbHostMsSession::~CUsbHostMsSession() |
|
78 |
{ |
|
79 |
__MSFNLOG |
|
80 |
||
81 |
iUsbHostMsServer.DecrementSessionCount(); |
|
82 |
iThread.Close(); |
|
83 |
__HOSTPRINT1(_L("\tClosed a session -> iSessionCount: %d\n"), iUsbHostMsServer.SessionCount()); |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
Called when a message is received from the client. |
|
88 |
||
89 |
param aMessage Message received from the client |
|
90 |
*/ |
|
91 |
void CUsbHostMsSession::ServiceL(const RMessage2& aMessage) |
|
92 |
{ |
|
93 |
__MSFNLOG |
|
94 |
DispatchMessageL(aMessage); |
|
95 |
} |
|
96 |
||
97 |
||
98 |
/** |
|
99 |
Handles the request (in the form of a message) received from the client |
|
100 |
||
101 |
param aMessage The received message |
|
102 |
*/ |
|
103 |
void CUsbHostMsSession::DispatchMessageL(const RMessage2& aMessage) |
|
104 |
{ |
|
105 |
__MSFNLOG |
|
106 |
TInt r = KErrNone; |
|
107 |
switch (aMessage.Function()) |
|
108 |
{ |
|
109 |
case EUsbHostMsRegisterInterface: |
|
110 |
TRAP(r, CreateDeviceThreadL(aMessage)); |
|
111 |
if(r != KErrNone) |
|
112 |
{ |
|
113 |
aMessage.Complete(r); |
|
114 |
return; |
|
115 |
} |
|
116 |
break; |
|
117 |
/* If it is a cleanup then we need to delete the iDeviceThread */ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
118 |
case EUsbHostMsFinalCleanup: |
0 | 119 |
delete iDeviceThread; |
120 |
iThread.Kill(KErrNone); |
|
121 |
aMessage.Complete(KErrNone); |
|
122 |
return; |
|
123 |
default: |
|
124 |
break; |
|
125 |
} |
|
126 |
||
127 |
__ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist)); |
|
128 |
||
129 |
r = iDeviceThread->QueueMsg(aMessage); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
if (r != KErrNone) |
0 | 131 |
{ |
132 |
aMessage.Complete(r); |
|
133 |
return; |
|
134 |
} |
|
135 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
if (iClientStatus && *iClientStatus == KRequestPending) |
0 | 137 |
{ |
138 |
__HOSTPRINT(_L("Signaling device thread to handle message")); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
iThread.RequestComplete(iClientStatus, KErrNone); |
0 | 140 |
} |
141 |
} |
|
142 |
||
143 |
||
144 |
void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage) |
|
145 |
{ |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
__MSFNLOG |
0 | 147 |
THostMassStorageConfig msDeviceConfig; |
148 |
TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig)); |
|
149 |
||
150 |
aMessage.ReadL(0, ptr); |
|
151 |
__HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken); |
|
152 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
153 |
TBuf<32> nameBuf; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
154 |
nameBuf.Format(_L("Host Ms Thread%8x"), msDeviceConfig.iInterfaceToken); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
iDeviceThread = CUsbHostMsDeviceThread::NewL(*this, msDeviceConfig.iInterfaceToken); |
0 | 156 |
|
157 |
RHeap* h = (RHeap*)&User::Allocator(); |
|
158 |
TInt maxsize = h->MaxLength(); // loader heap max size = file server heap max size |
|
159 |
const TUint KHeapMinSize = 2048; |
|
160 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
TInt r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread); |
0 | 162 |
if(r != KErrNone) |
163 |
{ |
|
164 |
delete iDeviceThread; |
|
165 |
iDeviceThread = NULL; |
|
166 |
User::Leave(r); |
|
167 |
} |
|
168 |
iThread.SetPriority(EPriorityAbsoluteBackgroundNormal); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
TRequestStatus status; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
iThread.Rendezvous(status); |
0 | 171 |
iThread.Resume(); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
User::WaitForRequest(status); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
if(status != KErrNone) |
0 | 174 |
{ |
175 |
delete iDeviceThread; |
|
176 |
iDeviceThread = NULL; |
|
177 |
iThread.Kill(KErrNone); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
User::Leave(status.Int()); |
0 | 179 |
} |
180 |
} |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
void CUsbHostMsSession::MessageRequest(TRequestStatus& aStatus) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
__MSFNLOG |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
iClientStatus = &aStatus; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
*iClientStatus = KRequestPending; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
} |