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 |
|
104 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin = %d" ), val )); |
|
105 |
97 |
106 return (EFalse == val ? EIdPinOff : EIdPinOn); |
98 return (EFalse == val ? EIdPinOff : EIdPinOn); |
107 } |
99 } |
108 |
100 |
109 // --------------------------------------------------------------------------- |
101 // --------------------------------------------------------------------------- |
110 // |
102 // |
111 // --------------------------------------------------------------------------- |
103 // --------------------------------------------------------------------------- |
112 // |
104 // |
113 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver) |
105 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver) |
114 { |
106 { |
115 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL" ) ); |
107 LOG_FUNC |
|
108 |
116 // check if the same observer already exist in a list |
109 // check if the same observer already exist in a list |
117 if(KErrNotFound != iObservers.Find(&aObserver)) |
110 if (KErrNotFound != iObservers.Find(&aObserver)) |
118 { |
111 { |
119 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) ); |
112 LOG("Observer already exists" ); |
120 Panic(EObserverAlreadyExists); |
113 Panic( EObserverAlreadyExists); |
121 return; |
114 return; |
122 } |
115 } |
123 iObservers.AppendL(&aObserver); |
116 iObservers.AppendL(&aObserver); |
124 |
117 |
125 if (KFirst == iObservers.Count()) // first item |
118 if (KFirst == iObservers.Count()) // first item |
134 // |
127 // |
135 // --------------------------------------------------------------------------- |
128 // --------------------------------------------------------------------------- |
136 // |
129 // |
137 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver) |
130 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver) |
138 { |
131 { |
139 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL" ) ); |
132 LOG_FUNC |
140 |
133 |
141 TInt i(iObservers.Find(&aObserver)); |
134 TInt i(iObservers.Find(&aObserver)); |
142 if(KErrNotFound == i) |
135 if (KErrNotFound == i) |
143 { |
136 { |
144 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) ); |
137 LOG("Observer not found"); |
145 Panic(ECanNotFindIdPinObserver); |
138 Panic( ECanNotFindIdPinObserver); |
146 return; |
139 return; |
147 } |
140 } |
148 |
141 |
149 iObservers.Remove(i); |
142 iObservers.Remove(i); |
150 |
143 |
151 if (0 == iObservers.Count()) // no observers anymore |
144 if (0 == iObservers.Count()) // no observers anymore |
152 { |
145 { |
153 // cancel pending request |
146 // cancel pending request |
154 Cancel(); |
147 Cancel(); |
155 } |
148 } |
159 // |
152 // |
160 // --------------------------------------------------------------------------- |
153 // --------------------------------------------------------------------------- |
161 // |
154 // |
162 void CUsbIdPinObserver::RunL() |
155 void CUsbIdPinObserver::RunL() |
163 { |
156 { |
164 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL iStatus = %d" ), iStatus.Int())); |
157 LOG_FUNC |
165 |
158 |
166 // if error occured, tell to Observers |
159 LOG1( "iStatus = %d" , iStatus.Int()); |
167 if(KErrNone != iStatus.Int()) |
160 |
168 { |
161 // if error occured, tell to Observers |
169 for (TInt i(0); i < iObservers.Count(); ++i) |
162 if (KErrNone != iStatus.Int()) |
170 { |
163 { |
171 iObservers[i]->IdPinErrorL(iStatus.Int()); |
164 for (TInt i(0); i < iObservers.Count(); ++i) |
172 } |
165 { |
173 return; |
166 iObservers[i]->IdPinErrorL(iStatus.Int()); |
174 } |
167 } |
|
168 return; |
|
169 } |
175 |
170 |
176 // re-issue request first |
171 // re-issue request first |
177 iIdPin.Subscribe(iStatus); |
172 iIdPin.Subscribe(iStatus); |
178 SetActive(); |
173 SetActive(); |
179 |
174 |