|
1 // Copyright (c) 2003-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 // |
|
15 |
|
16 /** |
|
17 @file Interface to example Logical Device Driver |
|
18 @publishedPartner |
|
19 @released |
|
20 */ |
|
21 |
|
22 #ifndef __DRIVER1_H__ |
|
23 #define __DRIVER1_H__ |
|
24 |
|
25 #include <e32cmn.h> |
|
26 #include <e32ver.h> |
|
27 #ifndef __KERNEL_MODE__ |
|
28 #include <e32std.h> |
|
29 #endif |
|
30 |
|
31 /** |
|
32 User interface for 'Driver1' |
|
33 */ |
|
34 class RDriver1 : public RBusLogicalChannel |
|
35 { |
|
36 public: |
|
37 /** |
|
38 Structure for holding driver capabilities information |
|
39 (Just a version number in this example.) |
|
40 */ |
|
41 class TCaps |
|
42 { |
|
43 public: |
|
44 TVersion iVersion; |
|
45 }; |
|
46 |
|
47 /** |
|
48 Structure for holding driver configuration data |
|
49 */ |
|
50 class TConfig |
|
51 { |
|
52 public: |
|
53 TInt iSpeed; /**< Data transfer speed in microseconds/byte */ |
|
54 TInt iPddBufferSize; /**< Size of the PDD's data buffer (not modifiable) */ |
|
55 TInt iMaxSendDataSize; /**< Maximum size of data which can be sent in one go (not modifiable) */ |
|
56 TInt iMaxReceiveDataSize; /**< Maximum size of data which can be received in one go (not modifiable) */ |
|
57 }; |
|
58 typedef TPckgBuf<TConfig> TConfigBuf; |
|
59 |
|
60 public: |
|
61 TInt Open(); |
|
62 TInt GetConfig(TConfigBuf& aConfig); |
|
63 TInt SetConfig(const TConfigBuf& aConfig); |
|
64 void SendData(TRequestStatus &aStatus,const TDesC8& aData); |
|
65 void SendDataCancel(); |
|
66 void ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer); |
|
67 void ReceiveDataCancel(); |
|
68 inline static const TDesC& Name(); |
|
69 inline static TVersion VersionRequired(); |
|
70 private: |
|
71 /** |
|
72 Enumeration of Control messages. |
|
73 */ |
|
74 enum TControl |
|
75 { |
|
76 EGetConfig, |
|
77 ESetConfig |
|
78 }; |
|
79 |
|
80 /** |
|
81 Enumeration of Request messages. |
|
82 */ |
|
83 enum TRequest |
|
84 { |
|
85 ESendData, |
|
86 EReceiveData, |
|
87 ENumRequests, |
|
88 EAllRequests = (1<<ENumRequests)-1 |
|
89 }; |
|
90 |
|
91 // Kernel side LDD channel is a friend |
|
92 friend class DDriver1Channel; |
|
93 }; |
|
94 |
|
95 /** |
|
96 The driver's name |
|
97 |
|
98 @return The name of the driver |
|
99 |
|
100 @internalComponent |
|
101 */ |
|
102 inline const TDesC& RDriver1::Name() |
|
103 { |
|
104 _LIT(KDriver1Name,"DRIVER1"); |
|
105 return KDriver1Name; |
|
106 } |
|
107 |
|
108 /** |
|
109 The driver's version |
|
110 |
|
111 @return The version number of the driver |
|
112 |
|
113 @internalComponent |
|
114 */ |
|
115 inline TVersion RDriver1::VersionRequired() |
|
116 { |
|
117 const TInt KMajorVersionNumber=1; |
|
118 const TInt KMinorVersionNumber=0; |
|
119 const TInt KBuildVersionNumber=KE32BuildVersionNumber; |
|
120 return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
121 } |
|
122 |
|
123 /* |
|
124 NOTE: The following methods would normally be exported from a seperate client DLL |
|
125 but are included inline in this header file for convenience. |
|
126 */ |
|
127 |
|
128 #ifndef __KERNEL_MODE__ |
|
129 |
|
130 /** |
|
131 Open a logical channel to the driver |
|
132 |
|
133 @return One of the system wide error codes. |
|
134 */ |
|
135 TInt RDriver1::Open() |
|
136 { |
|
137 return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread); |
|
138 } |
|
139 |
|
140 /** |
|
141 Get the current configuration settings. |
|
142 |
|
143 @param aConfig A structure which will be filled with the configuration settings. |
|
144 |
|
145 @return KErrNone |
|
146 */ |
|
147 TInt RDriver1::GetConfig(TConfigBuf& aConfig) |
|
148 { |
|
149 return DoControl(EGetConfig,(TAny*)&aConfig); |
|
150 } |
|
151 |
|
152 /** |
|
153 Set the current configuration settings. |
|
154 |
|
155 @param aConfig The new configuration settings to be used. |
|
156 |
|
157 @return KErrInUse if there are outstanding data transfer requests. |
|
158 KErrArgument if any configuration values are invalid. |
|
159 KErrNone otherwise |
|
160 */ |
|
161 TInt RDriver1::SetConfig(const TConfigBuf& aConfig) |
|
162 { |
|
163 return DoControl(ESetConfig,(TAny*)&aConfig); |
|
164 } |
|
165 |
|
166 /** |
|
167 Send data to the device. |
|
168 Only one send request may be pending at any time. |
|
169 |
|
170 @param aStatus The request to be signaled when the data has been sent. |
|
171 The result value will be set to KErrNone on success; |
|
172 or set to one of the system wide error codes when an error occurs. |
|
173 @param aData A descriptor containing the data to send. |
|
174 */ |
|
175 void RDriver1::SendData(TRequestStatus &aStatus,const TDesC8& aData) |
|
176 { |
|
177 DoRequest(ESendData,aStatus,(TAny*)&aData); |
|
178 } |
|
179 |
|
180 /** |
|
181 Cancel a previous SendData request. |
|
182 */ |
|
183 void RDriver1::SendDataCancel() |
|
184 { |
|
185 DoCancel(1<<ESendData); |
|
186 } |
|
187 |
|
188 /** |
|
189 Receive data from the device. |
|
190 Only one receive request may be pending at any time. |
|
191 |
|
192 @param aStatus The request to be signaled when the data has been received. |
|
193 The result value will be set to KErrNone on success; |
|
194 or set to one of the system wide error codes when an error occurs. |
|
195 @param aData A descriptor to which the received data will be written. |
|
196 */ |
|
197 void RDriver1::ReceiveData(TRequestStatus &aStatus,TDes8& aBuffer) |
|
198 { |
|
199 DoRequest(EReceiveData,aStatus,(TAny*)&aBuffer); |
|
200 } |
|
201 |
|
202 /** |
|
203 Cancel a previous ReceiveData request. |
|
204 */ |
|
205 void RDriver1::ReceiveDataCancel() |
|
206 { |
|
207 DoCancel(1<<EReceiveData); |
|
208 } |
|
209 |
|
210 #endif // !__KERNEL_MODE__ |
|
211 |
|
212 #endif |
|
213 |