|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <naviengine_priv.h> |
|
20 #include <gpio.h> |
|
21 #include "d_gpio.h" |
|
22 #include "d_gpio_dev.h" |
|
23 |
|
24 #define ETestStaticExtension 0x80000000 |
|
25 |
|
26 _LIT(KGpioDfscQueName, "D_GPIO_DFC"); |
|
27 |
|
28 DECLARE_STANDARD_LDD() |
|
29 { |
|
30 return new DGpioFactory; |
|
31 } |
|
32 |
|
33 DGpioFactory::DGpioFactory() |
|
34 { |
|
35 // Set version number for this device |
|
36 iVersion=RGpio::VersionRequired(); |
|
37 iParseMask=0; |
|
38 } |
|
39 |
|
40 TInt DGpioFactory::Install() |
|
41 { |
|
42 return SetName(&RGpio::Name()); |
|
43 } |
|
44 |
|
45 DGpioFactory::~DGpioFactory() |
|
46 { |
|
47 } |
|
48 |
|
49 void DGpioFactory::GetCaps(TDes8& aDes) const |
|
50 { |
|
51 // Create a capabilities object |
|
52 RGpio::TCaps caps; |
|
53 caps.iVersion = iVersion; |
|
54 // Write it back to user memory |
|
55 Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps)); |
|
56 } |
|
57 |
|
58 TInt DGpioFactory::Create(DLogicalChannelBase*& aChannel) |
|
59 { |
|
60 aChannel=new DGpioChannel; |
|
61 if(!aChannel) |
|
62 return KErrNoMemory; |
|
63 |
|
64 return KErrNone; |
|
65 } |
|
66 |
|
67 DGpioChannel::DGpioChannel() |
|
68 { |
|
69 iClient=&Kern::CurrentThread(); |
|
70 iClient->Open(); |
|
71 } |
|
72 |
|
73 TInt DGpioChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer) |
|
74 { |
|
75 TDynamicDfcQue* dfcq = NULL; |
|
76 TInt r = Kern::DynamicDfcQCreate(dfcq, 27, KGpioDfscQueName); |
|
77 |
|
78 if(r == KErrNone) |
|
79 { |
|
80 iDfcQ = dfcq; |
|
81 SetDfcQ(iDfcQ); |
|
82 iMsgQ.Receive(); |
|
83 } |
|
84 return r; |
|
85 } |
|
86 |
|
87 DGpioChannel::~DGpioChannel() |
|
88 { |
|
89 ((TDynamicDfcQue*)iDfcQ)->Destroy(); |
|
90 Kern::SafeClose((DObject*&)iClient,NULL); |
|
91 } |
|
92 |
|
93 TInt DGpioChannel::RequestUserHandle(DThread* aThread, TOwnerType aType) |
|
94 { |
|
95 // Make sure that only our client can get a handle |
|
96 if (aType!=EOwnerThread || aThread!=iClient) |
|
97 return KErrAccessDenied; |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 void DGpioChannel::HandleMsg(TMessageBase* aMsg) |
|
102 { |
|
103 TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
104 |
|
105 // Get message type |
|
106 TInt id=m.iValue; |
|
107 |
|
108 // Decode the message type and dispatch it to the relevent handler function... |
|
109 |
|
110 if (id==(TInt)ECloseMsg) |
|
111 { |
|
112 m.Complete(KErrNone, EFalse); |
|
113 return; |
|
114 } |
|
115 |
|
116 if (id==KMaxTInt) |
|
117 { |
|
118 m.Complete(KErrNone,ETrue); |
|
119 return; |
|
120 } |
|
121 |
|
122 if (id<0) |
|
123 { |
|
124 TInt r=DoControl(id); |
|
125 m.Complete(r, KErrNotSupported); |
|
126 } |
|
127 else |
|
128 { |
|
129 // DoControl |
|
130 TInt r=DoControl(id); |
|
131 m.Complete(r,ETrue); |
|
132 } |
|
133 } |
|
134 |
|
135 /** |
|
136 Process synchronous 'control' requests |
|
137 */ |
|
138 TInt DGpioChannel::DoControl(TInt aFunction) |
|
139 { |
|
140 TInt r=KErrNone; |
|
141 |
|
142 switch (aFunction) |
|
143 { |
|
144 case RGpio::ECallStaticExtension: |
|
145 r = GPIO::StaticExtension(0, ETestStaticExtension, NULL, NULL); |
|
146 break; |
|
147 |
|
148 default: |
|
149 r = KErrNotSupported; |
|
150 break; |
|
151 } |
|
152 |
|
153 return r; |
|
154 } |
|
155 |