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