|
1 /* |
|
2 * Copyright (c) 2008-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 * |
|
16 */ |
|
17 |
|
18 #include "cusbhost.h" |
|
19 #include <usb/usblogger.h> |
|
20 |
|
21 |
|
22 #ifdef __FLOG_ACTIVE |
|
23 _LIT8(KLogComponent, "usbhost"); |
|
24 #endif |
|
25 |
|
26 CUsbHost* CUsbHost::iInstance = 0; |
|
27 |
|
28 CUsbHost* CUsbHost::NewL() |
|
29 { |
|
30 if(iInstance == 0) |
|
31 { |
|
32 iInstance = new (ELeave) CUsbHost(); |
|
33 CleanupStack::PushL(iInstance); |
|
34 iInstance->ConstructL(); |
|
35 CleanupStack::Pop(iInstance); |
|
36 } |
|
37 return iInstance; |
|
38 } |
|
39 |
|
40 CUsbHost::~CUsbHost() |
|
41 { |
|
42 LOG_FUNC |
|
43 |
|
44 Stop(); |
|
45 |
|
46 TInt i =0; |
|
47 for(i=0;i<ENumMonitor;i++) |
|
48 { |
|
49 delete iUsbHostWatcher[i]; |
|
50 iUsbHostWatcher[i] = NULL; |
|
51 } |
|
52 iObservers.Close(); |
|
53 iInstance = 0; |
|
54 } |
|
55 |
|
56 CUsbHost::CUsbHost() |
|
57 { |
|
58 LOG_FUNC |
|
59 } |
|
60 |
|
61 void CUsbHost::ConstructL() |
|
62 { |
|
63 LOG_FUNC |
|
64 |
|
65 iUsbHostWatcher[EHostEventMonitor] = |
|
66 CActiveUsbHostEventWatcher::NewL(iUsbHostStack,*this,iHostEventInfo); |
|
67 iUsbHostWatcher[EHostMessageMonitor] = |
|
68 CActiveUsbHostMessageWatcher::NewL(iUsbHostStack,*this,iHostMessage); |
|
69 } |
|
70 void CUsbHost::StartL() |
|
71 { |
|
72 LOG_FUNC |
|
73 |
|
74 if(!iHasBeenStarted) |
|
75 { |
|
76 |
|
77 LEAVEIFERRORL(iUsbHostStack.Connect()); |
|
78 |
|
79 for(TInt i=0;i<ENumMonitor;i++) |
|
80 { |
|
81 iUsbHostWatcher[i]->Post(); |
|
82 } |
|
83 iHasBeenStarted = ETrue; |
|
84 } |
|
85 } |
|
86 |
|
87 void CUsbHost::Stop() |
|
88 { |
|
89 LOG_FUNC |
|
90 |
|
91 TInt i=0; |
|
92 for(i=0;i<ENumMonitor;i++) |
|
93 { |
|
94 if (iUsbHostWatcher[i]) |
|
95 { |
|
96 iUsbHostWatcher[i]->Cancel(); |
|
97 } |
|
98 } |
|
99 |
|
100 iUsbHostStack.Close(); |
|
101 |
|
102 iHasBeenStarted = EFalse; |
|
103 } |
|
104 |
|
105 void CUsbHost::RegisterObserverL(MUsbOtgHostNotifyObserver& aObserver) |
|
106 { |
|
107 LOG_FUNC |
|
108 |
|
109 iObservers.AppendL(&aObserver); |
|
110 UpdateNumOfObservers(); |
|
111 } |
|
112 |
|
113 void CUsbHost::DeregisterObserver(MUsbOtgHostNotifyObserver& aObserver) |
|
114 { |
|
115 LOG_FUNC |
|
116 TInt index = iObservers.Find(&aObserver); |
|
117 if(index == KErrNotFound) |
|
118 { |
|
119 LOGTEXT(_L8("\t Cannot remove observer, not found")); |
|
120 } |
|
121 else |
|
122 { |
|
123 iObservers.Remove(index); |
|
124 } |
|
125 |
|
126 UpdateNumOfObservers(); |
|
127 } |
|
128 |
|
129 TInt CUsbHost::GetSupportedLanguages(TUint aDeviceId,RArray<TUint>& aLangIds) |
|
130 { |
|
131 LOG_FUNC |
|
132 TInt err = KErrNone; |
|
133 if ( iUsbHostStack.Handle() ) |
|
134 { |
|
135 err = iUsbHostStack.GetSupportedLanguages(aDeviceId,aLangIds); |
|
136 } |
|
137 else |
|
138 { |
|
139 err = KErrBadHandle; |
|
140 } |
|
141 return err; |
|
142 } |
|
143 |
|
144 TInt CUsbHost::GetManufacturerStringDescriptor(TUint aDeviceId,TUint aLangId,TName& aString) |
|
145 { |
|
146 LOG_FUNC |
|
147 TInt err = KErrNone; |
|
148 if ( iUsbHostStack.Handle() ) |
|
149 { |
|
150 err = iUsbHostStack.GetManufacturerStringDescriptor(aDeviceId,aLangId,aString); |
|
151 } |
|
152 else |
|
153 { |
|
154 err = KErrBadHandle; |
|
155 } |
|
156 return err; |
|
157 } |
|
158 |
|
159 TInt CUsbHost::GetProductStringDescriptor(TUint aDeviceId,TUint aLangId,TName& aString) |
|
160 { |
|
161 LOG_FUNC |
|
162 TInt err = KErrNone; |
|
163 if ( iUsbHostStack.Handle() ) |
|
164 { |
|
165 err = iUsbHostStack.GetProductStringDescriptor(aDeviceId,aLangId,aString); |
|
166 } |
|
167 else |
|
168 { |
|
169 err = KErrBadHandle; |
|
170 } |
|
171 return err; |
|
172 } |
|
173 |
|
174 TInt CUsbHost::GetOtgDescriptor(TUint aDeviceId, TOtgDescriptor& otgDescriptor) |
|
175 { |
|
176 LOG_FUNC |
|
177 |
|
178 TInt err(KErrNone); |
|
179 |
|
180 if (iUsbHostStack.Handle()) |
|
181 { |
|
182 err = iUsbHostStack.GetOtgDescriptor(aDeviceId, otgDescriptor); |
|
183 } |
|
184 else |
|
185 { |
|
186 err = KErrBadHandle; |
|
187 } |
|
188 |
|
189 return err; |
|
190 } |
|
191 |
|
192 void CUsbHost::NotifyHostEvent(TUint aWatcherId) |
|
193 { |
|
194 LOG_FUNC |
|
195 if(aWatcherId == EHostEventMonitor) |
|
196 { |
|
197 |
|
198 LOGTEXT2(_L8("\t Device id %d"),iHostEventInfo.iDeviceId); |
|
199 LOGTEXT2(_L8("\t iEventType %d"),iHostEventInfo.iEventType); |
|
200 LOGTEXT2(_L8("\t TDriverLoadStatus %d"),iHostEventInfo.iDriverLoadStatus); |
|
201 LOGTEXT2(_L8("\t VID %d"),iHostEventInfo.iVid); |
|
202 LOGTEXT2(_L8("\t PID %d"),iHostEventInfo.iPid); |
|
203 |
|
204 for(TUint i=0;i<iNumOfObservers;i++) |
|
205 { |
|
206 iObservers[i]->UsbHostEvent(iHostEventInfo); |
|
207 } |
|
208 } |
|
209 else |
|
210 { |
|
211 LOGTEXT2(_L8("\t Host Message %d"),iHostMessage); |
|
212 |
|
213 for(TUint i=0;i<iNumOfObservers;i++) |
|
214 { |
|
215 iObservers[i]->UsbOtgHostMessage(iHostMessage); |
|
216 } |
|
217 } |
|
218 } |
|
219 |
|
220 void CUsbHost::UpdateNumOfObservers() |
|
221 { |
|
222 LOG_FUNC |
|
223 iNumOfObservers = iObservers.Count(); |
|
224 } |
|
225 |
|
226 TInt CUsbHost::EnableDriverLoading() |
|
227 { |
|
228 LOG_FUNC |
|
229 TInt err = KErrNone; |
|
230 if ( iUsbHostStack.Handle() ) |
|
231 { |
|
232 err = iUsbHostStack.EnableDriverLoading(); |
|
233 } |
|
234 else |
|
235 { |
|
236 err = KErrBadHandle; |
|
237 } |
|
238 return err; |
|
239 } |
|
240 |
|
241 void CUsbHost::DisableDriverLoading() |
|
242 { |
|
243 LOG_FUNC |
|
244 if ( iUsbHostStack.Handle() ) |
|
245 { |
|
246 iUsbHostStack.DisableDriverLoading(); |
|
247 } |
|
248 } |