author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 4 | 56f325a607ea |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\pccd\d_medch.cpp |
|
15 |
// This LDD allow simulation of media change on a peripheral bus controller. |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include <kernel/kernel.h> |
|
20 |
#include <drivers/pbus.h> |
|
21 |
#include "d_medch.h" |
|
22 |
||
23 |
const TInt KMajorVersionNumber=1; |
|
24 |
const TInt KMinorVersionNumber=0; |
|
25 |
const TInt KBuildVersionNumber=1; |
|
26 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
27 |
_LIT(KDFCThreadName,"D_MEDCH_DFC_THREAD"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
28 |
const TInt KMedChThreadPriority = 27; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
|
0 | 30 |
class DLddFactoryMedCh : public DLogicalDevice |
31 |
{ |
|
32 |
public: |
|
33 |
DLddFactoryMedCh(); |
|
34 |
virtual TInt Install(); |
|
35 |
virtual void GetCaps(TDes8 &aDes) const; |
|
36 |
virtual TInt Create(DLogicalChannelBase*& aChannel); |
|
37 |
}; |
|
38 |
||
39 |
class DLddMedCh : public DLogicalChannel |
|
40 |
{ |
|
41 |
public: |
|
42 |
DLddMedCh(); |
|
43 |
~DLddMedCh(); |
|
44 |
protected: |
|
45 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
46 |
virtual void HandleMsg(class TMessageBase *); |
|
47 |
private: |
|
48 |
TInt DoRequest(TInt aReqNo,TAny *a1,TAny *a2); |
|
49 |
TInt DoControl(TInt aFunction,TAny *a1,TAny *a2); |
|
50 |
private: |
|
51 |
static void MsCBFunc(TAny* aPtr); |
|
52 |
private: |
|
53 |
DPBusSocket* iSocketP; |
|
54 |
DThread* iClient; |
|
55 |
TRequestStatus* iReqStat; |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
TDynamicDfcQue* iDfcQ; |
0 | 57 |
|
58 |
NTimer iMsCallBack; |
|
59 |
TInt iMsInterval; |
|
60 |
||
61 |
DPBusSocket::TPBusSimulateMediaState iDelayedOperation; |
|
62 |
}; |
|
63 |
||
64 |
DECLARE_STANDARD_LDD() |
|
65 |
{ |
|
66 |
return new DLddFactoryMedCh; |
|
67 |
} |
|
68 |
||
69 |
DLddFactoryMedCh::DLddFactoryMedCh() |
|
70 |
/** |
|
71 |
* Constructor |
|
72 |
*/ |
|
73 |
{ |
|
74 |
||
75 |
iParseMask=KDeviceAllowUnit; |
|
76 |
iUnitsMask=0xffffffff; |
|
77 |
iVersion = TVersion(KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber); |
|
78 |
} |
|
79 |
||
80 |
TInt DLddFactoryMedCh::Install() |
|
81 |
/** |
|
82 |
* Install the device driver. |
|
83 |
*/ |
|
84 |
{ |
|
85 |
||
86 |
TPtrC name = _L("MedCh"); |
|
87 |
return(SetName(&name)); |
|
88 |
} |
|
89 |
||
90 |
void DLddFactoryMedCh::GetCaps(TDes8 &aDes) const |
|
91 |
/** |
|
92 |
* Return the media change LDD capabilities. |
|
93 |
*/ |
|
94 |
{ |
|
95 |
||
96 |
TCapsMediaChangeV01 caps; |
|
97 |
caps.version = TVersion(KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber); |
|
98 |
Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps)); |
|
99 |
} |
|
100 |
||
101 |
TInt DLddFactoryMedCh::Create(DLogicalChannelBase*& aChannel) |
|
102 |
/** |
|
103 |
* Create a channel on the device. |
|
104 |
*/ |
|
105 |
{ |
|
106 |
||
107 |
aChannel = new DLddMedCh; |
|
108 |
return aChannel ? KErrNone : KErrNoMemory; |
|
109 |
} |
|
110 |
||
111 |
DLddMedCh::DLddMedCh() |
|
112 |
/** |
|
113 |
* Constructor |
|
114 |
*/ |
|
115 |
: iMsCallBack(MsCBFunc, this) |
|
116 |
{ |
|
117 |
||
118 |
iClient = &Kern::CurrentThread(); |
|
119 |
((DObject*)iClient)->Open(); |
|
120 |
} |
|
121 |
||
122 |
DLddMedCh::~DLddMedCh() |
|
123 |
/** |
|
124 |
* Destructor |
|
125 |
*/ |
|
126 |
{ |
|
127 |
if(iSocketP) |
|
128 |
(void)iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaNormal, NULL); |
|
129 |
||
130 |
Kern::SafeClose((DObject*&)iClient, NULL); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
if (iDfcQ) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
iDfcQ->Destroy(); |
0 | 134 |
} |
135 |
||
136 |
TInt DLddMedCh::DoCreate(TInt aUnit, const TDesC8* /*aInfo*/, const TVersion& aVer) |
|
137 |
/** |
|
138 |
* Create channel. |
|
139 |
*/ |
|
140 |
{ |
|
141 |
||
142 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber), aVer)) |
|
143 |
return(KErrNotSupported); |
|
144 |
||
145 |
// |
|
146 |
// Obtain the requested socket (as specified by the opened logical unit) |
|
147 |
// |
|
148 |
iSocketP = DPBusSocket::SocketFromId(aUnit); |
|
149 |
if(iSocketP == NULL) |
|
150 |
return(KErrNoMemory); |
|
151 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
if (!iDfcQ) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
TInt r = Kern::DynamicDfcQCreate(iDfcQ, KMedChThreadPriority, KDFCThreadName); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
if (r != KErrNone) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
return r; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
#ifdef CPU_AFFINITY_ANY |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
#endif |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
SetDfcQ(iDfcQ); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
|
0 | 164 |
iMsgQ.Receive(); |
165 |
||
166 |
return KErrNone; |
|
167 |
} |
|
168 |
||
169 |
void DLddMedCh::HandleMsg(TMessageBase* aMsg) |
|
170 |
/** |
|
171 |
* Message Handler |
|
172 |
*/ |
|
173 |
{ |
|
174 |
||
175 |
TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
176 |
TInt id=m.iValue; |
|
177 |
||
178 |
if (id == (TInt)ECloseMsg) |
|
179 |
{ |
|
180 |
iMsCallBack.Cancel(); |
|
181 |
(void)iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaNormal, NULL); |
|
182 |
m.Complete(KErrNone, EFalse); |
|
183 |
return; |
|
184 |
} |
|
185 |
else if (id == KMaxTInt) |
|
186 |
{ |
|
187 |
// DoCancel |
|
188 |
m.Complete(KErrNone, ETrue); |
|
189 |
return; |
|
190 |
} |
|
191 |
||
192 |
if (id < 0) |
|
193 |
{ |
|
194 |
// DoRequest |
|
195 |
TRequestStatus* pS = (TRequestStatus*)m.Ptr0(); |
|
196 |
iReqStat = pS; |
|
197 |
TInt r = DoRequest(~id, m.Ptr1(), m.Ptr2()); |
|
198 |
if (r != KErrNone) |
|
199 |
Kern::RequestComplete(iClient, pS, r); |
|
200 |
m.Complete(KErrNone, ETrue); |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
// DoControl |
|
205 |
TInt r = DoControl(id, m.Ptr0(), m.Ptr1()); |
|
206 |
if(r != KErrCompletion) |
|
207 |
{ |
|
208 |
m.Complete(r, ETrue); |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
||
213 |
TInt DLddMedCh::DoRequest(TInt aFunction, TAny* a1, TAny* a2) |
|
214 |
/** |
|
215 |
* Asynchronous requests |
|
216 |
*/ |
|
217 |
{ |
|
218 |
||
219 |
TInt err = KErrNotSupported; |
|
220 |
||
221 |
switch (aFunction) |
|
222 |
{ |
|
223 |
case RMedCh::EDelayedDoorOpen: |
|
224 |
{ |
|
225 |
const TInt KMsInterval = (TInt)a1; |
|
226 |
iDelayedOperation = DPBusSocket::EPeriphBusDoorOpen; |
|
227 |
err = iMsCallBack.OneShot(NKern::TimerTicks(KMsInterval), ETrue); |
|
228 |
break; |
|
229 |
} |
|
230 |
||
231 |
case RMedCh::EDelayedDoorClose: |
|
232 |
{ |
|
233 |
const TInt KMsInterval = (TInt)a1; |
|
234 |
const TBool KMediaPresent = (TBool)a2; |
|
235 |
iDelayedOperation = KMediaPresent ? DPBusSocket::EPeriphBusMediaPresent : DPBusSocket::EPeriphBusMediaRemoved; |
|
236 |
err = iMsCallBack.OneShot(NKern::TimerTicks(KMsInterval), ETrue); |
|
237 |
break; |
|
238 |
} |
|
239 |
||
240 |
default: |
|
241 |
{ |
|
242 |
err = KErrNotSupported; |
|
243 |
break; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
return err; |
|
248 |
} |
|
249 |
||
250 |
TInt DLddMedCh::DoControl(TInt aFunction,TAny* a1, TAny* /*a2*/) |
|
251 |
/** |
|
252 |
* Synchronous requests |
|
253 |
*/ |
|
254 |
{ |
|
255 |
||
256 |
TInt err = KErrNotSupported; |
|
257 |
||
258 |
switch (aFunction) |
|
259 |
{ |
|
260 |
case RMedCh::EDoorOpen: |
|
261 |
{ |
|
262 |
err = iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusDoorOpen, NULL); |
|
263 |
break; |
|
264 |
} |
|
265 |
||
266 |
case RMedCh::EDoorClose: |
|
267 |
{ |
|
268 |
const TBool KMediaPresent = (TBool)a1; |
|
269 |
||
270 |
err = iSocketP->ControlIO(DPBusSocket::EControlMediaState, |
|
271 |
(TAny*)(KMediaPresent ? DPBusSocket::EPeriphBusMediaPresent : DPBusSocket::EPeriphBusMediaRemoved), |
|
272 |
NULL); |
|
273 |
break; |
|
274 |
} |
|
275 |
||
276 |
case RMedCh::EDoorNormal: |
|
277 |
{ |
|
278 |
err = iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaNormal, NULL); |
|
279 |
break; |
|
280 |
} |
|
281 |
||
282 |
case RMedCh::EDoubleDoorOpen: |
|
283 |
{ |
|
284 |
err = iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)DPBusSocket::EPeriphBusMediaDoubleDoorOpen, NULL); |
|
285 |
break; |
|
286 |
} |
|
287 |
||
288 |
default: |
|
289 |
{ |
|
290 |
err = KErrNotSupported; |
|
291 |
break; |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
return err; |
|
296 |
} |
|
297 |
||
298 |
void DLddMedCh::MsCBFunc(TAny* aPtr) |
|
299 |
/** |
|
300 |
* Delayed Open/Close timer callback |
|
301 |
*/ |
|
302 |
{ |
|
303 |
DLddMedCh& mcldd=*(DLddMedCh*)aPtr; |
|
304 |
TInt err = mcldd.iSocketP->ControlIO(DPBusSocket::EControlMediaState, (TAny*)mcldd.iDelayedOperation, NULL); |
|
305 |
Kern::RequestComplete(mcldd.iClient, mcldd.iReqStat, err); |
|
306 |
} |
|
307 |