1 /* |
|
2 * Copyright (c) 2002 - 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements OBEX class controller |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CUsbObexClassController.h" |
|
20 #include <usb_std.h> |
|
21 #include <obex.h> |
|
22 #include <SrcsInterface.h> |
|
23 #include <mmf/common/mmfcontrollerpluginresolver.h> //for CleanupResetAndDestroyPushL |
|
24 #include <musbclasscontrollernotify.h> |
|
25 |
|
26 // Panic category only used in debug builds |
|
27 #ifdef _DEBUG |
|
28 _LIT( KObexCcPanicCategory, "OBEXCC" ); |
|
29 #endif |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, "UsbObexCc"); |
|
33 #endif |
|
34 |
|
35 /** |
|
36 * Panic codes for the USB OBEX Class Controller. |
|
37 */ |
|
38 enum TObexCCPanic |
|
39 { |
|
40 /** Illigal calling of asynchronous function */ |
|
41 EBadAsynchronousCall = 0, |
|
42 /** Start() called while in an illegal state */ |
|
43 EBadApiCallStart = 1, |
|
44 /** Stop() called while in an illegal state */ |
|
45 EBadApiCallStop = 2, |
|
46 }; |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Constructs a CUsbObexClassController object. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CUsbObexClassController* CUsbObexClassController::NewL( |
|
53 MUsbClassControllerNotify& aOwner) |
|
54 { |
|
55 LOG_STATIC_FUNC_ENTRY |
|
56 |
|
57 CUsbObexClassController* self = new (ELeave) CUsbObexClassController(aOwner); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Constructor |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CUsbObexClassController::CUsbObexClassController( |
|
69 MUsbClassControllerNotify& aOwner) |
|
70 : CUsbClassControllerPlugIn(aOwner, KObexClassPriority) |
|
71 { |
|
72 LOG_FUNC |
|
73 iState = EUsbServiceIdle; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Method to perform second phase construction. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CUsbObexClassController::ConstructL() |
|
81 { |
|
82 LOG_FUNC |
|
83 iObexSM = CObexUSB::NewL(); |
|
84 iObexSMWatcher = CObexSMWatcher::NewL(*this); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // From class CUsbClassControllerPlugIn. |
|
89 // Destructor |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CUsbObexClassController::~CUsbObexClassController() |
|
93 { |
|
94 LOG_FUNC |
|
95 Cancel(); |
|
96 delete iObexSM; |
|
97 delete iObexSMWatcher; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // From class CUsbClassControllerPlugIn. |
|
102 // Called by UsbMan to start this class. |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CUsbObexClassController::Start(TRequestStatus& aStatus) |
|
106 { |
|
107 |
|
108 LOG_FUNC |
|
109 //Start() should never be called if started, starting or stopping (or in state EUsbServiceFatalError) |
|
110 __ASSERT_DEBUG(iState == EUsbServiceIdle, _USB_PANIC(KObexCcPanicCategory, EBadApiCallStart)); |
|
111 |
|
112 // Start OBEX SM |
|
113 iRequestStatus = &aStatus; |
|
114 iState = EUsbServiceStarting; |
|
115 aStatus = KRequestPending; |
|
116 LOGTEXT(_L8("CUsbObexClassController::Start() calling ManageUSBService(ETrue)")); |
|
117 iObexSM->ManageUSBServices(ETrue, iStatus); |
|
118 SetActive(); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // From class CUsbClassControllerPlugIn. |
|
123 // Called by UsbMan to stop this class. |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CUsbObexClassController::Stop(TRequestStatus& aStatus) |
|
127 { |
|
128 |
|
129 LOG_FUNC |
|
130 LOGTEXT2(_L8("CUsbObexClassController::Stop iState = %d"), iState); |
|
131 |
|
132 //Stop() should never be called if stopping or starting (or in state EUsbServiceFatalError) |
|
133 __ASSERT_DEBUG(iState == EUsbServiceStarted || iState == EUsbServiceIdle, _USB_PANIC(KObexCcPanicCategory, EBadApiCallStop)); |
|
134 |
|
135 //state may be idle after Cancel |
|
136 if ( iState == EUsbServiceIdle ) |
|
137 { |
|
138 TRequestStatus* status = &aStatus; |
|
139 User::RequestComplete(status, KErrNone); |
|
140 } |
|
141 else |
|
142 { |
|
143 // Stop OBEX SM |
|
144 iRequestStatus = &aStatus; |
|
145 iState = EUsbServiceStopping; |
|
146 aStatus = KRequestPending; |
|
147 LOGTEXT(_L8("CUsbObexClassController::Stop() calling ManageUSBService(EFalse)")); |
|
148 iObexSM->ManageUSBServices(EFalse, iStatus); |
|
149 SetActive(); |
|
150 } |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // From class CActive. |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CUsbObexClassController::RunL() |
|
158 { |
|
159 |
|
160 LOG_FUNC |
|
161 if (iStatus != KErrNone) |
|
162 { |
|
163 LOGTEXT2(_L8("CUsbObexClassController::RunL() Error = %d"), iStatus.Int()); |
|
164 User::RequestComplete(iRequestStatus, iStatus.Int()); |
|
165 return; |
|
166 } |
|
167 LOGTEXT2(_L8("CUsbObexClassController::RunL() State is %d"), iState); |
|
168 |
|
169 switch (iState) |
|
170 { |
|
171 case EUsbServiceStarting: |
|
172 iState = EUsbServiceStarted; |
|
173 User::RequestComplete(iRequestStatus, KErrNone); |
|
174 break; |
|
175 |
|
176 case EUsbServiceStopping: |
|
177 iState = EUsbServiceIdle; |
|
178 User::RequestComplete(iRequestStatus, KErrNone); |
|
179 break; |
|
180 |
|
181 case EUsbServiceStarted: |
|
182 case EUsbServiceIdle: |
|
183 |
|
184 default: |
|
185 LOGTEXT(_L8("CUsbObexClassController::RunL() Error or Unknown State")); |
|
186 break; |
|
187 } |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From class CUsbClassControllerPlugIn. |
|
192 // Returns information about the interfaces supported by this class. |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CUsbObexClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const |
|
196 { |
|
197 LOG_FUNC |
|
198 TRAPD(ret, DoGetDescriptorInfoL(aDescriptorInfo)); |
|
199 if(ret!=KErrNone) |
|
200 { |
|
201 LOGTEXT2(_L8("CUsbObexClassController::GetDescriptorInfo leave with code: %d"), ret); |
|
202 } |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // Leave version of GetDescriptor info function for fit in Class Controller framework. |
|
207 // Returns information about the interfaces supported by this class. |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CUsbObexClassController::DoGetDescriptorInfoL(TUsbDescriptor& aDescriptorInfo) const |
|
211 { |
|
212 LOG_FUNC |
|
213 RImplInfoPtrArray implInfoArray; |
|
214 CleanupResetAndDestroyPushL(implInfoArray); |
|
215 TEComResolverParams resolverParams; |
|
216 resolverParams.SetDataType(KSrcsTransportUSB); |
|
217 resolverParams.SetWildcardMatch(EFalse); |
|
218 REComSession::ListImplementationsL(KCSrcsInterfaceUid, resolverParams, implInfoArray); |
|
219 |
|
220 LOGTEXT2(_L8("CUsbObexClassController::DoGetDescriptorInfoL Number of Interfaces is %d"), |
|
221 implInfoArray.Count()); |
|
222 aDescriptorInfo.iNumInterfaces = (implInfoArray.Count())*KObexNumInterfaces; |
|
223 aDescriptorInfo.iLength = 0; |
|
224 |
|
225 CleanupStack::PopAndDestroy(&implInfoArray); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // From class CActive. |
|
230 // Will only be called when an asynchronous request is currently active. |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CUsbObexClassController::DoCancel() |
|
234 { |
|
235 LOG_FUNC |
|
236 |
|
237 switch (iState) |
|
238 { |
|
239 case EUsbServiceStarting: |
|
240 case EUsbServiceStopping: |
|
241 iObexSM->CancelManageUSBServices(); |
|
242 break; |
|
243 |
|
244 default: |
|
245 __ASSERT_DEBUG( EFalse, _USB_PANIC(KObexCcPanicCategory, EBadAsynchronousCall) ); |
|
246 break; |
|
247 } |
|
248 |
|
249 iState = EUsbServiceIdle; |
|
250 User::RequestComplete(iRequestStatus, KErrCancel); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // From class CActive. |
|
255 // Should return KErrNone to avoid an active scheduler panic. This function |
|
256 // should never be called as there is another mechanism for catching errors. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CUsbObexClassController::RunError(TInt aError) |
|
260 { |
|
261 LOG_FUNC |
|
262 LOGTEXT2(_L8("CUsbObexClassController::RunError aError=%d"), aError); |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 void CUsbObexClassController::MosmError(TInt aError) |
|
267 { |
|
268 LOG_FUNC |
|
269 LOGTEXT2(_L8("CUsbObexClassController::MosmError aError=%d"), aError); |
|
270 Owner().UccnError(aError); |
|
271 } |
|
272 |
|
273 // End of File |
|