|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * Implements part of the UsbMan USB Class Framework |
|
16 * |
|
17 */ |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include <e32debug.h> |
|
24 #include <e32std.h> |
|
25 #include <usb_std.h> |
|
26 #include "../../public/clientServerShared.h" |
|
27 #include "../../ClassControllerClientSession/inc/classControllerClientSession.h" |
|
28 #include "CUsbObexClassController.h" |
|
29 |
|
30 |
|
31 // Panic category only used in debug builds |
|
32 #ifdef _DEBUG |
|
33 _LIT( KObexCcPanicCategory, "UsbObexCc" ); |
|
34 #endif |
|
35 |
|
36 /** |
|
37 * Panic codes for the USB OBEX Class Controller. |
|
38 */ |
|
39 enum TObexCCPanic |
|
40 { |
|
41 /** Asynchronous function called (not needed, as all requests complete synchronously) */ |
|
42 EUnusedFunction = 0, |
|
43 /** Start() called while in an illegal state */ |
|
44 EBadApiCallStart = 1, |
|
45 /** Stop() called while in an illegal state */ |
|
46 EBadApiCallStop = 2, |
|
47 }; |
|
48 |
|
49 |
|
50 /** |
|
51 * Constructs a CUsbObexClassController object |
|
52 * |
|
53 * @param aOwner USB Device that owns and manages the class |
|
54 * |
|
55 * @return A new CUsbObexClassController object |
|
56 */ |
|
57 |
|
58 CUsbObexClassController* CUsbObexClassController::NewL( |
|
59 MUsbClassControllerNotify& aOwner) |
|
60 { |
|
61 CUsbObexClassController* r = new (ELeave) CUsbObexClassController(aOwner); |
|
62 CleanupStack::PushL(r); |
|
63 r->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 return r; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Destructor |
|
70 */ |
|
71 CUsbObexClassController::~CUsbObexClassController() |
|
72 { |
|
73 iClassContClient.Close(); |
|
74 } |
|
75 |
|
76 |
|
77 |
|
78 /** |
|
79 * Constructor. |
|
80 * |
|
81 * @param aOwner USB Device that owns and manages the class |
|
82 */ |
|
83 CUsbObexClassController::CUsbObexClassController( |
|
84 MUsbClassControllerNotify& aOwner) |
|
85 : CUsbClassControllerPlugIn(aOwner, KObexStartupPriority) |
|
86 { |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 /** |
|
92 * 2nd Phase Construction. |
|
93 */ |
|
94 void CUsbObexClassController::ConstructL() |
|
95 { |
|
96 } |
|
97 |
|
98 |
|
99 |
|
100 /** |
|
101 * Called by UsbMan when it wants to start the USB Obex class. |
|
102 * Data member from RSessionBase implements a Start call on the |
|
103 * Obex Server process. |
|
104 * |
|
105 * @param aStatus The caller's request status, filled in with an error code |
|
106 */ |
|
107 void CUsbObexClassController::Start(TRequestStatus& aStatus) |
|
108 { |
|
109 //Start() should never be called if started, starting or stopping (or in state EUsbServiceFatalError) |
|
110 __ASSERT_DEBUG( iState == EUsbServiceIdle, User::Panic(KObexCcPanicCategory, EBadApiCallStart) ); |
|
111 |
|
112 TRequestStatus* status = &aStatus; |
|
113 TInt err; |
|
114 iState = EUsbServiceStarting; |
|
115 |
|
116 err = iClassContClient.Connect(); // Connect to the Server Session |
|
117 if (err != KErrNone) |
|
118 { |
|
119 iState = EUsbServiceFatalError; |
|
120 User::RequestComplete(status, err); |
|
121 } |
|
122 else |
|
123 { |
|
124 err = iClassContClient.StartService(); // Call function to implement Obex Server |
|
125 if (err != KErrNone) |
|
126 { |
|
127 iState = EUsbServiceFatalError; |
|
128 User::RequestComplete(status, err); |
|
129 } |
|
130 else |
|
131 { |
|
132 iState = EUsbServiceStarted; |
|
133 User::RequestComplete(status,KErrNone); |
|
134 } |
|
135 } |
|
136 |
|
137 } |
|
138 |
|
139 /** |
|
140 * Called by UsbMan when it wants to stop the USB Obex class. |
|
141 * Data member from RSessionBase implements a Stop call on |
|
142 * the Obex Server process. |
|
143 * |
|
144 * @param aStatus The caller's request status: always set to KErrNone |
|
145 */ |
|
146 void CUsbObexClassController::Stop(TRequestStatus& aStatus) |
|
147 { |
|
148 |
|
149 //Stop() should never be called if stopping, idle or starting (or in state EUsbServiceFatalError) |
|
150 __ASSERT_DEBUG( iState == EUsbServiceStarted, User::Panic(KObexCcPanicCategory, EBadApiCallStop) ); |
|
151 |
|
152 TRequestStatus* status = &aStatus; |
|
153 TInt err; |
|
154 iState = EUsbServiceStopping; |
|
155 |
|
156 err = iClassContClient.StopService(); |
|
157 if (err != KErrNone) |
|
158 { |
|
159 iState = EUsbServiceFatalError; |
|
160 User::RequestComplete(status, err); |
|
161 } |
|
162 else |
|
163 { |
|
164 iState = EUsbServiceIdle; |
|
165 User::RequestComplete(status, KErrNone); |
|
166 } |
|
167 |
|
168 } |
|
169 |
|
170 /** |
|
171 * Gets information about the descriptor which this class provides. |
|
172 * |
|
173 * @param aDescriptorInfo Descriptor info structure filled in by this function |
|
174 */ |
|
175 void CUsbObexClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const |
|
176 { |
|
177 aDescriptorInfo.iNumInterfaces = KNumObexInterfaces; |
|
178 aDescriptorInfo.iLength = KObexDescriptorLength; |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 /** |
|
184 * Standard active object RunL. Never called because this class has no |
|
185 * asynchronous requests. As it is never called, function causes a panic. |
|
186 */ |
|
187 void CUsbObexClassController::RunL() |
|
188 { |
|
189 __ASSERT_DEBUG(EFalse, User::Panic(KObexCcPanicCategory, EUnusedFunction)); |
|
190 } |
|
191 |
|
192 /** |
|
193 * Standard active object cancellation function. Never called because this |
|
194 * class has no asynchronous requests. As it is never called, function causes a panic. |
|
195 */ |
|
196 void CUsbObexClassController::DoCancel() |
|
197 { |
|
198 __ASSERT_DEBUG(EFalse, User::Panic(KObexCcPanicCategory, EUnusedFunction)); |
|
199 } |
|
200 |
|
201 |
|
202 /** |
|
203 * Standard active object error-handling function. |
|
204 * |
|
205 * Should return KErrNone to avoid an active scheduler panic. This function |
|
206 * should never be called as there is another mechanism for catching errors. |
|
207 */ |
|
208 TInt CUsbObexClassController::RunError(TInt /*aError*/) |
|
209 { |
|
210 __ASSERT_DEBUG(EFalse, User::Panic(KObexCcPanicCategory, EUnusedFunction)); |
|
211 return KErrNone; |
|
212 } |
|
213 |
|
214 |