sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Implementation of MS drive state watcher
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalTechnology
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "t_ms_main.h"
|
sl@0
|
24 |
#include "cpropertywatch.h"
|
sl@0
|
25 |
#include "cstatemachine.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
LOCAL_D TInt testedDriveIndex = -1;
|
sl@0
|
28 |
|
sl@0
|
29 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
30 |
// class CPropertyWatch
|
sl@0
|
31 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
32 |
|
sl@0
|
33 |
CPropertyWatch* CPropertyWatch::NewLC(TUsbMsDriveState_Subkey aSubkey, CPropertyHandler& aHandler)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CPropertyWatch* me=new(ELeave) CPropertyWatch(aHandler);
|
sl@0
|
36 |
CleanupStack::PushL(me);
|
sl@0
|
37 |
me->ConstructL(aSubkey);
|
sl@0
|
38 |
return me;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
CPropertyWatch::CPropertyWatch(CPropertyHandler& aHandler)
|
sl@0
|
42 |
: CActive(0), iHandler(aHandler)
|
sl@0
|
43 |
{}
|
sl@0
|
44 |
|
sl@0
|
45 |
void CPropertyWatch::ConstructL(TUsbMsDriveState_Subkey aSubkey)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, aSubkey));
|
sl@0
|
48 |
CActiveScheduler::Add(this);
|
sl@0
|
49 |
// initial subscription and process current property value
|
sl@0
|
50 |
RunL();
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CPropertyWatch::~CPropertyWatch()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
Cancel();
|
sl@0
|
56 |
iProperty.Close();
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void CPropertyWatch::DoCancel()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
iProperty.Cancel();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
void CPropertyWatch::RunL()
|
sl@0
|
65 |
{
|
sl@0
|
66 |
// resubscribe before processing new value to prevent missing updates
|
sl@0
|
67 |
iProperty.Subscribe(iStatus);
|
sl@0
|
68 |
iHandler.HandleStatusChange(iProperty);
|
sl@0
|
69 |
SetActive();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
73 |
// class CPropertyHandler
|
sl@0
|
74 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
75 |
|
sl@0
|
76 |
CPropertyHandler::CPropertyHandler(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
77 |
: iDriveNo(aDriveNo)
|
sl@0
|
78 |
, iStateMachine(aSm)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
CPropertyHandler::~CPropertyHandler()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
87 |
// class CMsDriveStatusHandler
|
sl@0
|
88 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
89 |
|
sl@0
|
90 |
CMsDriveStatusHandler*
|
sl@0
|
91 |
CMsDriveStatusHandler::NewLC(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
CMsDriveStatusHandler* self = new (ELeave) CMsDriveStatusHandler(aDriveNo, aSm);
|
sl@0
|
94 |
CleanupStack::PushL(self);
|
sl@0
|
95 |
return self;
|
sl@0
|
96 |
};
|
sl@0
|
97 |
|
sl@0
|
98 |
CMsDriveStatusHandler::CMsDriveStatusHandler(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
99 |
: CPropertyHandler(aDriveNo, aSm)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void
|
sl@0
|
104 |
CMsDriveStatusHandler::HandleStatusChange(RProperty& aProperty)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
TInt driveStatus = -1;
|
sl@0
|
107 |
TInt currentStatus = iStateMachine.CurrentStateId();
|
sl@0
|
108 |
TBuf8<16> allDrivesStatus;
|
sl@0
|
109 |
TInt ret = aProperty.Get(allDrivesStatus);
|
sl@0
|
110 |
test.Printf(_L("Property.Get() return value: %d\n"), ret);
|
sl@0
|
111 |
test(ret == KErrNone);
|
sl@0
|
112 |
|
sl@0
|
113 |
if (testedDriveIndex < 0)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
for(TInt i=0; i<allDrivesStatus.Length()/2; i++)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
if (allDrivesStatus[2*i] == iDriveNo)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
testedDriveIndex = i;
|
sl@0
|
120 |
break;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
}
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
if (testedDriveIndex < 0)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
test.Printf(_L("Tested drive %d not found\n"), iDriveNo);
|
sl@0
|
128 |
test(EFalse);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
driveStatus = allDrivesStatus[2*testedDriveIndex + 1];
|
sl@0
|
132 |
|
sl@0
|
133 |
switch (currentStatus)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
case EUsbMsDriveState_Disconnected:
|
sl@0
|
136 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Disconnected)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
iStateMachine.MoveTo(EUsbMsDriveState_Connected);
|
sl@0
|
139 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Disconnected);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
else if (iStateMachine.FromStateId() == EUsbMsDriveState_Disconnecting)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
test(driveStatus == currentStatus);
|
sl@0
|
144 |
iStateMachine.MoveTo(EUsbMsDriveState_Connecting);
|
sl@0
|
145 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Disconnected);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
else if (iStateMachine.FromStateId() == EUsbMsState_Read)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
CActiveScheduler::Stop();
|
sl@0
|
150 |
}
|
sl@0
|
151 |
break;
|
sl@0
|
152 |
case EUsbMsDriveState_Connecting:
|
sl@0
|
153 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Disconnected)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
iStateMachine.MoveTo(EUsbMsState_Written);
|
sl@0
|
156 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Connecting);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
break;
|
sl@0
|
159 |
case EUsbMsDriveState_Connected:
|
sl@0
|
160 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Disconnected)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
test(driveStatus == currentStatus);
|
sl@0
|
163 |
iStateMachine.MoveTo(EUsbMsDriveState_Active);
|
sl@0
|
164 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Connected);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
break;
|
sl@0
|
167 |
case EUsbMsDriveState_Disconnecting:
|
sl@0
|
168 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Active)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
test(driveStatus == currentStatus);
|
sl@0
|
171 |
iStateMachine.MoveTo(EUsbMsDriveState_Disconnected);
|
sl@0
|
172 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Disconnecting);
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
break;
|
sl@0
|
176 |
case EUsbMsDriveState_Active:
|
sl@0
|
177 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Connected)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
test(driveStatus == currentStatus);
|
sl@0
|
180 |
iStateMachine.MoveTo(EUsbMsDriveState_Disconnecting);
|
sl@0
|
181 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Active);
|
sl@0
|
182 |
}
|
sl@0
|
183 |
break;
|
sl@0
|
184 |
case EUsbMsDriveState_Locked:
|
sl@0
|
185 |
iStateMachine.MoveTo(EUsbMsDriveState_Disconnecting);
|
sl@0
|
186 |
break;
|
sl@0
|
187 |
default:
|
sl@0
|
188 |
test.Printf(_L("uninteresting drive status: %d\n"), currentStatus);
|
sl@0
|
189 |
break;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
194 |
// class CMsReadStatusHandler
|
sl@0
|
195 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
196 |
|
sl@0
|
197 |
CMsReadStatusHandler*
|
sl@0
|
198 |
CMsReadStatusHandler::NewLC(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
CMsReadStatusHandler* self = new (ELeave) CMsReadStatusHandler(aDriveNo, aSm);
|
sl@0
|
201 |
CleanupStack::PushL(self);
|
sl@0
|
202 |
return self;
|
sl@0
|
203 |
};
|
sl@0
|
204 |
|
sl@0
|
205 |
CMsReadStatusHandler::CMsReadStatusHandler(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
206 |
: CPropertyHandler(aDriveNo, aSm)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
void
|
sl@0
|
211 |
CMsReadStatusHandler::HandleStatusChange(RProperty& aProperty)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
TInt currentStatus = iStateMachine.CurrentStateId();
|
sl@0
|
214 |
TUsbMsBytesTransferred kBytes;
|
sl@0
|
215 |
|
sl@0
|
216 |
TInt ret = aProperty.Get(kBytes);
|
sl@0
|
217 |
test.Printf(_L("Read Property.Get() return value: %d\n"), ret);
|
sl@0
|
218 |
test(ret == KErrNone);
|
sl@0
|
219 |
|
sl@0
|
220 |
switch (currentStatus)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
case EUsbMsState_Read:
|
sl@0
|
223 |
if (iStateMachine.FromStateId() == EUsbMsState_Written
|
sl@0
|
224 |
&& (1 == kBytes[testedDriveIndex]))
|
sl@0
|
225 |
{
|
sl@0
|
226 |
iStateMachine.MoveTo(EUsbMsDriveState_Disconnected);
|
sl@0
|
227 |
iStateMachine.SetFromStateId(EUsbMsState_Read);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
break;
|
sl@0
|
230 |
case EUsbMsDriveState_Active:
|
sl@0
|
231 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Connected)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
iStateMachine.MoveTo(EUsbMsDriveState_Disconnecting);
|
sl@0
|
234 |
iStateMachine.SetFromStateId(EUsbMsDriveState_Active);
|
sl@0
|
235 |
}
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
default:
|
sl@0
|
238 |
test.Printf(_L("uninteresting read status: %d\n"), currentStatus);
|
sl@0
|
239 |
break;
|
sl@0
|
240 |
}
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
244 |
// class CMsWrittenStatusHandler
|
sl@0
|
245 |
///////////////////////////////////////////////////////////////////////////
|
sl@0
|
246 |
|
sl@0
|
247 |
CMsWrittenStatusHandler*
|
sl@0
|
248 |
CMsWrittenStatusHandler::NewLC(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
CMsWrittenStatusHandler* self = new (ELeave) CMsWrittenStatusHandler(aDriveNo, aSm);
|
sl@0
|
251 |
CleanupStack::PushL(self);
|
sl@0
|
252 |
return self;
|
sl@0
|
253 |
};
|
sl@0
|
254 |
|
sl@0
|
255 |
CMsWrittenStatusHandler::CMsWrittenStatusHandler(TInt aDriveNo, CStateMachine& aSm)
|
sl@0
|
256 |
: CPropertyHandler(aDriveNo, aSm)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
void
|
sl@0
|
261 |
CMsWrittenStatusHandler::HandleStatusChange(RProperty& aProperty)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
TInt currentStatus = iStateMachine.CurrentStateId();
|
sl@0
|
264 |
TUsbMsBytesTransferred kBytes;
|
sl@0
|
265 |
|
sl@0
|
266 |
TInt ret = aProperty.Get(kBytes);
|
sl@0
|
267 |
test.Printf(_L("Written Property.Get() return value: %d\n"), ret);
|
sl@0
|
268 |
test(ret == KErrNone);
|
sl@0
|
269 |
test.Printf(_L("Kilobytes written: %d\n"), kBytes[testedDriveIndex]);
|
sl@0
|
270 |
|
sl@0
|
271 |
switch (currentStatus)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
case EUsbMsState_Written:
|
sl@0
|
274 |
if (iStateMachine.FromStateId() == EUsbMsDriveState_Connecting &&
|
sl@0
|
275 |
kBytes[testedDriveIndex] == 1)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
iStateMachine.MoveTo(EUsbMsState_Read);
|
sl@0
|
278 |
iStateMachine.SetFromStateId(EUsbMsState_Written);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
break;
|
sl@0
|
281 |
default:
|
sl@0
|
282 |
test.Printf(_L("uninteresting write status: %d\n"), currentStatus);
|
sl@0
|
283 |
break;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
}
|