1 sensrvchannel.h |
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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Sensor channel class definition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SENSRVCHANNEL_H |
|
20 #define SENSRVCHANNEL_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <sensrvtypes.h> |
|
24 #include <sensrvchannelconditionset.h> |
|
25 #include <sensrvchannelinfo.h> |
|
26 |
|
27 |
|
28 class MSensrvPropertyListener; |
|
29 class MSensrvDataListener; |
|
30 class MSensrvChannelConditionListener; |
|
31 class CSensrvChannelCondition; |
|
32 class CSensrvChannelListener; |
|
33 |
|
34 |
|
35 /** |
|
36 * The CSensrvChannel class provides an API that allows clients to open, control, configure, |
|
37 * receive data and receive notifications from a sensor channel. |
|
38 * |
|
39 * When instantiating CSensrvChannel an instance of TSensrvChannelInfo returned by |
|
40 * CSensrvChannelFinder::FindChannelsL() must be used. This ensures that internal data used |
|
41 * in identifying the chosen channel is passed back to Sensor Services in its entirety |
|
42 * therefore ensuring correct operation. Not using the instance returned by |
|
43 * CSensrvChannelFinder::FindChannelsL() will result in undefined behaviour. |
|
44 * |
|
45 * On instantiation of this class a session connection to the Sensor Server is made. The Sensor |
|
46 * server is a transient server and is started, if not already running, when a session connection |
|
47 * is made. The sensor server is shutdown when a device-configured timeout period expires after |
|
48 * the last session connection has been dropped. The Sensor Server will not shutdown if there is |
|
49 * a session connection to it. |
|
50 * |
|
51 * The instance of TSensrvChannelInfo returned by CSensrvChannelFinder::FindChannelsL() |
|
52 * contains a channel Id which is only valid for the lifetime of the sensor server. If a client |
|
53 * requires that this id remains unchanged then the client must ensure that an instance of either |
|
54 * CSensrvChannelFinder or CSensrvChannel remains instantiated. This keeps a session connection with |
|
55 * the server open which prevents the sensor server from shutting down. |
|
56 * |
|
57 * After creating an instance of this class a client would typically: |
|
58 * 1. Check the configuration of the channel using GetPropertyL() or GetAllPropertuies(). |
|
59 * 2. Change the configuration where necessary using SetPropertiesL() |
|
60 * 3. If SetPropertiesL() failed, because of higher priority clients of this same channel or higher |
|
61 * priority clients of impacted channels on the same sensor, listen for notifications indicating |
|
62 * when it is able to set properties using SetPropertyListenerl(). |
|
63 * 4. Listen for property changes using SetPropertyListenerl(). This notifies the client of property |
|
64 * changes made by other clients of this same channel. |
|
65 * 5. Listen for data and retrieve data on the channel using StartDataListeningL() and GetData(). |
|
66 * 6. Set trigger conditions for a 1 off notification when the condition is met using AddConditionL() |
|
67 * and SetConditionListeningL(). |
|
68 * |
|
69 * Its possible that there may be more than 1 client using the same sensor channel on the device. Each |
|
70 * of these clients will have created their own instance of CSensrvChannel and can attempt to configure |
|
71 * the sensor using the SetPropertyL() operation. To manage any contention between clients wishing to |
|
72 * change the configuration of the sensor a concept of Client Priorities is employed. This means that a |
|
73 * device creator assigns a pre-determined priority to a client. If a client has not been assigned a |
|
74 * priority then it is assumed it has the lowest priority. |
|
75 * |
|
76 * When the SetPropertyL() operation is called the sensor server checks to see if the client has the |
|
77 * highest Client Priority of all clients using that channel or using an impacted channel on the same |
|
78 * sensor. If it has the property is set and all other clients of the channel are notified of the property |
|
79 * change. If it has not the SetPropertyL() operation fails with KErrAccessDenied. If clients have |
|
80 * the same priority then property setting is done on a first come first served basis. |
|
81 * |
|
82 * If a client is unable to set a property because of higher priority clients then the client should |
|
83 * implement the MSensrvPropertyListener::SetPropertySuccessIndicationChanged() callback so that they can |
|
84 * be notified when they are able to set properties. |
|
85 * |
|
86 * All client applications should be designed in such a way so that they are able to handle the situation |
|
87 * where they are unable to configure a channel using the SetPropertyL() operation. |
|
88 * |
|
89 * For example: |
|
90 * Should application features be disabled or should the application shutdown in such conditions? |
|
91 * Should features be disabled under certain channel configurations? |
|
92 * |
|
93 * This object is closed when deleted either by a call to operator delete or by the cleanup stack. No special |
|
94 * cleanup code is necessary to close the object before deletion. |
|
95 * |
|
96 * @see CSensrvChannelFinder |
|
97 * @lib sensrvclient.lib |
|
98 * @since S60 5.0 |
|
99 */ |
|
100 |
|
101 NONSHARABLE_CLASS( CSensrvChannel ): public CBase |
|
102 { |
|
103 public: |
|
104 /** |
|
105 * Two-phased constructor. |
|
106 * |
|
107 * The Sensor Server uses aChannelInfo to identify the channel in the server that the returned object |
|
108 * represents. |
|
109 * |
|
110 * @since S60 5.0 |
|
111 * @param aChannelInfo The information that determines which channel object is created. This must |
|
112 * be an object returned by CSensrvChannelFinder::FindChannelsL(). |
|
113 * @return Pointer to created CSensorChannel object |
|
114 * @leave KErrNoMemory |
|
115 * @leave One of the system-wide error codes |
|
116 */ |
|
117 IMPORT_C static CSensrvChannel* NewL |
|
118 ( const TSensrvChannelInfo& aChannelInfo ); |
|
119 |
|
120 /** |
|
121 * Two-phased constructor. |
|
122 * |
|
123 * The Sensor Server uses aChannelInfo to identify the channel in the server that the returned object |
|
124 * represents. |
|
125 * |
|
126 * @since S60 5.0 |
|
127 * @param aChannelInfo The information that determines which channel object is created. This must |
|
128 * be an object returned by CSensrvChannelFinder::FindChannelsL(). |
|
129 * @return Pointer to created CSensorChannel object that is placed on the cleanup stack. |
|
130 * @leave KErrNoMemory |
|
131 * @leave One of the system-wide error codes |
|
132 */ |
|
133 IMPORT_C static CSensrvChannel* NewLC |
|
134 ( const TSensrvChannelInfo& aChannelInfo ); |
|
135 |
|
136 public: |
|
137 /** |
|
138 * Initializes and opens the channel. After the channel is opened, the client can set and get channel |
|
139 * properties, add channel conditions and listen for sensor data. |
|
140 * |
|
141 * @since S60 5.0 |
|
142 * @leave KErrAlreadyExists if channel is already open |
|
143 * @leave One of the system-wide error codes |
|
144 */ |
|
145 virtual void OpenChannelL() = 0; |
|
146 |
|
147 /** |
|
148 * Closes the channel. |
|
149 * |
|
150 * This object is closed when deleted either by a call to operator delete or by the cleanup stack. No special |
|
151 * cleanup code is necessary to close the object before deletion. |
|
152 * |
|
153 * @since S60 5.0 |
|
154 * @return KErrNone if channel closing is successful, or one of the system-wide error codes |
|
155 */ |
|
156 virtual TInt CloseChannel() = 0; |
|
157 |
|
158 /** |
|
159 * Retrieves a channel information object related to this channel. |
|
160 * |
|
161 * @since S60 5.0 |
|
162 * @return Reference to the channel information object |
|
163 */ |
|
164 virtual const TSensrvChannelInfo& GetChannelInfo() const = 0; |
|
165 |
|
166 /** |
|
167 * Starts channel data listening on the channel. |
|
168 * |
|
169 * To use this operation clients must provide an object that inherits from MSensrvDataListener. |
|
170 * |
|
171 * When new data is available to be read, the client is notified by the |
|
172 * MSensrvDataListener::DataReceived() callback. On receiving this notificaton the client should |
|
173 * retrieve the data using the GetData() operation. |
|
174 * |
|
175 * Note that if a client is listening for both data and conditions on the channel then the lower |
|
176 * desired count and buffering period provided in either start listening operation arguments will be |
|
177 * used for both listeners. When either listener is stopped neither the desired count nor the |
|
178 * buffering period shall be changed. |
|
179 * |
|
180 * For the best performance, always use the highest desired count and maximum count as the use case |
|
181 * allows. This will reduce the overhead caused by a high volume of IPC context switches. However, |
|
182 * be aware that higher counts need to reserve more memory. |
|
183 * |
|
184 * @since S60 5.0 |
|
185 * @param aDataListener Data listener for the channel. Must be valid until data listening is stopped. |
|
186 * @param aDesiredCount Desired receiving buffer size defined as a count of the channel data objects. |
|
187 * The maximum value is determined by sensor server internal channel buffer size, and minimum |
|
188 * value is one. Any value outside these limits is interpreted as maximum possible value. |
|
189 * The actual count of channel data objects received may be smaller than aDesiredCount, if a |
|
190 * non-zero buffering period has been specified. |
|
191 * The actual count of channel data objects received may larger, if aMaximumCount is bigger |
|
192 * than aDesiredCount. |
|
193 * If the sensor supplies data sporadically, and the clients requires every data object then |
|
194 * aDesiredCount should be set to one to ensure that no data objects are missed. |
|
195 * @param aMaximumCount Maximum receiving buffer size defined as a count of the channel data object. |
|
196 * The Maximum value is determined by sensor server internal channel buffer size, and minimum |
|
197 * value is aDesiredCount. Any value outside these limits is interpreted as maximum possible |
|
198 * value. |
|
199 * It is recommended that whenever aDesiredCount needs to be low and sensor has relatively high |
|
200 * data rate, aMaximumCount is set to significantly higher than aDesiredCount to reduce IPC |
|
201 * context switches and data loss. |
|
202 * @param aBufferingPeriod Specifies the maximum time in milliseconds that sensor server waits before |
|
203 * notifying the client that new data is available. It is possible that no new data is will be |
|
204 * available when the client is notified. |
|
205 * Zero timeout means that only desired and maximum counts are used in getting data. |
|
206 * Using a buffering period results in lot of unnecessary IPC context switches if a sensor |
|
207 * channel supplies data sporadically. It is therefore recommended that a buffering period is |
|
208 * used only when it is absolutely vital to have data at specific intervals and using a low |
|
209 * desired count is otherwise too expensive performance-wise. |
|
210 * @leave KErrArgument if aDataListener is NULL, or if a negative argument is supplied |
|
211 * @leave KErrNotFound if the channel is not open |
|
212 * @leave KErrAlreadyExists if data listening has already started on the channel |
|
213 * @leave One of the system-wide error codes |
|
214 */ |
|
215 virtual void StartDataListeningL( MSensrvDataListener* aDataListener, |
|
216 const TInt aDesiredCount, |
|
217 const TInt aMaximumCount, |
|
218 const TInt aBufferingPeriod ) = 0; |
|
219 |
|
220 /** |
|
221 * Stop channel data listening. |
|
222 * |
|
223 * @since S60 5.0 |
|
224 * @return KErrNone if stopping successful or one of the system-wide error codes |
|
225 */ |
|
226 virtual TInt StopDataListening() = 0; |
|
227 |
|
228 /** |
|
229 * Get data items when the client is notified by the MSensrvDataListener::DataReceived() callback |
|
230 * that new data is ready to be retrieved. The callback also indicates the number of data items |
|
231 * contained in aData. |
|
232 * |
|
233 * Example: |
|
234 * |
|
235 * How to retrieve data using TPckg |
|
236 * |
|
237 * @code |
|
238 * void DataReceived(CSensrvChannel& aChannel, TInt aCount, TInt aDataLost ) |
|
239 * { |
|
240 * if(aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdAccelerometerXYZAxisData) |
|
241 * { |
|
242 * TSensrvAccelerometerAxisData XYZData; |
|
243 * TPckg<TSensrvAccelerometerAxisData> XYZPackage( XYZData ); |
|
244 * aChannel.GetData( XYZPackage ); |
|
245 * } |
|
246 * } |
|
247 * @endcode |
|
248 * |
|
249 * @since S60 5.0 |
|
250 * @param aData Reference to descriptor that contains the data. Typically this is a package buffer |
|
251 * defined for data type of this channel. See channel specific data headers for details of |
|
252 * the package types and data supported by a channel. |
|
253 * @return KErrNotFound if data buffer is empty, KErrOverflow if aData is wrong size for data |
|
254 * item, or one of the system-wide error codes |
|
255 */ |
|
256 virtual TInt GetData( TDes8& aData ) = 0; |
|
257 |
|
258 /** |
|
259 * Sets a property value for this channel. To manage any contention between multiple clients wishing |
|
260 * to change the configuration of the sensor a concept of Client Priorities is employed. See class |
|
261 * description for further information. |
|
262 * |
|
263 * The sensor plugin may police setting of properties by verifying that the client making the request |
|
264 * has the necessary capabilities. If the client does not then it will return with KErrAccessDenied. |
|
265 * @since S60 5.0 |
|
266 * @param aProperty Identifies the property that is to be set and its new value. Only the Property Id, |
|
267 * Item Index and Property Value should be filled in. All other fields in TSensrvProperty are |
|
268 * ignored. |
|
269 * @return KErrNotFound if channel is not open or if the property does not exist, KErrAccessDenied |
|
270 * if there are other clients for this channel or impacted channel on the same sensor with a |
|
271 * higher Client Priority, KErrAccessDenied if the client does not have the required |
|
272 * capabilities or one of the system-wide error codes |
|
273 */ |
|
274 virtual TInt SetProperty( const TSensrvProperty& aProperty ) = 0; |
|
275 |
|
276 /** |
|
277 * Gets a channel property value for this channel. |
|
278 * |
|
279 * @since S60 5.0 |
|
280 * @param aPropertyId Id of the property that is to be retrieved |
|
281 * @param aItemIndex The Item Index of the property to be retrieved. This is mapped to a specific item |
|
282 * in channel data structure. See channel specific data headers. |
|
283 * @param aProperty Reference for a property object where property data is to be copied |
|
284 * @leave KErrNotFound if channel is not open |
|
285 * @leave KErrNotFound if property does not exist |
|
286 * @leave KErrArgument if a negative argument is supplied |
|
287 * @leave One of the system-wide error codes |
|
288 * */ |
|
289 virtual void GetPropertyL( const TSensrvPropertyId aPropertyId, |
|
290 const TInt aItemIndex, |
|
291 TSensrvProperty& aProperty ) = 0; |
|
292 |
|
293 /** |
|
294 * Get a channel property value for this channel |
|
295 * |
|
296 * @since S60 5.0 |
|
297 * @param aPropertyId Id of the property that is to be retrieved |
|
298 * @param aItemIndex Item Index of the property to be retrieved. This is mapped to a specific item |
|
299 * in channel data structure. See channel specific data headers. |
|
300 * @param aArrayIndex Array index of the property to be retrieved when the property is part of a |
|
301 * property array. |
|
302 * @param aProperty Reference for a property object where property data is to be copied |
|
303 * @leave KErrNotFound if channel is not open |
|
304 * @leave KErrNotFound if property does not exist |
|
305 * @leave KErrArgument if a negative argument is supplied |
|
306 * @leave One of the system-wide error codes |
|
307 */ |
|
308 virtual void GetPropertyL( const TSensrvPropertyId aPropertyId, |
|
309 const TInt aItemIndex, |
|
310 const TInt aArrayIndex, |
|
311 TSensrvProperty& aProperty ) = 0; |
|
312 |
|
313 /** |
|
314 * Get all properties for this channel |
|
315 * |
|
316 * @since S60 5.0 |
|
317 * @param aChannelPropertyList Reference for a property list where all property data is to be |
|
318 * copied. Any existing data in the list will be lost. |
|
319 * @leave KErrNotFound if channel is not open |
|
320 * @leave One of the system-wide error codes |
|
321 */ |
|
322 virtual void GetAllPropertiesL |
|
323 ( RSensrvPropertyList& aChannelPropertyList ) = 0; |
|
324 |
|
325 /** |
|
326 * Get all channel properties having the supplied Property Id. This is used when the property |
|
327 * is an array property. |
|
328 * |
|
329 * @since S60 5.0 |
|
330 * @param aPropertyId Id of the property to be retrieved |
|
331 * @param aChannelPropertyList Reference for a property list where all property data is to be |
|
332 * copied. Any existing data in the list will be lost. |
|
333 * @leave KErrNotFound if channel is not open |
|
334 * @leave KErrNotFound if property does not exist |
|
335 * @leave One of the system-wide error codes |
|
336 */ |
|
337 virtual void GetAllPropertiesL |
|
338 ( const TSensrvPropertyId aPropertyId, |
|
339 RSensrvPropertyList& aChannelPropertyList ) = 0; |
|
340 |
|
341 /** |
|
342 * Start property listening on this channel. |
|
343 * |
|
344 * To use this operation clients must provide an object that inherits from MSensrvPropertyListener. |
|
345 * |
|
346 * The client can use the property listener to get notifications when properties are changed and |
|
347 * to get a notification when the client is able/unable to set properties because of higher priority |
|
348 * clients have opened/closed the same sensor channel. |
|
349 * |
|
350 * If the client itself changes a property value, no notification is received for that property by |
|
351 * the client. If another client changes a property on this channel or another channel that impacts |
|
352 * this channel a notification will be received by the client. |
|
353 * |
|
354 * Some sensors support a number of channels with each channel having some common properties. |
|
355 * Therefore changing a common property may result in notifications on a number of other channels |
|
356 * supported by the sensor. |
|
357 * |
|
358 * @since S60 5.0 |
|
359 * @param aChannelPropertyListener Pointer to channel property listener callback instance. The |
|
360 * channel property listener must be valid until the CSensrvChannel object is destroyed or |
|
361 * listening has been stopped. Listening can be stopped using a NULL parameter. |
|
362 * @leave KErrAlreadyExists if channel property listener has already been set |
|
363 * @leave KErrNotFound if channel is not open |
|
364 * @leave One of the system-wide error codes |
|
365 */ |
|
366 virtual void SetPropertyListenerL |
|
367 ( MSensrvPropertyListener* aChannelPropertyListener ) = 0; |
|
368 |
|
369 /** |
|
370 * Add a channel ConditionSet to the channel. |
|
371 * |
|
372 * Channel ConditionSet's are used for channel condition listening and at least 1 ConditionSet must |
|
373 * be added before listening can begin. |
|
374 * |
|
375 * When the conditions defined by the ConditionSet is met the client will be notified by the |
|
376 * MSensrvChannelConditionListener::ConditionMet() callback and listening for this ConditionSet will |
|
377 * cease. If a client wishes to listen for this ConditionSet again it must be added again. |
|
378 * |
|
379 * The client continues to own the ConditionSet object after a call to this function and must ensure |
|
380 * that it is destroyed when no longer required. |
|
381 * |
|
382 * The client must ensure that the ConditionSet object is valid until it is no longer needed by the |
|
383 * Sensor Server. This is either after the condition set has been removed by the client using |
|
384 * RemoveConditionL() or the client has been notified that the condition has been met. |
|
385 * |
|
386 * @since S60 5.0 |
|
387 * @param aChannelConditionSet The channel condition set to be added. |
|
388 * @leave KErrNotFound if channel is not open |
|
389 * @leave KErrNotSupported if a channel does not support conditions. |
|
390 * @leave One of the system-wide error codes |
|
391 * @see CSensrvChannel::StartConditionListeningL() |
|
392 */ |
|
393 virtual void AddConditionL( CSensrvChannelConditionSet& aChannelConditionSet ) = 0; |
|
394 |
|
395 /** |
|
396 * Remove a channel ConditionSet from the channel. |
|
397 * |
|
398 * The same reference used to to add the Condition Set in AddConditionL(), must also be used to |
|
399 * remove it. |
|
400 * |
|
401 * The removed channel ConditionSet is no longer used for channel condition listening. |
|
402 * |
|
403 * The client continues to own the ConditionSet object after a call to this function and must ensure |
|
404 * that it is destroyed when no longer required. |
|
405 * |
|
406 * @since S60 5.0 |
|
407 * @param aChannelConditionSet The channel condition set to be removed. |
|
408 * @leave KErrNotFound if channel is not open |
|
409 * @leave One of the system-wide error codes |
|
410 */ |
|
411 virtual void RemoveConditionL |
|
412 ( CSensrvChannelConditionSet& aChannelConditionSet ) = 0; |
|
413 |
|
414 /** |
|
415 * Start channel condition listening. |
|
416 * |
|
417 * To use this operation clients must provide an object that inherits from MSensrvChannelConditionListener. |
|
418 * |
|
419 * If the conditions of an added ConditionSet is met the MSensrvChannelConditionListener::ConditionMet() |
|
420 * callback function will be called and listening for this ConditionSet will cease. If a client wishes |
|
421 * to listen for the same ConditionSet again it must be added again. |
|
422 * |
|
423 * Note that if a client is listening for both data and conditions on the channel then the lower |
|
424 * desired count and buffering period provided in either start listening operation arguments will be |
|
425 * used for both listeners. When either listener is stopped neither the desired count nor the |
|
426 * buffering period shall be changed. |
|
427 * |
|
428 * @since S60 5.0 |
|
429 * @param aChannelConditionListener Condition listener for the channel. Must be valid until data |
|
430 * listening is stopped. |
|
431 * @param aObjectCount Listening buffer size defined as a count of the channel data objects. When the |
|
432 * desired object count is reached each ConditionSet is evaluated in turn. The maximum value is |
|
433 * determined by sensor server internal channel buffer size, and minimum value is one. Any value |
|
434 * outside these limits is interpreted as maximum possible value. |
|
435 * @param aBufferingPeriod Specifies the maximum time in milliseconds that sensor server waits before |
|
436 * evaluating new data. |
|
437 * Zero timeout means that the sensor server only evaluates new data when the object count has been |
|
438 * reached. |
|
439 * @leave KErrArgument if aChannelConditionListener is NULL, or if a negative argument is supplied |
|
440 * @leave KErrNotFound if the channel is not open |
|
441 * @leave KErrAlreadyExists if condition listening has already started on the channel |
|
442 * @leave One of the system-wide error codes |
|
443 */ |
|
444 virtual void StartConditionListeningL |
|
445 ( MSensrvChannelConditionListener* aChannelConditionListener, |
|
446 const TInt aObjectCount, |
|
447 const TInt aBufferingPeriod ) = 0; |
|
448 |
|
449 /** |
|
450 * Stop channel condition listening. |
|
451 * |
|
452 * All remaining unmet ConditionSet's are removed and channel condition listening is stopped. |
|
453 * |
|
454 * If the same ConditionSet's need to be used when condition listening has been restarted then they must be |
|
455 * re-added. |
|
456 * |
|
457 * @since S60 5.0 |
|
458 * @return KErrNone if condition listening is successfully stopped or one of the system-wide error codes |
|
459 */ |
|
460 virtual TInt StopConditionListening() = 0; |
|
461 |
|
462 public: |
|
463 /** |
|
464 * Default constructor. |
|
465 */ |
|
466 CSensrvChannel(); |
|
467 }; |
|
468 |
|
469 |
|
470 #endif //SENSRVCHANNEL_H |
|
471 |
|
472 // End of File |