119 break; |
116 break; |
120 /* If it is a cleanup then we need to delete the iDeviceThread */ |
117 /* If it is a cleanup then we need to delete the iDeviceThread */ |
121 case EUsbHostMsFinalCleanup: |
118 case EUsbHostMsFinalCleanup: |
122 if(iDeviceThread->IsActive()) |
119 if(iDeviceThread->IsActive()) |
123 { |
120 { |
124 TRequestStatus* s=&iDeviceThread->iStatus; |
121 iThread.RequestComplete(iClientStatus, KErrSessionClosed); |
125 iThread.RequestComplete(s, KErrSessionClosed); |
|
126 } |
122 } |
127 iDeviceThread->Cancel(); |
123 |
128 delete iDeviceThread; |
124 delete iDeviceThread; |
129 iThread.Kill(KErrNone); |
125 iThread.Kill(KErrNone); |
130 aMessage.Complete(KErrNone); |
126 aMessage.Complete(KErrNone); |
131 return; |
127 return; |
132 default: |
128 default: |
133 break; |
129 break; |
134 } |
130 } |
135 |
131 |
136 __HOSTPRINT1(_L("Queuing %d message"), ++iMsgCount); |
|
137 __ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist)); |
132 __ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist)); |
138 |
133 |
139 r = iDeviceThread->QueueMsg(aMessage); |
134 r = iDeviceThread->QueueMsg(aMessage); |
140 if(r != KErrNone) |
135 if (r != KErrNone) |
141 { |
136 { |
142 aMessage.Complete(r); |
137 aMessage.Complete(r); |
143 return; |
138 return; |
144 } |
139 } |
145 |
140 |
146 if(iDeviceThread->IsActive()) |
141 if (iClientStatus && *iClientStatus == KRequestPending) |
147 { |
142 { |
148 iDeviceThread->Lock(); |
|
149 if(iDeviceThread->iIsSignalled) |
|
150 { |
|
151 iDeviceThread->Unlock(); |
|
152 return; |
|
153 } |
|
154 iDeviceThread->iIsSignalled = ETrue; |
|
155 iDeviceThread->Unlock(); |
|
156 __HOSTPRINT(_L("Signaling device thread to handle message")); |
143 __HOSTPRINT(_L("Signaling device thread to handle message")); |
157 TRequestStatus* s=&iDeviceThread->iStatus; |
144 iThread.RequestComplete(iClientStatus, KErrNone); |
158 iThread.RequestComplete(s, KErrNone); |
|
159 } |
145 } |
160 } |
146 } |
161 |
147 |
162 |
148 |
163 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage) |
149 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage) |
164 { |
150 { |
|
151 __MSFNLOG |
165 THostMassStorageConfig msDeviceConfig; |
152 THostMassStorageConfig msDeviceConfig; |
166 TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig)); |
153 TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig)); |
167 |
154 |
168 aMessage.ReadL(0, ptr); |
155 aMessage.ReadL(0, ptr); |
169 __HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken); |
156 __HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken); |
170 |
157 |
171 TInt r = KErrNone; |
158 TBuf<20> nameBuf; |
172 TName nameBuf; |
|
173 TRequestStatus aStatus; |
|
174 |
|
175 nameBuf.Format(_L("Host Ms Thread%d"), msDeviceConfig.iInterfaceToken); |
159 nameBuf.Format(_L("Host Ms Thread%d"), msDeviceConfig.iInterfaceToken); |
176 iDeviceThread = CUsbHostMsDeviceThread::NewL(msDeviceConfig.iInterfaceToken); |
160 iDeviceThread = CUsbHostMsDeviceThread::NewL(*this, msDeviceConfig.iInterfaceToken); |
177 |
161 |
178 RHeap* h = (RHeap*)&User::Allocator(); |
162 RHeap* h = (RHeap*)&User::Allocator(); |
179 TInt maxsize = h->MaxLength(); // loader heap max size = file server heap max size |
163 TInt maxsize = h->MaxLength(); // loader heap max size = file server heap max size |
180 const TUint KHeapMinSize = 2048; |
164 const TUint KHeapMinSize = 2048; |
181 |
165 |
182 r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread); |
166 TInt r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread); |
183 if(r != KErrNone) |
167 if(r != KErrNone) |
184 { |
168 { |
185 delete iDeviceThread; |
169 delete iDeviceThread; |
186 iDeviceThread = NULL; |
170 iDeviceThread = NULL; |
187 User::Leave(r); |
171 User::Leave(r); |
188 } |
172 } |
189 iThread.SetPriority(EPriorityAbsoluteBackgroundNormal); |
173 iThread.SetPriority(EPriorityAbsoluteBackgroundNormal); |
190 iThread.Rendezvous(aStatus); |
174 TRequestStatus status; |
|
175 iThread.Rendezvous(status); |
191 iThread.Resume(); |
176 iThread.Resume(); |
192 User::WaitForRequest(aStatus); |
177 User::WaitForRequest(status); |
193 if(aStatus != KErrNone) |
178 if(status != KErrNone) |
194 { |
179 { |
195 if(iDeviceThread->IsActive()) |
180 if(iDeviceThread->IsActive()) |
196 { |
181 { |
197 TRequestStatus* s=&iDeviceThread->iStatus; |
182 iThread.RequestComplete(iClientStatus, KErrSessionClosed); |
198 iThread.RequestComplete(s, KErrSessionClosed); |
|
199 } |
183 } |
200 iDeviceThread->Cancel(); |
184 iDeviceThread->Cancel(); |
201 delete iDeviceThread; |
185 delete iDeviceThread; |
202 iDeviceThread = NULL; |
186 iDeviceThread = NULL; |
203 iThread.Kill(KErrNone); |
187 iThread.Kill(KErrNone); |
204 User::Leave(aStatus.Int()); |
188 User::Leave(status.Int()); |
205 } |
189 } |
206 } |
190 } |
|
191 |
|
192 |
|
193 |
|
194 void CUsbHostMsSession::MessageRequest(TRequestStatus& aStatus) |
|
195 { |
|
196 __MSFNLOG |
|
197 iClientStatus = &aStatus; |
|
198 *iClientStatus = KRequestPending; |
|
199 } |