williamr@2: /* williamr@2: * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * 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 williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: Sensor channel class definition williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: #ifndef SENSRVCHANNEL_H williamr@2: #define SENSRVCHANNEL_H williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: class MSensrvPropertyListener; williamr@2: class MSensrvDataListener; williamr@2: class MSensrvChannelConditionListener; williamr@2: class CSensrvChannelCondition; williamr@2: class CSensrvChannelListener; williamr@2: williamr@2: williamr@2: /** williamr@2: * The CSensrvChannel class provides an API that allows clients to open, control, configure, williamr@2: * receive data and receive notifications from a sensor channel. williamr@2: * williamr@2: * When instantiating CSensrvChannel an instance of TSensrvChannelInfo returned by williamr@2: * CSensrvChannelFinder::FindChannelsL() must be used. This ensures that internal data used williamr@2: * in identifying the chosen channel is passed back to Sensor Services in its entirety williamr@2: * therefore ensuring correct operation. Not using the instance returned by williamr@2: * CSensrvChannelFinder::FindChannelsL() will result in undefined behaviour. williamr@2: * williamr@2: * On instantiation of this class a session connection to the Sensor Server is made. The Sensor williamr@2: * server is a transient server and is started, if not already running, when a session connection williamr@2: * is made. The sensor server is shutdown when a device-configured timeout period expires after williamr@2: * the last session connection has been dropped. The Sensor Server will not shutdown if there is williamr@2: * a session connection to it. williamr@2: * williamr@2: * The instance of TSensrvChannelInfo returned by CSensrvChannelFinder::FindChannelsL() williamr@2: * contains a channel Id which is only valid for the lifetime of the sensor server. If a client williamr@2: * requires that this id remains unchanged then the client must ensure that an instance of either williamr@2: * CSensrvChannelFinder or CSensrvChannel remains instantiated. This keeps a session connection with williamr@2: * the server open which prevents the sensor server from shutting down. williamr@2: * williamr@2: * After creating an instance of this class a client would typically: williamr@2: * 1. Check the configuration of the channel using GetPropertyL() or GetAllPropertuies(). williamr@2: * 2. Change the configuration where necessary using SetPropertiesL() williamr@2: * 3. If SetPropertiesL() failed, because of higher priority clients of this same channel or higher williamr@2: * priority clients of impacted channels on the same sensor, listen for notifications indicating williamr@2: * when it is able to set properties using SetPropertyListenerl(). williamr@2: * 4. Listen for property changes using SetPropertyListenerl(). This notifies the client of property williamr@2: * changes made by other clients of this same channel. williamr@2: * 5. Listen for data and retrieve data on the channel using StartDataListeningL() and GetData(). williamr@2: * 6. Set trigger conditions for a 1 off notification when the condition is met using AddConditionL() williamr@2: * and SetConditionListeningL(). williamr@2: * williamr@2: * Its possible that there may be more than 1 client using the same sensor channel on the device. Each williamr@2: * of these clients will have created their own instance of CSensrvChannel and can attempt to configure williamr@2: * the sensor using the SetPropertyL() operation. To manage any contention between clients wishing to williamr@2: * change the configuration of the sensor a concept of Client Priorities is employed. This means that a williamr@2: * device creator assigns a pre-determined priority to a client. If a client has not been assigned a williamr@2: * priority then it is assumed it has the lowest priority. williamr@2: * williamr@2: * When the SetPropertyL() operation is called the sensor server checks to see if the client has the williamr@2: * highest Client Priority of all clients using that channel or using an impacted channel on the same williamr@2: * sensor. If it has the property is set and all other clients of the channel are notified of the property williamr@2: * change. If it has not the SetPropertyL() operation fails with KErrAccessDenied. If clients have williamr@2: * the same priority then property setting is done on a first come first served basis. williamr@2: * williamr@2: * If a client is unable to set a property because of higher priority clients then the client should williamr@2: * implement the MSensrvPropertyListener::SetPropertySuccessIndicationChanged() callback so that they can williamr@2: * be notified when they are able to set properties. williamr@2: * williamr@2: * All client applications should be designed in such a way so that they are able to handle the situation williamr@2: * where they are unable to configure a channel using the SetPropertyL() operation. williamr@2: * williamr@2: * For example: williamr@2: * Should application features be disabled or should the application shutdown in such conditions? williamr@2: * Should features be disabled under certain channel configurations? williamr@2: * williamr@2: * This object is closed when deleted either by a call to operator delete or by the cleanup stack. No special williamr@2: * cleanup code is necessary to close the object before deletion. williamr@2: * williamr@2: * @see CSensrvChannelFinder williamr@2: * @lib sensrvclient.lib williamr@2: * @since S60 5.0 williamr@2: */ williamr@2: williamr@2: NONSHARABLE_CLASS( CSensrvChannel ): public CBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Two-phased constructor. williamr@2: * williamr@2: * The Sensor Server uses aChannelInfo to identify the channel in the server that the returned object williamr@2: * represents. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelInfo The information that determines which channel object is created. This must williamr@2: * be an object returned by CSensrvChannelFinder::FindChannelsL(). williamr@2: * @return Pointer to created CSensorChannel object williamr@2: * @leave KErrNoMemory williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: IMPORT_C static CSensrvChannel* NewL williamr@2: ( const TSensrvChannelInfo& aChannelInfo ); williamr@2: williamr@2: /** williamr@2: * Two-phased constructor. williamr@2: * williamr@2: * The Sensor Server uses aChannelInfo to identify the channel in the server that the returned object williamr@2: * represents. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelInfo The information that determines which channel object is created. This must williamr@2: * be an object returned by CSensrvChannelFinder::FindChannelsL(). williamr@2: * @return Pointer to created CSensorChannel object that is placed on the cleanup stack. williamr@2: * @leave KErrNoMemory williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: IMPORT_C static CSensrvChannel* NewLC williamr@2: ( const TSensrvChannelInfo& aChannelInfo ); williamr@2: williamr@2: public: williamr@2: /** williamr@2: * Initializes and opens the channel. After the channel is opened, the client can set and get channel williamr@2: * properties, add channel conditions and listen for sensor data. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @leave KErrAlreadyExists if channel is already open williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void OpenChannelL() = 0; williamr@2: williamr@2: /** williamr@2: * Closes the channel. williamr@2: * williamr@2: * This object is closed when deleted either by a call to operator delete or by the cleanup stack. No special williamr@2: * cleanup code is necessary to close the object before deletion. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @return KErrNone if channel closing is successful, or one of the system-wide error codes williamr@2: */ williamr@2: virtual TInt CloseChannel() = 0; williamr@2: williamr@2: /** williamr@2: * Retrieves a channel information object related to this channel. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @return Reference to the channel information object williamr@2: */ williamr@2: virtual const TSensrvChannelInfo& GetChannelInfo() const = 0; williamr@2: williamr@2: /** williamr@2: * Starts channel data listening on the channel. williamr@2: * williamr@2: * To use this operation clients must provide an object that inherits from MSensrvDataListener. williamr@2: * williamr@2: * When new data is available to be read, the client is notified by the williamr@2: * MSensrvDataListener::DataReceived() callback. On receiving this notificaton the client should williamr@2: * retrieve the data using the GetData() operation. williamr@2: * williamr@2: * Note that if a client is listening for both data and conditions on the channel then the lower williamr@2: * desired count and buffering period provided in either start listening operation arguments will be williamr@2: * used for both listeners. When either listener is stopped neither the desired count nor the williamr@2: * buffering period shall be changed. williamr@2: * williamr@2: * For the best performance, always use the highest desired count and maximum count as the use case williamr@2: * allows. This will reduce the overhead caused by a high volume of IPC context switches. However, williamr@2: * be aware that higher counts need to reserve more memory. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aDataListener Data listener for the channel. Must be valid until data listening is stopped. williamr@2: * @param aDesiredCount Desired receiving buffer size defined as a count of the channel data objects. williamr@2: * The maximum value is determined by sensor server internal channel buffer size, and minimum williamr@2: * value is one. Any value outside these limits is interpreted as maximum possible value. williamr@2: * The actual count of channel data objects received may be smaller than aDesiredCount, if a williamr@2: * non-zero buffering period has been specified. williamr@2: * The actual count of channel data objects received may larger, if aMaximumCount is bigger williamr@2: * than aDesiredCount. williamr@2: * If the sensor supplies data sporadically, and the clients requires every data object then williamr@2: * aDesiredCount should be set to one to ensure that no data objects are missed. williamr@2: * @param aMaximumCount Maximum receiving buffer size defined as a count of the channel data object. williamr@2: * The Maximum value is determined by sensor server internal channel buffer size, and minimum williamr@2: * value is aDesiredCount. Any value outside these limits is interpreted as maximum possible williamr@2: * value. williamr@2: * It is recommended that whenever aDesiredCount needs to be low and sensor has relatively high williamr@2: * data rate, aMaximumCount is set to significantly higher than aDesiredCount to reduce IPC williamr@2: * context switches and data loss. williamr@2: * @param aBufferingPeriod Specifies the maximum time in milliseconds that sensor server waits before williamr@2: * notifying the client that new data is available. It is possible that no new data is will be williamr@2: * available when the client is notified. williamr@2: * Zero timeout means that only desired and maximum counts are used in getting data. williamr@2: * Using a buffering period results in lot of unnecessary IPC context switches if a sensor williamr@2: * channel supplies data sporadically. It is therefore recommended that a buffering period is williamr@2: * used only when it is absolutely vital to have data at specific intervals and using a low williamr@2: * desired count is otherwise too expensive performance-wise. williamr@2: * @leave KErrArgument if aDataListener is NULL, or if a negative argument is supplied williamr@2: * @leave KErrNotFound if the channel is not open williamr@2: * @leave KErrAlreadyExists if data listening has already started on the channel williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void StartDataListeningL( MSensrvDataListener* aDataListener, williamr@2: const TInt aDesiredCount, williamr@2: const TInt aMaximumCount, williamr@2: const TInt aBufferingPeriod ) = 0; williamr@2: williamr@2: /** williamr@2: * Stop channel data listening. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @return KErrNone if stopping successful or one of the system-wide error codes williamr@2: */ williamr@2: virtual TInt StopDataListening() = 0; williamr@2: williamr@2: /** williamr@2: * Get data items when the client is notified by the MSensrvDataListener::DataReceived() callback williamr@2: * that new data is ready to be retrieved. The callback also indicates the number of data items williamr@2: * contained in aData. williamr@2: * williamr@2: * Example: williamr@2: * williamr@2: * How to retrieve data using TPckg williamr@2: * williamr@2: * @code williamr@2: * void DataReceived(CSensrvChannel& aChannel, TInt aCount, TInt aDataLost ) williamr@2: * { williamr@2: * if(aChannel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdAccelerometerXYZAxisData) williamr@2: * { williamr@2: * TSensrvAccelerometerAxisData XYZData; williamr@2: * TPckg XYZPackage( XYZData ); williamr@2: * aChannel.GetData( XYZPackage ); williamr@2: * } williamr@2: * } williamr@2: * @endcode williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aData Reference to descriptor that contains the data. Typically this is a package buffer williamr@2: * defined for data type of this channel. See channel specific data headers for details of williamr@2: * the package types and data supported by a channel. williamr@2: * @return KErrNotFound if data buffer is empty, KErrOverflow if aData is wrong size for data williamr@2: * item, or one of the system-wide error codes williamr@2: */ williamr@2: virtual TInt GetData( TDes8& aData ) = 0; williamr@2: williamr@2: /** williamr@2: * Sets a property value for this channel. To manage any contention between multiple clients wishing williamr@2: * to change the configuration of the sensor a concept of Client Priorities is employed. See class williamr@2: * description for further information. williamr@2: * williamr@2: * The sensor plugin may police setting of properties by verifying that the client making the request williamr@2: * has the necessary capabilities. If the client does not then it will return with KErrAccessDenied. williamr@2: * @since S60 5.0 williamr@2: * @param aProperty Identifies the property that is to be set and its new value. Only the Property Id, williamr@2: * Item Index and Property Value should be filled in. All other fields in TSensrvProperty are williamr@2: * ignored. williamr@2: * @return KErrNotFound if channel is not open or if the property does not exist, KErrAccessDenied williamr@2: * if there are other clients for this channel or impacted channel on the same sensor with a williamr@2: * higher Client Priority, KErrAccessDenied if the client does not have the required williamr@2: * capabilities or one of the system-wide error codes williamr@2: */ williamr@2: virtual TInt SetProperty( const TSensrvProperty& aProperty ) = 0; williamr@2: williamr@2: /** williamr@2: * Gets a channel property value for this channel. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aPropertyId Id of the property that is to be retrieved williamr@2: * @param aItemIndex The Item Index of the property to be retrieved. This is mapped to a specific item williamr@2: * in channel data structure. See channel specific data headers. williamr@2: * @param aProperty Reference for a property object where property data is to be copied williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave KErrNotFound if property does not exist williamr@2: * @leave KErrArgument if a negative argument is supplied williamr@2: * @leave One of the system-wide error codes williamr@2: * */ williamr@2: virtual void GetPropertyL( const TSensrvPropertyId aPropertyId, williamr@2: const TInt aItemIndex, williamr@2: TSensrvProperty& aProperty ) = 0; williamr@2: williamr@2: /** williamr@2: * Get a channel property value for this channel williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aPropertyId Id of the property that is to be retrieved williamr@2: * @param aItemIndex Item Index of the property to be retrieved. This is mapped to a specific item williamr@2: * in channel data structure. See channel specific data headers. williamr@2: * @param aArrayIndex Array index of the property to be retrieved when the property is part of a williamr@2: * property array. williamr@2: * @param aProperty Reference for a property object where property data is to be copied williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave KErrNotFound if property does not exist williamr@2: * @leave KErrArgument if a negative argument is supplied williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void GetPropertyL( const TSensrvPropertyId aPropertyId, williamr@2: const TInt aItemIndex, williamr@2: const TInt aArrayIndex, williamr@2: TSensrvProperty& aProperty ) = 0; williamr@2: williamr@2: /** williamr@2: * Get all properties for this channel williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelPropertyList Reference for a property list where all property data is to be williamr@2: * copied. Any existing data in the list will be lost. williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void GetAllPropertiesL williamr@2: ( RSensrvPropertyList& aChannelPropertyList ) = 0; williamr@2: williamr@2: /** williamr@2: * Get all channel properties having the supplied Property Id. This is used when the property williamr@2: * is an array property. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aPropertyId Id of the property to be retrieved williamr@2: * @param aChannelPropertyList Reference for a property list where all property data is to be williamr@2: * copied. Any existing data in the list will be lost. williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave KErrNotFound if property does not exist williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void GetAllPropertiesL williamr@2: ( const TSensrvPropertyId aPropertyId, williamr@2: RSensrvPropertyList& aChannelPropertyList ) = 0; williamr@2: williamr@2: /** williamr@2: * Start property listening on this channel. williamr@2: * williamr@2: * To use this operation clients must provide an object that inherits from MSensrvPropertyListener. williamr@2: * williamr@2: * The client can use the property listener to get notifications when properties are changed and williamr@2: * to get a notification when the client is able/unable to set properties because of higher priority williamr@2: * clients have opened/closed the same sensor channel. williamr@2: * williamr@2: * If the client itself changes a property value, no notification is received for that property by williamr@2: * the client. If another client changes a property on this channel or another channel that impacts williamr@2: * this channel a notification will be received by the client. williamr@2: * williamr@2: * Some sensors support a number of channels with each channel having some common properties. williamr@2: * Therefore changing a common property may result in notifications on a number of other channels williamr@2: * supported by the sensor. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelPropertyListener Pointer to channel property listener callback instance. The williamr@2: * channel property listener must be valid until the CSensrvChannel object is destroyed or williamr@2: * listening has been stopped. Listening can be stopped using a NULL parameter. williamr@2: * @leave KErrAlreadyExists if channel property listener has already been set williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void SetPropertyListenerL williamr@2: ( MSensrvPropertyListener* aChannelPropertyListener ) = 0; williamr@2: williamr@2: /** williamr@2: * Add a channel ConditionSet to the channel. williamr@2: * williamr@2: * Channel ConditionSet's are used for channel condition listening and at least 1 ConditionSet must williamr@2: * be added before listening can begin. williamr@2: * williamr@2: * When the conditions defined by the ConditionSet is met the client will be notified by the williamr@2: * MSensrvChannelConditionListener::ConditionMet() callback and listening for this ConditionSet will williamr@2: * cease. If a client wishes to listen for this ConditionSet again it must be added again. williamr@2: * williamr@2: * The client continues to own the ConditionSet object after a call to this function and must ensure williamr@2: * that it is destroyed when no longer required. williamr@2: * williamr@2: * The client must ensure that the ConditionSet object is valid until it is no longer needed by the williamr@2: * Sensor Server. This is either after the condition set has been removed by the client using williamr@2: * RemoveConditionL() or the client has been notified that the condition has been met. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelConditionSet The channel condition set to be added. williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave KErrNotSupported if a channel does not support conditions. williamr@2: * @leave One of the system-wide error codes williamr@2: * @see CSensrvChannel::StartConditionListeningL() williamr@2: */ williamr@2: virtual void AddConditionL( CSensrvChannelConditionSet& aChannelConditionSet ) = 0; williamr@2: williamr@2: /** williamr@2: * Remove a channel ConditionSet from the channel. williamr@2: * williamr@2: * The same reference used to to add the Condition Set in AddConditionL(), must also be used to williamr@2: * remove it. williamr@2: * williamr@2: * The removed channel ConditionSet is no longer used for channel condition listening. williamr@2: * williamr@2: * The client continues to own the ConditionSet object after a call to this function and must ensure williamr@2: * that it is destroyed when no longer required. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelConditionSet The channel condition set to be removed. williamr@2: * @leave KErrNotFound if channel is not open williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void RemoveConditionL williamr@2: ( CSensrvChannelConditionSet& aChannelConditionSet ) = 0; williamr@2: williamr@2: /** williamr@2: * Start channel condition listening. williamr@2: * williamr@2: * To use this operation clients must provide an object that inherits from MSensrvChannelConditionListener. williamr@2: * williamr@2: * If the conditions of an added ConditionSet is met the MSensrvChannelConditionListener::ConditionMet() williamr@2: * callback function will be called and listening for this ConditionSet will cease. If a client wishes williamr@2: * to listen for the same ConditionSet again it must be added again. williamr@2: * williamr@2: * Note that if a client is listening for both data and conditions on the channel then the lower williamr@2: * desired count and buffering period provided in either start listening operation arguments will be williamr@2: * used for both listeners. When either listener is stopped neither the desired count nor the williamr@2: * buffering period shall be changed. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @param aChannelConditionListener Condition listener for the channel. Must be valid until data williamr@2: * listening is stopped. williamr@2: * @param aObjectCount Listening buffer size defined as a count of the channel data objects. When the williamr@2: * desired object count is reached each ConditionSet is evaluated in turn. The maximum value is williamr@2: * determined by sensor server internal channel buffer size, and minimum value is one. Any value williamr@2: * outside these limits is interpreted as maximum possible value. williamr@2: * @param aBufferingPeriod Specifies the maximum time in milliseconds that sensor server waits before williamr@2: * evaluating new data. williamr@2: * Zero timeout means that the sensor server only evaluates new data when the object count has been williamr@2: * reached. williamr@2: * @leave KErrArgument if aChannelConditionListener is NULL, or if a negative argument is supplied williamr@2: * @leave KErrNotFound if the channel is not open williamr@2: * @leave KErrAlreadyExists if condition listening has already started on the channel williamr@2: * @leave One of the system-wide error codes williamr@2: */ williamr@2: virtual void StartConditionListeningL williamr@2: ( MSensrvChannelConditionListener* aChannelConditionListener, williamr@2: const TInt aObjectCount, williamr@2: const TInt aBufferingPeriod ) = 0; williamr@2: williamr@2: /** williamr@2: * Stop channel condition listening. williamr@2: * williamr@2: * All remaining unmet ConditionSet's are removed and channel condition listening is stopped. williamr@2: * williamr@2: * If the same ConditionSet's need to be used when condition listening has been restarted then they must be williamr@2: * re-added. williamr@2: * williamr@2: * @since S60 5.0 williamr@2: * @return KErrNone if condition listening is successfully stopped or one of the system-wide error codes williamr@2: */ williamr@2: virtual TInt StopConditionListening() = 0; williamr@2: williamr@2: public: williamr@2: /** williamr@2: * Default constructor. williamr@2: */ williamr@2: CSensrvChannel(); williamr@2: }; williamr@2: williamr@2: williamr@2: #endif //SENSRVCHANNEL_H williamr@2: williamr@2: // End of File