equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Implementation |
14 * Description: Implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
|
18 |
17 |
19 #include <usbotgdefs.h> |
18 #include <usbotgdefs.h> |
20 |
19 |
21 #include "cusbbusactivityobserver.h" |
20 #include "cusbbusactivityobserver.h" |
22 |
21 |
38 // |
37 // |
39 // --------------------------------------------------------------------------- |
38 // --------------------------------------------------------------------------- |
40 // |
39 // |
41 void CUsbBusActivityObserver::ConstructL() |
40 void CUsbBusActivityObserver::ConstructL() |
42 { |
41 { |
43 |
42 LOG_FUNC |
44 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::ConstructL" ) ); |
|
45 |
43 |
46 User::LeaveIfError(iBusActivity.Attach(KUidUsbManCategory, |
44 User::LeaveIfError(iBusActivity.Attach(KUidUsbManCategory, |
47 KUsbOtgConnectionIdleProperty)); |
45 KUsbOtgConnectionIdleProperty)); |
48 |
46 |
49 } |
47 } |
52 // |
50 // |
53 // --------------------------------------------------------------------------- |
51 // --------------------------------------------------------------------------- |
54 // |
52 // |
55 CUsbBusActivityObserver* CUsbBusActivityObserver::NewL() |
53 CUsbBusActivityObserver* CUsbBusActivityObserver::NewL() |
56 { |
54 { |
57 |
55 LOG_FUNC |
58 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::NewL" ) ); |
|
59 |
56 |
60 CUsbBusActivityObserver* self = new (ELeave) CUsbBusActivityObserver(); |
57 CUsbBusActivityObserver* self = new (ELeave) CUsbBusActivityObserver(); |
61 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
62 self->ConstructL(); |
59 self->ConstructL(); |
63 CleanupStack::Pop(self); |
60 CleanupStack::Pop(self); |
69 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
70 // |
67 // |
71 CUsbBusActivityObserver::~CUsbBusActivityObserver() |
68 CUsbBusActivityObserver::~CUsbBusActivityObserver() |
72 |
69 |
73 { |
70 { |
74 |
71 LOG_FUNC |
75 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::~CUsbBusActivityObserver" ) ); |
|
76 |
72 |
77 Cancel(); |
73 Cancel(); |
78 |
74 |
79 iBusActivity.Close(); |
75 iBusActivity.Close(); |
80 |
76 |
93 |
89 |
94 TInt err = iBusActivity.Get(val); |
90 TInt err = iBusActivity.Get(val); |
95 |
91 |
96 if (KErrNone != err) |
92 if (KErrNone != err) |
97 { |
93 { |
98 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::BusActivity CanNotGetBusActivityProperty" ) ); |
94 LOG("ECanNotGetBusActivityProperty" ); |
99 Panic(ECanNotGetBusActivityProperty); |
95 Panic( ECanNotGetBusActivityProperty); |
100 } |
96 } |
101 |
|
102 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::State = %d" ), val )); |
|
103 |
97 |
104 return (0 == val ? EBusActive : EBusIdle); |
98 return (0 == val ? EBusActive : EBusIdle); |
105 |
99 |
106 } |
100 } |
107 |
101 |
109 // |
103 // |
110 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
111 // |
105 // |
112 void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver& aObserver) |
106 void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver& aObserver) |
113 { |
107 { |
114 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::SubscribeL" ) ); |
108 LOG_FUNC |
|
109 |
115 // check if the same observer already exist in a list |
110 // check if the same observer already exist in a list |
116 if(KErrNotFound != iObservers.Find(&aObserver)) |
111 if (KErrNotFound != iObservers.Find(&aObserver)) |
117 { |
112 { |
118 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) ); |
113 LOG( "Observer already exists" ); |
119 Panic(EObserverAlreadyExists); |
114 Panic( EObserverAlreadyExists); |
120 return; |
115 return; |
121 } |
116 } |
122 iObservers.AppendL(&aObserver); |
117 iObservers.AppendL(&aObserver); |
123 |
118 |
124 if (KFirst == iObservers.Count()) // first item |
119 if (KFirst == iObservers.Count()) // first item |
133 // |
128 // |
134 // --------------------------------------------------------------------------- |
129 // --------------------------------------------------------------------------- |
135 // |
130 // |
136 void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver& aObserver) |
131 void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver& aObserver) |
137 { |
132 { |
138 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL" ) ); |
133 LOG_FUNC |
139 |
134 |
140 TInt i(iObservers.Find(&aObserver)); |
135 TInt i(iObservers.Find(&aObserver)); |
141 if(KErrNotFound == i) |
136 if (KErrNotFound == i) |
142 { |
137 { |
143 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL Observer not found." ) ); |
138 LOG( "Observer not found" ); |
144 Panic(ECanNotFindIdPinObserver); |
139 Panic( ECanNotFindBusActivityObserver); |
145 return; |
140 return; |
146 } |
141 } |
147 |
142 |
148 iObservers.Remove(i); |
143 iObservers.Remove(i); |
149 |
144 |
150 if (0 == iObservers.Count()) // no observers anymore |
145 if (0 == iObservers.Count()) // no observers anymore |
151 { |
146 { |
152 // cancel pending request |
147 // cancel pending request |
153 Cancel(); |
148 Cancel(); |
154 } |
149 } |
158 |
153 |
159 // --------------------------------------------------------------------------- |
154 // --------------------------------------------------------------------------- |
160 // |
155 // |
161 void CUsbBusActivityObserver::RunL() |
156 void CUsbBusActivityObserver::RunL() |
162 { |
157 { |
163 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL iStatus = %d" ), iStatus.Int())); |
158 LOG_FUNC |
|
159 |
|
160 LOG1( "iStatus = %d" , iStatus.Int()); |
164 |
161 |
165 // if error occured, inform observers |
162 // if error occured, inform observers |
166 if(KErrNone != iStatus.Int()) |
163 if (KErrNone != iStatus.Int()) |
167 { |
164 { |
168 for (TInt i(0); i < iObservers.Count(); ++i) |
165 for (TInt i(0); i < iObservers.Count(); ++i) |
169 { |
166 { |
170 iObservers[i]->BusActivityErrorL(iStatus.Int()); |
167 iObservers[i]->BusActivityErrorL(iStatus.Int()); |
171 } |
168 } |
172 } |
169 } |
173 |
170 |
174 // re-issue request first |
171 // re-issue request first |
175 iBusActivity.Subscribe(iStatus); |
172 iBusActivity.Subscribe(iStatus); |
176 SetActive(); |
173 SetActive(); |
180 |
177 |
181 switch (state) |
178 switch (state) |
182 { |
179 { |
183 case EBusIdle: |
180 case EBusIdle: |
184 { |
181 { |
185 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusIdle" ) ); |
182 LOG("BusIdle"); |
186 |
183 |
187 for (TInt i(0); i < iObservers.Count(); ++i) |
184 for (TInt i(0); i < iObservers.Count(); ++i) |
188 { |
185 { |
189 iObservers[i]->BusIdleL(); |
186 iObservers[i]->BusIdleL(); |
190 } |
187 } |
191 break; |
188 break; |
192 } |
189 } |
193 |
190 |
194 case EBusActive: |
191 case EBusActive: |
195 { |
192 { |
196 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusActive" ) ); |
193 LOG("BusActive"); |
197 |
194 |
198 for (TInt i(0); i < iObservers.Count(); ++i) |
195 for (TInt i(0); i < iObservers.Count(); ++i) |
199 { |
196 { |
200 iObservers[i]->BusActiveL(); |
197 iObservers[i]->BusActiveL(); |
201 } |
198 } |
202 break; |
199 break; |
203 } |
200 } |
204 |
201 |
205 default: |
202 default: |
206 { |
203 { |
207 FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusActive WrongBusState" ) ); |
204 LOG("WrongBusState" ); |
208 Panic(EWrongBusState); |
205 Panic( EWrongBusState); |
209 } |
206 } |
210 } |
207 } |
211 |
208 |
212 } |
209 } |
213 |
210 |
224 // |
221 // |
225 // --------------------------------------------------------------------------- |
222 // --------------------------------------------------------------------------- |
226 // |
223 // |
227 TInt CUsbBusActivityObserver::RunError(TInt aError) |
224 TInt CUsbBusActivityObserver::RunError(TInt aError) |
228 { |
225 { |
229 |
226 LOG_FUNC |
230 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunError aError = %d" ), aError)); |
227 |
231 |
228 LOG1( "aError = %d", aError ); |
|
229 |
232 // try to continue |
230 // try to continue |
233 return KErrNone; |
231 return KErrNone; |
234 |
232 |
235 } |
233 } |
236 |
234 |