1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of the License "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 |
20 |
21 #include "cusbotg.h" |
21 #include "cusbotg.h" |
22 #include "cusbotgwatcher.h" |
22 #include "cusbotgwatcher.h" |
23 #include "rusbmspublisher.h" |
23 #include "rusbmspublisher.h" |
24 |
24 |
25 |
|
26 #include "tmslog.h" |
|
27 #include "debug.h" |
25 #include "debug.h" |
28 |
26 |
29 _LIT(KOtgdiLddFileName, "otgdi"); |
27 _LIT(KOtgdiLddFileName, "otgdi"); |
30 |
28 |
31 |
29 |
32 ROtgStateChangeNotifier::ROtgStateChangeNotifier() |
30 ROtgStateChangeNotifier::ROtgStateChangeNotifier() |
33 : iRegistered(EFalse) |
31 : iRegistered(EFalse) |
34 { |
32 { |
35 __MSFNSLOG |
|
36 } |
33 } |
37 |
34 |
38 |
35 |
39 ROtgStateChangeNotifier::~ROtgStateChangeNotifier() |
36 ROtgStateChangeNotifier::~ROtgStateChangeNotifier() |
40 { |
37 { |
41 __MSFNSLOG |
|
42 if (iRegistered) |
38 if (iRegistered) |
43 iMessage.Complete(KErrDisconnected); |
39 iMessage.Complete(KErrDisconnected); |
44 } |
40 } |
45 |
41 |
46 /** |
42 /** |
48 |
44 |
49 @param aMessage The message to commplete the notification |
45 @param aMessage The message to commplete the notification |
50 */ |
46 */ |
51 void ROtgStateChangeNotifier::Register(const RMessage2& aMessage) |
47 void ROtgStateChangeNotifier::Register(const RMessage2& aMessage) |
52 { |
48 { |
53 __MSFNLOG |
49 iRegistered = ETrue; |
54 iRegistered = ETrue; |
50 iMessage = aMessage; |
55 iMessage = aMessage; |
|
56 } |
51 } |
57 |
52 |
58 |
53 |
59 void ROtgStateChangeNotifier::DoNotifyL() |
54 void ROtgStateChangeNotifier::DoNotifyL() |
60 { |
55 { |
61 __MSFNLOG |
56 CompleteNotifierL(KErrNone); |
62 CompleteNotifierL(KErrNone); |
|
63 } |
57 } |
64 |
58 |
65 |
59 |
66 void ROtgStateChangeNotifier::DoCancelL() |
60 void ROtgStateChangeNotifier::DoCancelL() |
67 { |
61 { |
68 __MSFNLOG |
62 CompleteNotifierL(KErrCancel); |
69 CompleteNotifierL(KErrCancel); |
|
70 } |
63 } |
71 |
64 |
72 |
65 |
73 void ROtgStateChangeNotifier::CompleteNotifierL(TInt aReason) |
66 void ROtgStateChangeNotifier::CompleteNotifierL(TInt aReason) |
74 { |
67 { |
75 __MSFNLOG |
68 if (iRegistered) |
76 if (iRegistered) |
69 { |
77 { |
70 TBool changed = ETrue; |
78 TBool changed = ETrue; |
|
79 TPckgBuf<TBool> p(changed); |
71 TPckgBuf<TBool> p(changed); |
80 iMessage.WriteL(0, p); |
72 iMessage.WriteL(0, p); |
81 iMessage.Complete(aReason); |
73 iMessage.Complete(aReason); |
82 iRegistered = EFalse; |
74 iRegistered = EFalse; |
83 } |
75 } |
84 } |
76 } |
85 |
77 |
86 |
78 |
87 CUsbOtg* CUsbOtg::NewL() |
79 CUsbOtg* CUsbOtg::NewL() |
88 { |
80 { |
89 __MSFNSLOG |
81 CUsbOtg* self = new (ELeave) CUsbOtg(); |
90 CUsbOtg* self = new (ELeave) CUsbOtg(); |
82 CleanupStack::PushL(self); |
91 CleanupStack::PushL(self); |
83 self->ConstructL(); |
92 self->ConstructL(); |
84 CleanupStack::Pop(self); |
93 CleanupStack::Pop(self); |
85 return self; |
94 return self; |
86 } |
95 } |
|
96 |
87 |
97 |
88 |
98 void CUsbOtg::ConstructL() |
89 void CUsbOtg::ConstructL() |
99 { |
90 { |
100 __MSFNLOG |
|
101 |
91 |
102 TInt r = User::LoadLogicalDevice(KOtgdiLddFileName); |
92 TInt r = User::LoadLogicalDevice(KOtgdiLddFileName); |
103 |
93 |
104 if (r != KErrNone && r != KErrAlreadyExists) |
94 if (r != KErrNone && r != KErrAlreadyExists) |
105 { |
95 { |
124 User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
114 User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
125 User::Leave(r); |
115 User::Leave(r); |
126 } |
116 } |
127 |
117 |
128 __USBOTGPRINT(_L(" otg stacks successfully started")); |
118 __USBOTGPRINT(_L(" otg stacks successfully started")); |
129 } |
119 } |
130 |
120 |
131 |
121 |
132 CUsbOtg::CUsbOtg() |
122 CUsbOtg::CUsbOtg() |
133 : iOtgState(KOtgStateStart) |
123 : iOtgState(KOtgStateStart) |
134 { |
124 { |
135 __MSFNLOG |
|
136 } |
125 } |
137 |
126 |
138 |
127 |
139 CUsbOtg::~CUsbOtg() |
128 CUsbOtg::~CUsbOtg() |
140 { |
129 { |
141 __MSFNLOG |
|
142 Stop(); |
130 Stop(); |
143 |
131 |
144 TInt r = iUsbOtgDriver.BusDrop(); |
132 TInt r = iUsbOtgDriver.BusDrop(); |
145 |
133 |
146 // Unload OTGDI components if it was ever started |
134 // Unload OTGDI components if it was ever started |
151 iUsbOtgDriver.Close(); |
139 iUsbOtgDriver.Close(); |
152 |
140 |
153 } |
141 } |
154 |
142 |
155 TInt err = User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
143 TInt err = User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
156 } |
144 } |
157 |
145 |
158 |
146 |
159 void CUsbOtg::StartL() |
147 void CUsbOtg::StartL() |
160 { |
148 { |
161 __MSFNLOG |
149 // Request Otg notifications |
162 // Request Otg notifications |
|
163 iOtgEventWatcher = CUsbOtgEventWatcher::NewL(iUsbOtgDriver, *this); |
150 iOtgEventWatcher = CUsbOtgEventWatcher::NewL(iUsbOtgDriver, *this); |
164 iOtgEventWatcher->Start(); |
151 iOtgEventWatcher->Start(); |
165 |
152 |
166 iRequestSessionWatcher = CRequestSessionWatcher::NewL(*this); |
153 iRequestSessionWatcher = CRequestSessionWatcher::NewL(*this); |
167 } |
154 } |
168 |
155 |
169 |
156 |
170 void CUsbOtg::Stop() |
157 void CUsbOtg::Stop() |
171 /** |
158 /** |
172 * Stop the USB OTG events watcher |
159 * Stop the USB OTG events watcher |
173 */ |
160 */ |
174 { |
161 { |
175 __MSFNLOG |
|
176 |
|
177 if (iOtgEventWatcher) |
162 if (iOtgEventWatcher) |
178 { |
163 { |
179 iOtgEventWatcher->Cancel(); |
164 iOtgEventWatcher->Cancel(); |
180 delete iOtgEventWatcher; |
165 delete iOtgEventWatcher; |
181 iOtgEventWatcher = NULL; |
166 iOtgEventWatcher = NULL; |
243 } |
225 } |
244 |
226 |
245 |
227 |
246 TBool CUsbOtg::DeviceInserted() |
228 TBool CUsbOtg::DeviceInserted() |
247 { |
229 { |
248 __MSFNLOG |
|
249 return iOtgState == KOtgStateAPlugInserted ? ETrue : EFalse; |
230 return iOtgState == KOtgStateAPlugInserted ? ETrue : EFalse; |
250 } |
231 } |
251 |
232 |
252 void CUsbOtg::NotifyChange(const RMessage2& aMessage) |
233 void CUsbOtg::NotifyChange(const RMessage2& aMessage) |
253 { |
234 { |
254 __MSFNLOG |
|
255 iNotifier.Register(aMessage); |
235 iNotifier.Register(aMessage); |
256 } |
236 } |
257 |
237 |
258 |
238 |
259 void CUsbOtg::NotifyChangeCancel() |
239 void CUsbOtg::NotifyChangeCancel() |
260 { |
240 { |
261 __MSFNLOG |
|
262 iNotifier.DoCancelL(); |
241 iNotifier.DoCancelL(); |
263 } |
242 } |
264 |
243 |
265 |
244 |
266 TInt CUsbOtg::BusDrop() |
245 TInt CUsbOtg::BusDrop() |
267 { |
246 { |
268 __MSFNLOG |
|
269 return iUsbOtgDriver.BusDrop(); |
247 return iUsbOtgDriver.BusDrop(); |
270 } |
248 } |