diff -r 0818dd463d41 -r 924385140d98 sensorsupport/testsensor/src/ssyreferenceconfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensorsupport/testsensor/src/ssyreferenceconfig.h Tue Aug 31 15:24:25 2010 +0300 @@ -0,0 +1,522 @@ +// ssyreferenceconfig.h + +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +/** + @file + @internalComponent +*/ + + +#ifndef SSYREFERENCECONFIG_H +#define SSYREFERENCECONFIG_H + +// INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include + +// CONSTANTS +// Data item sizes +const TInt KSsyRefAxisDataItemSize = sizeof( TSensrvAccelerometerAxisData ); +const TInt KSsyRefTappingDataItemSize = sizeof( TSensrvTappingData ); +const TInt KSsyRefProximityDataItemSize = sizeof( TSensrvProximityData ); + +// ENUMS +enum TSsyReferenceFunctions + { + ESsyReferenceOpenChannel, + ESsyReferenceOpenChannelResp, + ESsyReferenceDataItemReceived, + ESsyReferenceCloseChannel, + ESsyReferenceCloseChannelResp, + ESsyReferenceStartChannelData, + ESsyReferenceStopChannelData + }; + +/** + * Base class for Channel data types. Contains iChannelDataType which is set + * by derived classes on construction. + */ +class TSsyRefChannelDataBase + { + public: + /** + * Enumeration for possible channel data types + */ + enum TSsyRefChannelDataType + { + ESsyRefChannelTypeTapping = 5000, + ESsyRefChannelTypeAxis, + ESsyRefChannelTypeProximity, + ESsyRefChannelTypeAmbientLight + }; + + TInt ChannelDataType() const { return iChannelDataType; } + TInt Interval() const { return iInterval; } + + void SetTimestamp( const TTime aTimestamp ) { iTimestamp = aTimestamp; } + TTime Timestamp() const { return iTimestamp; } + + TInt Size() const { return iSize; } + + protected: + + /** + * Protected constructor as this class is not supposed to be instantiate + * directly. + */ + TSsyRefChannelDataBase() {} + + protected: // data + + /** + * Identifies the type of data type class derived from this base class + */ + TInt iChannelDataType; + + /** + * Interval. Indicates time in ms from previous item until next item is produced + */ + TInt iInterval; + + /** + * Timestamp. Time when this data item is generated. + */ + TTime iTimestamp; + + /** + * Size of one data item. This is filled by derived class + */ + TInt iSize; + + /** + * Axis data item values. + * Accessible only from TSsyRefChannelDataAxis class + */ + TInt iXAxis; + TInt iYAxis; + TInt iZAxis; + + + /** + * Proximity data item values. + * Accessible only from TSsyRefChannelProximity class + */ + TInt iProximityState; + + /** + * AmbientLight data item values. + * Accessible only from TSsyRefChannelAmbientLight class + */ + TInt iAmbientLightState; + + /** + * Tapping data item values. Difrection of the tapping. + * Accessible only from TSsyRefChannelDataTapping class + */ + TInt iDirection; + }; + +// Type definition array for Data item base class +typedef RArray TSsyRefDataItemArray; + +/** + * Message item for SSY <--> Sensor communications + * Contains Channel ID for which the message belongs to, + * Function ID that identifies the command and + * error for error cases. + */ +class TSsyReferenceMsg + { + public: + + /** + * Constructor of the TSsyReferenceMsg + * + * @param[in] aChannelId Channel identifier + * @param[in] aFunction See TSsyReferenceFunctions + */ + TSsyReferenceMsg( TInt aChannelId, TInt aFunction ) : + iChannelId( aChannelId ), + iFunction( aFunction ), + iError( KErrNone ) + {} + + /** + * Copy constructor of the TSsyReferenceMsg + * + * @param[in] aMsg Object to be copied to constructed object + */ + TSsyReferenceMsg( const TSsyReferenceMsg& aMsg ) : + iChannelId( aMsg.iChannelId ), + iFunction( aMsg.iFunction ), + iError( aMsg.iError ) + {} + + TInt ChannelId() { return iChannelId; } + + void SetFunction( TInt aFunction ) { iFunction = aFunction; } + TInt Function() { return iFunction; } + + void SetError( TInt aError ) { iError = aError; } + TInt Error() { return iError; } + + void SetDataItem( TSsyRefChannelDataBase* aDataItem ) { iDataItem = aDataItem; } + TSsyRefChannelDataBase* DataItem() const { return iDataItem; } + + private: // data + + TInt iChannelId; // Identifies the channel + TInt iFunction; // Identifies the command + TInt iError; // Error is passed to response handler + + // Data item for received data. This is casted to correct data item + // class implementation according to ChannelDataType + TSsyRefChannelDataBase* iDataItem; + }; + +/** + * Tapping data type class implementation. + */ +class TSsyRefChannelDataTapping : public TSsyRefChannelDataBase + { + public: + + TSsyRefChannelDataTapping( TInt aDirection, TInt aInterval ) + { + iChannelDataType = ESsyRefChannelTypeTapping; + iSize = KSsyRefTappingDataItemSize; + iInterval = aInterval; + iDirection = aDirection; + } + + TInt Direction() const { return iDirection; } + }; + +/** + * XYZ Axis data type class implementation. + */ +class TSsyRefChannelDataAxis : public TSsyRefChannelDataBase + { + public: + + TSsyRefChannelDataAxis( TInt aXAxis, TInt aYAxis, TInt aZAxis, + TInt aInterval ) + { + iChannelDataType = ESsyRefChannelTypeAxis; + iSize = KSsyRefAxisDataItemSize; + iInterval = aInterval; + iXAxis = aXAxis; + iYAxis = aYAxis; + iZAxis = aZAxis; + } + + TInt XAxis() const { return iXAxis; } + TInt YAxis() const { return iYAxis; } + TInt ZAxis() const { return iZAxis; } + }; + + +/** + * Proximity data type class implementation. + */ +class TSsyRefChannelDataProximity : public TSsyRefChannelDataBase + { + public: + + TSsyRefChannelDataProximity( TInt aProximityState, TInt aInterval ) + { + iChannelDataType = ESsyRefChannelTypeProximity; + iSize = KSsyRefProximityDataItemSize; + iInterval = aInterval; + iProximityState = aProximityState; + } + + TInt ProximityState() const { return iProximityState; } + }; + +/** + * Channel ID pair class for pairing config file channel id and + * Sensor Server generated channel ID. + */ +class TSsyRefChannelIdPair + { + public: + /** + * Constructor of the TSsyRefChannelIdPair + * + * @param[in] aConfigChannelId Channel identifier from config file + */ + TSsyRefChannelIdPair( TInt aConfigChannelId ) : + iConfigChannelId( aConfigChannelId ) + {} + + TInt ConfigId() const { return iConfigChannelId; } + TInt ServerId() const { return iSrvChannelId; } + + void SetServerId( const TInt aSrvId ) { iSrvChannelId = aSrvId; } + + private: // data + + TInt iConfigChannelId; // Config file ID of the channel + TInt iSrvChannelId; // Sensor server assigned ID of the channel + }; + +typedef RArray TSsyRefChannelIdArray; + + +// CONSTANTS + +/** + * Configuration class for SSY reference plugin. Generates configured SSY channel information. + * This keeps reference SSY implementation independent from 'sensor' it uses. This class is fully + * modifiable regarding to the needs of this SSY. It may be for example accelerometer sensor + * without any changes in the SSY reference implementation. Only this class is modified. + */ +class CSsyReferenceConfig : public CActive, public MMDXMLParserObserver + { + +public: + + /** + * Two-phase constructor + * + * @return Pointer to created CSsyReferenceControl object + */ + static CSsyReferenceConfig* NewL(); + + /** + * Virtual destructor + */ + virtual ~CSsyReferenceConfig(); + + /** + * From CActive + */ + void RunL(); + + /** + * From CActive + */ + void DoCancel(); + + /** + * From CActive + */ + TInt RunError( TInt aError ); + + /** + * From MMDXMLParserObserver + * + * Call back function used to inform a client of the Parser when a parsing operation completes. + */ + void ParseFileCompleteL(); + + /** + * Starts parsing config file. This function blocks until file is parsed + */ + void InitConfigL(); + + /** + * Total number of channels this SSY provides + * + * @return Count of channels this SSY is configured to provide + */ + TInt ChannelCount(); + + /** + * Generates channels this SSY is configured to provide + * + * @param[in,out] aChannnelList Filled with generated channels by this configurator + */ + void GenerateChannels( RSensrvChannelInfoList& aChannelList ); + + /** + * Updates Sensor server's generated channel Ids + * + * @param[in] aChannnelList Same list as GenerateChannels produces but + * this contains channel identifiers + */ + void UpdateChannelIds( RSensrvChannelInfoList aChannelList ); + + /** + * Reads all channel data information from config file and fills + * parameters with information + * + * @param[in] aSrvChannelId Sensor server generated channel id of the target channel + * @param[in,out] aDataItemList Contains data item objects defined in config file. Each + * Data item is presented as Data Item class derived from TSsyRefChannelDataBase. + * List can contain only one type of derived channel data items + * @param[in,out] aStartInterval Contains start interval to start producing data items + */ + void GetChannelDataInformationL( const TInt aSrvChannelId, + TSsyRefDataItemArray& aDataItemList, + TInt& aStartInterval ); + + /** + * Reads sensor properties from config file and adds them to list + * + * @param[out] aPropertyList List where to append properties + */ + void GetSensorPropertiesL( RSensrvPropertyList& aPropertyList ); + + /** + * Reads channel properties from config file and adds them to list + * + * @param[in] aSenSrvChannelId Sensor server generated channel id + * @param[out] aPropertyList List where to append properties + */ + void GetChannelPropertiesL( const TInt aSrvChannelId, + RSensrvPropertyList& aPropertyList ); + +private: + + /** + * C++ constructor. + */ + CSsyReferenceConfig(); + + /** + * Symbian 2nd phase constructor. + */ + void ConstructL(); + + /** + * Makes synchronous calls asynchronous + */ + void IssueRequest( TInt aError = KErrNone ); + + /** + * Reads attribute value from element and casts it into TInt value + * + * @param[in] aElement Element from where to read attribute + * @param[in] aAttrib Attribute name which to read + * @return Integer value of read value + */ + TInt GetAttributeIntValue( CMDXMLElement& aElement, const TDesC& aAttrib ); + + /** + * Reads attribute value from element and casts it into literal value + * + * @param[in] aElement Element from where to read attribute + * @param[in] aAttrib Attribute name which to read + * @param[in/out] aTarget Target descriptor where to copy read literal + */ + void GetAttributeStrValue( CMDXMLElement& aElement, const TDesC& aAttrib, TDes8& aTarget ); + + /** + * Reads attribute value from element and casts it into TReal value + * + * @param[in] aElement Element from where to read attribute + * @param[in] aAttrib Attribute name which to read + * @return value of the attribute + */ + TReal GetAttributeRealValue( CMDXMLElement& aElement, const TDesC& aAttrib ); + + /** + * Reads Hexadesimal attribute value from element and casts it into Integer value + * + * @param[in] aElement Element from where to read attribute + * @param[in] aAttrib Attribute name which to read + * @return Unsigned integer value of read Hexadesimal value + */ + TUint GetAttributeHexValue( CMDXMLElement& aElement, const TDesC& aAttrib ); + + /** + * Compares Sensor server generated channel IDs and return corresponding + * ConfigFile channel id + * + * @param[in] aSrvChannelId SenServer generated channel ID for which pair is needed + * @return ConfigFile channel ID that is paired with aSrvChannelId + */ + TInt ConfigChannelId( const TInt aSrvChannelId ) const; + + /** + * Searches channel element for given SensorServer generated channel ID + * + * @param[in] aSrvChannelId SenServer generated channel ID identifying wanted channel element + * @return Pointer to found channel element or NULL if not found + */ + CMDXMLElement* ChannelElement( const TInt aSrvChannelId ); + + /** + * Reads properties from given element and adds them to list. + * Element can be either 'SsyGenealInformation' or 'ChannelItem' + * + * @param[in] aElement Element from where to read properties + * @param[out] aPropertyList List where to append properties + */ + void GetElementPropertiesL( CMDXMLElement& aElement, RSensrvPropertyList& aPropertyList ); + + +private: // data + + /** + * Pointer of the config xml-file parser + */ + CMDXMLParser* iConfigParser; + + /** + * Contains Ssy general information element and all of its childs + */ + CMDXMLElement* iGenralInfoElement; + + /** + * Contains Ssy Channel information group element and all of its childs + * including each channel information and channel data for testing purpose + */ + CMDXMLElement* iChannelGroupElement; + + /** + * Number of channels defined in config file + */ + TInt iChannelCount; + + /** + * Active scheduler wait for blocking construction until config file is parsed + */ + CActiveSchedulerWait iSchedulerWait; + + /** + * Indicates is config file parsed + */ + TBool iConfigFileParsed; + + /** + * Channel ID pair array + */ + TSsyRefChannelIdArray iChannelPairArray; + + /** + * Elements of the config file. These needs to be stored + */ + CMDXMLDocument* iConfigFile; + CMDXMLElement* iSsyReferenceConfig; // Root of the config + }; + +#endif //SSYREFERENCECONFIG_H +