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 "cusbvbusobserver.h" |
20 #include "cusbvbusobserver.h" |
22 |
21 |
38 // |
37 // |
39 // --------------------------------------------------------------------------- |
38 // --------------------------------------------------------------------------- |
40 // |
39 // |
41 void CUsbVBusObserver::ConstructL() |
40 void CUsbVBusObserver::ConstructL() |
42 { |
41 { |
43 |
42 LOG_FUNC |
44 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::ConstructL" ) ); |
|
45 |
43 |
46 User::LeaveIfError(iVBus.Attach(KUidUsbManCategory, |
44 User::LeaveIfError(iVBus.Attach(KUidUsbManCategory, |
47 KUsbOtgVBusPoweredProperty)); |
45 KUsbOtgVBusPoweredProperty)); |
48 |
46 |
49 } |
47 } |
52 // |
50 // |
53 // --------------------------------------------------------------------------- |
51 // --------------------------------------------------------------------------- |
54 // |
52 // |
55 CUsbVBusObserver* CUsbVBusObserver::NewL() |
53 CUsbVBusObserver* CUsbVBusObserver::NewL() |
56 { |
54 { |
57 |
55 LOG_FUNC |
58 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::NewL" ) ); |
|
59 |
56 |
60 CUsbVBusObserver* self = new (ELeave) CUsbVBusObserver(); |
57 CUsbVBusObserver* self = new (ELeave) CUsbVBusObserver(); |
61 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
62 self->ConstructL(); |
59 self->ConstructL(); |
63 CleanupStack::Pop(self); |
60 CleanupStack::Pop(self); |
86 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
87 // |
83 // |
88 CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const */ |
84 CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const */ |
89 { |
85 { |
90 |
86 |
91 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus" ) ); |
|
92 |
|
93 TInt val(0); |
87 TInt val(0); |
94 |
88 |
95 TInt err = iVBus.Get(val); |
89 TInt err = iVBus.Get(val); |
96 |
90 |
97 if (KErrNone != err) |
91 if (KErrNone != err) |
98 { |
92 { |
99 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus CanNotGetVBusProperty" ) ); |
93 LOG("CanNotGetVBusProperty" ) |
100 Panic(ECanNotGetVBusProperty); |
94 Panic( ECanNotGetVBusProperty); |
101 } |
95 } |
102 |
|
103 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus = %d" ), val )); |
|
104 |
96 |
105 return (0 == val ? EVBusDown : EVBusUp); |
97 return (0 == val ? EVBusDown : EVBusUp); |
106 } |
98 } |
107 |
99 |
108 // --------------------------------------------------------------------------- |
100 // --------------------------------------------------------------------------- |
109 // |
101 // |
110 // --------------------------------------------------------------------------- |
102 // --------------------------------------------------------------------------- |
111 // |
103 // |
112 void CUsbVBusObserver::SubscribeL(MUsbVBusObserver& aObserver) |
104 void CUsbVBusObserver::SubscribeL(MUsbVBusObserver& aObserver) |
113 { |
105 { |
114 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL" ) ); |
106 LOG_FUNC |
115 |
107 |
116 // check if the same observer already exist in a list |
108 // check if the same observer already exist in a list |
117 if(KErrNotFound != iObservers.Find(&aObserver)) |
109 if (KErrNotFound != iObservers.Find(&aObserver)) |
118 { |
110 { |
119 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL Observer already exists." ) ); |
111 LOG( "Observer already exists" ); |
120 Panic(EObserverAlreadyExists); |
112 Panic( EObserverAlreadyExists); |
121 return; |
113 return; |
122 } |
114 } |
123 |
115 |
124 iObservers.AppendL(&aObserver); |
116 iObservers.AppendL(&aObserver); |
125 |
117 |
126 if (KFirst == iObservers.Count()) // first item |
118 if (KFirst == iObservers.Count()) // first item |
127 { |
119 { |
128 iVBus.Subscribe(iStatus); |
120 iVBus.Subscribe(iStatus); |
129 SetActive(); |
121 SetActive(); |
130 } |
122 } |
134 // |
126 // |
135 // --------------------------------------------------------------------------- |
127 // --------------------------------------------------------------------------- |
136 // |
128 // |
137 void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver& aObserver) |
129 void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver& aObserver) |
138 { |
130 { |
139 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL" ) ); |
131 LOG_FUNC |
140 |
132 |
141 TInt i(iObservers.Find(&aObserver)); |
133 TInt i(iObservers.Find(&aObserver)); |
142 if(KErrNotFound == i) |
134 if (KErrNotFound == i) |
143 { |
135 { |
144 FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL Observer not found." ) ); |
136 LOG("Observer not found" ); |
145 Panic(ECanNotFindVBusObserver); |
137 Panic( ECanNotFindVBusObserver); |
146 return; |
138 return; |
147 } |
139 } |
148 |
140 |
149 iObservers.Remove(i); |
141 iObservers.Remove(i); |
150 |
142 |
151 if (0 == iObservers.Count()) // no observers anymore |
143 if (0 == iObservers.Count()) // no observers anymore |
152 { |
144 { |
153 // cancel pending request, if any |
145 // cancel pending request, if any |
154 Cancel(); |
146 Cancel(); |
155 } |
147 } |
159 // |
151 // |
160 // --------------------------------------------------------------------------- |
152 // --------------------------------------------------------------------------- |
161 // |
153 // |
162 void CUsbVBusObserver::RunL() |
154 void CUsbVBusObserver::RunL() |
163 { |
155 { |
164 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::RunL iStatus = %d" ), iStatus.Int())); |
156 LOG_FUNC |
165 |
157 |
166 // if error occured, tell to Observers |
158 LOG1( "iStatus = %d" , iStatus.Int()); |
167 if(KErrNone != iStatus.Int()) |
159 |
168 { |
160 // if error occured, tell to Observers |
169 for (TInt i(0); i < iObservers.Count(); ++i) |
161 if (KErrNone != iStatus.Int()) |
170 { |
162 { |
171 iObservers[i]->VBusObserverErrorL(iStatus.Int()); |
163 for (TInt i(0); i < iObservers.Count(); ++i) |
172 } |
164 { |
173 return; |
165 iObservers[i]->VBusObserverErrorL(iStatus.Int()); |
174 } |
166 } |
|
167 return; |
|
168 } |
175 |
169 |
176 // re-issue request first |
170 // re-issue request first |
177 iVBus.Subscribe(iStatus); |
171 iVBus.Subscribe(iStatus); |
178 SetActive(); |
172 SetActive(); |
179 |
173 |