35
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <usbotgdefs.h>
|
|
19 |
|
|
20 |
#include "cusbidpinobserver.h"
|
|
21 |
|
|
22 |
#include "definitions.h"
|
|
23 |
#include "debug.h"
|
|
24 |
#include "panic.h"
|
|
25 |
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
//
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
CUsbIdPinObserver::CUsbIdPinObserver() :
|
|
31 |
CActive(EPriorityStandard)
|
|
32 |
{
|
|
33 |
CActiveScheduler::Add(this);
|
|
34 |
}
|
|
35 |
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
void CUsbIdPinObserver::ConstructL()
|
|
41 |
{
|
|
42 |
LOG_FUNC
|
|
43 |
|
|
44 |
LEAVEIFERROR(iIdPin.Attach(KUidUsbManCategory,
|
|
45 |
KUsbOtgIdPinPresentProperty));
|
|
46 |
|
|
47 |
}
|
|
48 |
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CUsbIdPinObserver* CUsbIdPinObserver::NewL()
|
|
54 |
{
|
|
55 |
LOG_FUNC
|
|
56 |
|
|
57 |
CUsbIdPinObserver* self = new (ELeave) CUsbIdPinObserver();
|
|
58 |
CleanupStack::PushL(self);
|
|
59 |
self->ConstructL();
|
|
60 |
CleanupStack::Pop(self);
|
|
61 |
return self;
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
CUsbIdPinObserver::~CUsbIdPinObserver()
|
|
69 |
{
|
|
70 |
LOG_FUNC
|
|
71 |
|
|
72 |
Cancel();
|
|
73 |
|
|
74 |
iIdPin.Close();
|
|
75 |
|
|
76 |
iObservers.Close();
|
|
77 |
|
|
78 |
}
|
|
79 |
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
CUsbIdPinObserver::TState CUsbIdPinObserver::IdPin()
|
|
85 |
/* this getter is not const, because for some reason RProperty::Get is not const */
|
|
86 |
{
|
|
87 |
|
|
88 |
TInt val(0);
|
|
89 |
|
|
90 |
TInt err = iIdPin.Get(val);
|
|
91 |
|
|
92 |
if (KErrNone != err)
|
|
93 |
{
|
|
94 |
LOG("CanNotGetIdPinProperty" );
|
|
95 |
PANIC( ECanNotGetIdPinProperty);
|
|
96 |
}
|
|
97 |
|
|
98 |
return (EFalse == val ? EIdPinOff : EIdPinOn);
|
|
99 |
}
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver)
|
|
106 |
{
|
|
107 |
LOG_FUNC
|
|
108 |
|
|
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);
|
|
117 |
|
|
118 |
if (KFirst == iObservers.Count()) // first item
|
|
119 |
{
|
|
120 |
iIdPin.Subscribe(iStatus);
|
|
121 |
SetActive();
|
|
122 |
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver)
|
|
131 |
{
|
|
132 |
LOG_FUNC
|
|
133 |
|
|
134 |
TInt i(iObservers.Find(&aObserver));
|
|
135 |
if (KErrNotFound == i)
|
|
136 |
{
|
|
137 |
LOG("Observer not found");
|
|
138 |
PANIC( ECanNotFindIdPinObserver);
|
|
139 |
return;
|
|
140 |
}
|
|
141 |
|
|
142 |
iObservers.Remove(i);
|
|
143 |
|
|
144 |
if (0 == iObservers.Count()) // no observers anymore
|
|
145 |
{
|
|
146 |
// cancel pending request
|
|
147 |
Cancel();
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CUsbIdPinObserver::RunL()
|
|
156 |
{
|
|
157 |
LOG_FUNC
|
|
158 |
|
|
159 |
LOG1( "iStatus = %d" , iStatus.Int());
|
|
160 |
|
|
161 |
// if error occured, tell to Observers
|
|
162 |
if (KErrNone != iStatus.Int())
|
|
163 |
{
|
|
164 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
165 |
{
|
|
166 |
iObservers[i]->IdPinErrorL(iStatus.Int());
|
|
167 |
}
|
|
168 |
return;
|
|
169 |
}
|
|
170 |
|
|
171 |
// re-issue request first
|
|
172 |
iIdPin.Subscribe(iStatus);
|
|
173 |
SetActive();
|
|
174 |
|
|
175 |
// then process property change
|
|
176 |
TState state(IdPin());
|
|
177 |
|
|
178 |
// report change
|
|
179 |
switch (state)
|
|
180 |
{
|
|
181 |
case EIdPinOn:
|
|
182 |
{
|
|
183 |
LOG("IdPin ON");
|
|
184 |
|
|
185 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
186 |
{
|
|
187 |
iObservers[i]->IdPinOnL();
|
|
188 |
}
|
|
189 |
break;
|
|
190 |
}
|
|
191 |
|
|
192 |
case EIdPinOff:
|
|
193 |
{
|
|
194 |
LOG("IdPin OFF");
|
|
195 |
|
|
196 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
197 |
{
|
|
198 |
iObservers[i]->IdPinOffL();
|
|
199 |
}
|
|
200 |
break;
|
|
201 |
}
|
|
202 |
|
|
203 |
default:
|
|
204 |
{
|
|
205 |
LOG("WrongIdPinState");
|
|
206 |
PANIC( EWrongIdPinState);
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
}
|
|
211 |
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
// ---------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
void CUsbIdPinObserver::DoCancel()
|
|
217 |
{
|
|
218 |
iIdPin.Cancel();
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
TInt CUsbIdPinObserver::RunError(TInt aError)
|
|
226 |
{
|
|
227 |
LOG_FUNC
|
|
228 |
|
|
229 |
LOG1( "aError = %d", aError);
|
|
230 |
|
|
231 |
// try to continue
|
|
232 |
return KErrNone;
|
|
233 |
|
|
234 |
}
|