sensorsupport/testsensor/src/ssyreferenceconfig.cpp
branchRCL_3
changeset 19 924385140d98
equal deleted inserted replaced
18:0818dd463d41 19:924385140d98
       
     1 // ssyreferenceconfig.cpp
       
     2 
       
     3 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 // All rights reserved.
       
     5 // This component and the accompanying materials are made available
       
     6 // under the terms of "Eclipse Public License v1.0"
       
     7 // which accompanies this distribution, and is available
       
     8 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 //
       
    10 // Initial Contributors:
       
    11 // Nokia Corporation - initial contribution.
       
    12 //
       
    13 // Contributors:
       
    14 //
       
    15 // Description:
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 #include <sensors/sensrvtypes.h>
       
    21 #include <f32file.h>
       
    22 #include <gmxmldocument.h>
       
    23 #include <gmxmlelement.h>
       
    24 #include <sensors/channels/ssyreferenceaccelerometer.h>
       
    25 #include <sensors/channels/ssyreferencemagnetometer.h>
       
    26 #include <sensors/channels/ssyreferenceorientation.h>
       
    27 #include <sensors/channels/ssyreferenceproximity.h>
       
    28 
       
    29 #include "ssyreferencecontrol.h"
       
    30 #include "ssyreferenceconfig.h"
       
    31 #include "ssyreferencetrace.h"
       
    32 
       
    33 
       
    34 // ======== CONSTANTS =======
       
    35 _LIT( KSsyReferenceCfgFileOrig, "z:\\refssy\\ssyreferenceconfig.xml" );
       
    36 _LIT( KSsyReferenceCfgFileExt, "c:\\refssy\\ssyreferenceconfig.xml" );
       
    37 
       
    38 // Config file definitions
       
    39 
       
    40 // Maximum attribute length
       
    41 const TInt KSsyRefMaxAttribLength = 20;
       
    42 
       
    43 // TAG DEFINITIONS
       
    44 _LIT( KSsyRefRootTag, "SsyReferenceConfig" );                       // Ssy general information tag
       
    45 _LIT( KSsyRefGeneralInfoTag, "SsyGeneralInformation" );             // Ssy general information tag
       
    46 _LIT( KSsyRefChannelInfoGroupTag, "ChannelInformationGroup" );      // Channel information group tag
       
    47 _LIT( KSsyRefChannelItemTag, "ChannelItem" );                       // Channel item tag
       
    48 _LIT( KSsyRefChannelDataTag, "ChannelData" );                       // Channel data tag
       
    49 _LIT( KSsyRefChannelDataItemTag, "ChannelDataItem" );               // Channel data item tag
       
    50 
       
    51 _LIT( KSsyRefProperties, "Properties" );                            // Properties tag
       
    52 _LIT( KSsyRefPropertyItem, "PropertyItem" );                        // PropertyItem tag
       
    53 
       
    54 // Data item definitions
       
    55 _LIT( KSsyRefAxisDataItemTag, "SsyRefChannelDataAxis" );            // SsyRefChannelDataAxis data item tag
       
    56 _LIT( KSsyRefXAxis, "XAxis" );                                      // XAxis from SsyRefChannelDataAxis
       
    57 _LIT( KSsyRefYAxis, "YAxis" );                                      // YAxis from SsyRefChannelDataAxis
       
    58 _LIT( KSsyRefZAxis, "ZAxis" );                                      // ZAxis from SsyRefChannelDataAxis
       
    59 
       
    60 _LIT( KSsyRefTappingDataItemTag, "SsyRefChannelDataTapping" );      // SsyRefChannelDataTapping data item tag
       
    61 _LIT( KSsyRefDirection, "Direction" );                              // Direction from SsyRefChannelDataTapping
       
    62 
       
    63 _LIT( KSsyRefProximityDataItemTag, "SsyRefChannelDataProximity" );  // SsyRefChannelDataProximity data item tag
       
    64 _LIT( KSsyRefProximityState, "ProximityState" );                    // ProximityStatus from SsyRefChannelDataProximity
       
    65 
       
    66 // ATTRIBUTE DEFINITIONS
       
    67 _LIT( KSsyRefChannelCount, "ChannelCount" );    // Channel count from ChannelInformationGroup
       
    68 _LIT( KSsyRefChannelId, "ChannelId" );          // Channel ID from ChannelItem
       
    69 _LIT( KSsyRefContextType, "ContextType" );      // Context type from ChannelItem
       
    70 _LIT( KSsyRefQuantity, "Quantity" );            // Quantity from ChannelItem
       
    71 _LIT( KSsyRefChannelType, "ChannelType" );      // ChannelType from ChannelItem
       
    72 _LIT( KSsyRefLocation, "Location" );            // Location from ChannelItem
       
    73 _LIT( KSsyRefVendorId, "Vendor" );              // Vendor from ChannelItem
       
    74 
       
    75 
       
    76 // Channel data item specific attribute definitions
       
    77 _LIT( KSsyRefStartInterval, "StartIntervalMs" );              // StartInterval from ChannelData
       
    78 _LIT( KSsyRefDataItemCount, "count" );                        // count from ChannelDataItem
       
    79 _LIT( KSsyRefDataTypeID, "DataTypeId" );                      // DataTypeId from ChannelDataItem
       
    80 _LIT( KSsyRefInterval, "IntervalMs" );                        // IntervalMs from ChannelDataItem
       
    81 
       
    82 // Property spesific attributes
       
    83 _LIT( KSsyRefPropertyId, "PropertyId" );              // PropertyId from PropertyItem
       
    84 _LIT( KSsyRefArrayIndex, "ArrayIndex" );              // ArrayIndex from PropertyItem
       
    85 _LIT( KSsyRefItemIndex, "ItemIndex" );                // ItemIndex from PropertyItem
       
    86 _LIT( KSsyRefPropertyValue, "PropertyValue" );        // PropertyValue from PorpertyItem
       
    87 _LIT( KSsyRefPropertyType, "PropertyType" );          // PropertyType from PropertyItem
       
    88 _LIT( KSsyRefMaxValue, "MaxValue" );                  // MaxValue from PropertyItem
       
    89 _LIT( KSsyRefMinValue, "MinValue" );                  // MinValue from PorpertyItem
       
    90 _LIT( KSsyRefReadOnly, "ReadOnly" );                  // ReadOnly from PropertyItem
       
    91 
       
    92 
       
    93 // ======== MEMBER FUNCTIONS ========
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CSsyReferenceConfig C++ constructor
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CSsyReferenceConfig::CSsyReferenceConfig() :
       
   100     CActive( EPriorityMuchLess )
       
   101     {
       
   102     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::CSsyReferenceConfig()" ) ) );
       
   103     CActiveScheduler::Add( this );
       
   104     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::CSsyReferenceConfig() - return" ) ) );
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Symbian 2nd phase constructor
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CSsyReferenceConfig::ConstructL()
       
   113     {
       
   114     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ConstructL()" ) ) );
       
   115     // Create config file parser
       
   116     iConfigParser = CMDXMLParser::NewL( this );
       
   117 
       
   118     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ConstructL() - return" ) ) );
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CSsyReferenceConfig::NewL
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CSsyReferenceConfig* CSsyReferenceConfig::NewL()
       
   127     {
       
   128     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::NewL()" ) ) );
       
   129     CSsyReferenceConfig* self = new ( ELeave ) CSsyReferenceConfig();
       
   130     CleanupStack::PushL( self );
       
   131     self->ConstructL();
       
   132     CleanupStack::Pop( self );
       
   133     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::NewL() - return" ) ) );
       
   134     return self;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Destructor
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 CSsyReferenceConfig::~CSsyReferenceConfig()
       
   142     {
       
   143     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::~CSsyReferenceConfig()" ) ) );
       
   144     
       
   145     if ( iConfigParser )
       
   146         {
       
   147         delete iConfigParser;
       
   148         iConfigParser = NULL;
       
   149         }
       
   150 
       
   151     if ( iGenralInfoElement )
       
   152         {
       
   153         delete iGenralInfoElement;
       
   154         iGenralInfoElement = NULL;
       
   155         }
       
   156 
       
   157     if ( iChannelGroupElement )
       
   158         {
       
   159         delete iChannelGroupElement;
       
   160         iChannelGroupElement = NULL;
       
   161         }
       
   162 
       
   163     if ( iSsyReferenceConfig )
       
   164         {
       
   165         delete iSsyReferenceConfig;
       
   166         iSsyReferenceConfig = NULL;
       
   167         }
       
   168 
       
   169     if ( iConfigFile )
       
   170         {
       
   171         delete iConfigFile;
       
   172         iConfigFile = NULL;
       
   173         }
       
   174 
       
   175     iChannelPairArray.Reset();
       
   176     
       
   177     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::~CSsyReferenceConfig() - return" ) ) );
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CSsyReferenceConfig::InitConfig
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CSsyReferenceConfig::InitConfigL()
       
   185     {
       
   186     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::InitConfig()" ) ) );
       
   187     
       
   188     // Open config file
       
   189     RFs fileSession;
       
   190     User::LeaveIfError( fileSession.Connect() );
       
   191 
       
   192     // Locate extrenal file... 
       
   193     RFile file;
       
   194     TInt err( file.Open( fileSession, KSsyReferenceCfgFileExt, EFileRead ) );
       
   195     file.Close();
       
   196 
       
   197     // Check is external file found
       
   198     if ( KErrNone == err )
       
   199         {
       
   200         // Use SSY with external configuration
       
   201         User::LeaveIfError( iConfigParser->ParseFile( fileSession, KSsyReferenceCfgFileExt ) );
       
   202         }
       
   203     else
       
   204         {
       
   205         // Use SSY with original configuration
       
   206 
       
   207         // Start parsing file and wait notification to ParseFileCompleteL
       
   208         // XML Parser takes ownership of the RFs and closes it when file is parsed
       
   209         User::LeaveIfError( iConfigParser->ParseFile( fileSession, KSsyReferenceCfgFileOrig ) );
       
   210         }
       
   211 
       
   212     iConfigFileParsed = EFalse;
       
   213 
       
   214     // This active object has very low priority since XML parser uses Active objects also, 
       
   215     // so it is mandatory to let XML parser to complete sooner than this active object
       
   216     IssueRequest();
       
   217     iSchedulerWait.Start(); // Blocks until file is parsed
       
   218 
       
   219     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::InitConfig() - return" ) ) );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CSsyReferenceConfig::IssueRequest
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CSsyReferenceConfig::IssueRequest( TInt aError )
       
   227     {
       
   228     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::IssueRequest()" ) ) );
       
   229     // Provides synchronous function calls to be handled as asynchronous
       
   230     if ( !IsActive() )
       
   231         {
       
   232         SetActive();
       
   233         TRequestStatus *s = &iStatus;
       
   234 	    User::RequestComplete( s, aError );
       
   235         }
       
   236     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::IssueRequest() - return" ) ) );
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CSsyReferenceConfig::RunL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CSsyReferenceConfig::RunL()
       
   244     {
       
   245     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::RunL() - %i" ), iStatus.Int() ) );
       
   246 
       
   247     if ( iConfigFileParsed )
       
   248         {
       
   249         // Stop blocking
       
   250         iSchedulerWait.AsyncStop();
       
   251         }
       
   252     else
       
   253         {
       
   254         // Continue RunL loop
       
   255         IssueRequest();
       
   256         }
       
   257 
       
   258     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::RunL() - return" ) ) );
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CSsyReferenceConfig::DoCancel
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 void CSsyReferenceConfig::DoCancel()
       
   266     {
       
   267     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::DoCancel()" ) ) );
       
   268 
       
   269     // Stop blocking
       
   270     iSchedulerWait.AsyncStop();
       
   271     
       
   272     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::DoCancel() - return" ) ) );
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CSsyReferenceConfig::RunError
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 TInt CSsyReferenceConfig::RunError( TInt /*aError*/ )
       
   280     {
       
   281     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::RunError()" ) ) );
       
   282 
       
   283     // Handle possible errors here and return KErrNone to prevent SSY from panic
       
   284 
       
   285     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::RunError() - return" ) ) );
       
   286     return KErrNone;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CSsyReferenceConfig::ParseFileCompleteL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CSsyReferenceConfig::ParseFileCompleteL()
       
   294     {
       
   295     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ParseFileCompleteL()" ) ) );
       
   296     // First get document
       
   297     iConfigFile = iConfigParser->DetachXMLDoc();
       
   298     // Then get document element
       
   299     CMDXMLElement*  documentElement = iConfigFile->DocumentElement();
       
   300     // Get root element, 'SsyReferenceConfig'
       
   301     iSsyReferenceConfig = documentElement->FirstChildOfType( KSsyRefRootTag );
       
   302     // Get gereral information element 
       
   303     iGenralInfoElement = iSsyReferenceConfig->FirstChildOfType( KSsyRefGeneralInfoTag );
       
   304     // Get channel information group element
       
   305     iChannelGroupElement = iSsyReferenceConfig->FirstChildOfType( KSsyRefChannelInfoGroupTag );
       
   306     // Get channel count
       
   307     iChannelCount = GetAttributeIntValue( *iChannelGroupElement, KSsyRefChannelCount );
       
   308 
       
   309     // No need to delete documentElement, it is owned by iConfigFile.
       
   310     documentElement = NULL;
       
   311     iConfigFileParsed = ETrue;
       
   312 
       
   313     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ParseFileCompleteL() - return" ) ) );
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CSsyReferenceConfig::GetAttributeIntValue
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 TInt CSsyReferenceConfig::GetAttributeIntValue( CMDXMLElement& aElement, const TDesC& aAttrib )
       
   321     {
       
   322     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeIntValue()" ) ) );
       
   323     COMPONENT_TRACE( ( _L( "  Element: %s", aElement.NodeName() ) ) );
       
   324     COMPONENT_TRACE( ( _L( "  Attribute: %s", aAttrib ) ) );
       
   325 
       
   326     TInt intValue( 0 );
       
   327 
       
   328     // Check availability
       
   329     if ( aElement.IsAttributeSpecified( aAttrib ) )
       
   330         {
       
   331         // Buffer to where to read value
       
   332         TBufC<KSsyRefMaxAttribLength> buffer( KNullDesC );
       
   333         TPtrC ptr( buffer );
       
   334 
       
   335         // Read attribute value
       
   336         aElement.GetAttribute( aAttrib, ptr );
       
   337 
       
   338         // Cast literal value into TInt
       
   339         TLex lexValue( ptr );
       
   340         lexValue.Val( intValue );
       
   341         }
       
   342 
       
   343     COMPONENT_TRACE( ( _L( "  IntValue: %i", intValue ) ) );
       
   344     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeIntValue() - return" ) ) );
       
   345     return intValue;
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CSsyReferenceConfig::GetAttributeStrValue
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CSsyReferenceConfig::GetAttributeStrValue( CMDXMLElement& aElement, const TDesC& aAttrib, TDes8& aTarget )
       
   353     {
       
   354     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeStrValue()" ) ) );
       
   355     COMPONENT_TRACE( ( _L( "  Element: %s", aElement.NodeName() ) ) );
       
   356     COMPONENT_TRACE( ( _L( "  Attribute: %s", aAttrib ) ) );
       
   357 
       
   358     // Check availability
       
   359     if ( aElement.IsAttributeSpecified( aAttrib ) )
       
   360         {
       
   361         // Buffer to where to read value
       
   362         TBufC<KSsyRefMaxAttribLength> buffer( KNullDesC );
       
   363         TPtrC ptr( buffer );
       
   364 
       
   365         // Read attribute value
       
   366         aElement.GetAttribute( aAttrib, ptr );
       
   367 
       
   368         // Copy string from 16-bit descriptor to 8-bit descriptor
       
   369         aTarget.Copy( ptr );
       
   370         }
       
   371 
       
   372     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeStrValue() - return" ) ) );
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CSsyReferenceConfig::GetAttributeHexValue
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 TUint CSsyReferenceConfig::GetAttributeHexValue( CMDXMLElement& aElement, const TDesC& aAttrib )
       
   380     {
       
   381     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeHexValue()" ) ) );
       
   382     COMPONENT_TRACE( ( _L( "  Element: %s", aElement.NodeName() ) ) );
       
   383     COMPONENT_TRACE( ( _L( "  Attribute: %s", aAttrib ) ) );
       
   384 
       
   385     TUint32 hexValue( 0 );
       
   386 
       
   387     // Check availability
       
   388     if ( aElement.IsAttributeSpecified( aAttrib ) )
       
   389         {
       
   390         // Buffer to where to read value
       
   391         TBufC<KSsyRefMaxAttribLength> buffer( KNullDesC );
       
   392         TPtrC ptr( buffer );
       
   393 
       
   394         // Read attribute value
       
   395         aElement.GetAttribute( aAttrib, ptr );
       
   396 
       
   397         // Get bounded value and cast it into TUint32 (hex)
       
   398         TRadix radix( EHex );
       
   399         TUint limit( 0xFFFFFFFF );
       
   400 
       
   401         // Append string into Lex and skip first two characters, 0x
       
   402         TLex lexValue( ptr );
       
   403         lexValue.Inc( 2 );
       
   404 
       
   405         // Read value
       
   406         lexValue.BoundedVal( hexValue, radix, limit );
       
   407         }
       
   408 
       
   409     COMPONENT_TRACE( ( _L( "  HexValue: %x", hexValue ) ) );
       
   410     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeHexValue() - return" ) ) );
       
   411     return hexValue;
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // CSsyReferenceConfig::GetAttributeRealValue
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TReal CSsyReferenceConfig::GetAttributeRealValue( CMDXMLElement& aElement, const TDesC& aAttrib )
       
   419     {
       
   420     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeRealValue()" ) ) );
       
   421     COMPONENT_TRACE( ( _L( "  Element: %s", aElement.NodeName() ) ) );
       
   422     COMPONENT_TRACE( ( _L( "  Attribute: %s", aAttrib ) ) );
       
   423 
       
   424     TReal realValue( 0 );
       
   425 
       
   426     // Check availability
       
   427     if ( aElement.IsAttributeSpecified( aAttrib ) )
       
   428         {
       
   429 
       
   430         // Buffer to where to read value
       
   431         TBufC<KSsyRefMaxAttribLength> buffer( KNullDesC );
       
   432         TPtrC ptr( buffer );
       
   433 
       
   434         // Read attribute value
       
   435         aElement.GetAttribute( aAttrib, ptr );
       
   436 
       
   437         // Cast literal value into TReal
       
   438         TLex lexValue( ptr );
       
   439         TInt error = lexValue.Val( realValue );
       
   440         if( error!=KErrNone )
       
   441         	{
       
   442         	realValue = error;
       
   443         	}
       
   444         }
       
   445 
       
   446     COMPONENT_TRACE( ( _L( "  IntValue: %i", realValue ) ) );
       
   447     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetAttributeRealValue() - return" ) ) );
       
   448     return realValue;
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // CSsyReferenceConfig::ChannelCount
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 TInt CSsyReferenceConfig::ChannelCount()
       
   456     {
       
   457     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ChannelCount() - %i" ), iChannelCount ) );
       
   458     return iChannelCount;
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // CSsyReferenceConfig::GenerateChannels
       
   463 // ---------------------------------------------------------------------------
       
   464 //
       
   465 void CSsyReferenceConfig::GenerateChannels( RSensrvChannelInfoList& aChannelList )
       
   466     {
       
   467     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GenerateChannels()" ) ) );
       
   468 
       
   469     // Initialize channel pair array
       
   470     TSsyRefChannelIdArray tempArray( iChannelCount );
       
   471     iChannelPairArray = tempArray;
       
   472 
       
   473     // Go through Channel group element and get all information
       
   474     TSensrvChannelInfo channelInfo;
       
   475     CMDXMLElement* channelElement = iChannelGroupElement->FirstChildOfType( KSsyRefChannelItemTag );
       
   476 
       
   477     while( channelElement )
       
   478         {
       
   479         // check is element correct type of node
       
   480         if ( channelElement->NodeType() == CMDXMLNode::EElementNode )
       
   481             {
       
   482             // read channel identifier
       
   483             iChannelPairArray.Append( TSsyRefChannelIdPair( GetAttributeIntValue( *channelElement, KSsyRefChannelId ) ) );
       
   484 
       
   485             // Read attributes
       
   486             channelInfo.iContextType = ( TSensrvContextType ) GetAttributeIntValue( *channelElement, KSsyRefContextType );
       
   487             channelInfo.iQuantity = ( TSensrvQuantity ) GetAttributeIntValue( *channelElement, KSsyRefQuantity );
       
   488             channelInfo.iChannelType = ( TSensrvChannelTypeId ) GetAttributeHexValue( *channelElement, KSsyRefChannelType );
       
   489             GetAttributeStrValue( *channelElement, KSsyRefLocation, channelInfo.iLocation );
       
   490             GetAttributeStrValue( *channelElement, KSsyRefVendorId, channelInfo.iVendorId );
       
   491             channelInfo.iChannelDataTypeId = ( TSensrvChannelDataTypeId ) GetAttributeHexValue( *channelElement, KSsyRefDataTypeID );
       
   492             
       
   493             // Calculate data item size based on channel type
       
   494             switch ( channelInfo.iChannelType )
       
   495                 {
       
   496                 case KSensrvChannelTypeIdAccelerometerXYZAxisData:
       
   497                     {
       
   498                     channelInfo.iDataItemSize = KSsyRefAxisDataItemSize;
       
   499                     break;
       
   500                     }
       
   501                 case KSensrvChannelTypeIdProximityMonitor:
       
   502                     {
       
   503                     channelInfo.iDataItemSize = KSsyRefProximityDataItemSize;
       
   504                     break;
       
   505                     }
       
   506                 case KSensrvChannelTypeIdAccelerometerWakeupData:
       
   507                 case KSensrvChannelTypeIdAccelerometerDoubleTappingData:
       
   508                     {
       
   509                     channelInfo.iDataItemSize = KSsyRefTappingDataItemSize;
       
   510                     break;
       
   511                     }
       
   512                 default:
       
   513                     {
       
   514                     channelInfo.iDataItemSize = 0;
       
   515                     break;
       
   516                     }
       
   517                 }
       
   518 
       
   519             // Append channel info to list
       
   520             aChannelList.Append( channelInfo );
       
   521             }
       
   522         channelElement = static_cast<CMDXMLElement*>( channelElement->NextSibling() );
       
   523         }
       
   524 
       
   525     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GenerateChannels() - return" ) ) );
       
   526     }
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // CSsyReferenceConfig::GetChannelDataInformation
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CSsyReferenceConfig::GetChannelDataInformationL( 
       
   533     const TInt aSrvChannelId,
       
   534     TSsyRefDataItemArray& aDataItemList, 
       
   535     TInt& aStartInterval )
       
   536     {
       
   537     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetChannelDataInformation()" ) ) );
       
   538 
       
   539     // First, get correct config channel element corresponding to aSrvChannelId
       
   540     CMDXMLElement* channelElement = ChannelElement( aSrvChannelId );
       
   541 
       
   542     if ( channelElement )
       
   543         {
       
   544         // Channel element found, get channel data group element
       
   545         CMDXMLElement* groupElement = channelElement->FirstChildOfType( KSsyRefChannelDataTag );
       
   546         
       
   547         if ( groupElement )
       
   548             {
       
   549             // Get start interval
       
   550             aStartInterval = GetAttributeIntValue( *groupElement, KSsyRefStartInterval );
       
   551 
       
   552             // First, loop channel data items to get total count
       
   553             CMDXMLElement* dataItemElement = groupElement->FirstChildOfType( KSsyRefChannelDataItemTag );
       
   554 
       
   555             // Take channel data item type at this point. One channel can produce only one type of
       
   556             // channel data item
       
   557             TUint channelType( GetAttributeHexValue( *dataItemElement, KSsyRefDataTypeID ) );
       
   558 
       
   559             TInt channelItemCount( 0 ); // Total number of data items
       
   560             TInt definitionCount( 0 );  // Total number of different definitions
       
   561 
       
   562             // Go through elements and get counters
       
   563             while ( dataItemElement )
       
   564                 {
       
   565                 definitionCount++;
       
   566                 channelItemCount = channelItemCount + GetAttributeIntValue( *dataItemElement, KSsyRefDataItemCount );
       
   567                 // This will return NULL if no next sibling found
       
   568                 dataItemElement = static_cast<CMDXMLElement*>( dataItemElement->NextSibling() );
       
   569                 }
       
   570 
       
   571             // Now, start all over to get item information
       
   572             dataItemElement = groupElement->FirstChildOfType( KSsyRefChannelDataItemTag );
       
   573 
       
   574             // Create temp array now that we know the data item count
       
   575             TSsyRefDataItemArray tempArray( channelItemCount );
       
   576 
       
   577             for ( TInt i = 0; i < definitionCount; i++ )
       
   578                 {
       
   579                 // Check element type
       
   580                 if ( dataItemElement->NodeType() == CMDXMLNode::EElementNode )
       
   581                     {
       
   582                     // First we get interval and count from channel item
       
   583                     TInt interval( GetAttributeIntValue( *dataItemElement, KSsyRefInterval ) );
       
   584                     TInt countOfType( GetAttributeIntValue( *dataItemElement, KSsyRefDataItemCount ) );
       
   585 
       
   586                     // Read next child values to corresponding data type class
       
   587                     switch ( channelType )
       
   588                         {
       
   589                         case TSensrvAccelerometerAxisData::KDataTypeId:
       
   590                             {
       
   591                             CMDXMLElement* axisDataElement = dataItemElement->FirstChildOfType( KSsyRefAxisDataItemTag );
       
   592                             TInt axisX( GetAttributeIntValue( *axisDataElement, KSsyRefXAxis ) );
       
   593                             TInt axisY( GetAttributeIntValue( *axisDataElement, KSsyRefYAxis ) );
       
   594                             TInt axisZ( GetAttributeIntValue( *axisDataElement, KSsyRefZAxis ) );
       
   595 
       
   596                             // Create channel data type item
       
   597                             TSsyRefChannelDataAxis channelData( axisX, axisY, axisZ, interval );
       
   598                             // add items into array
       
   599                             for ( TInt k = 0; k < countOfType; k++ )
       
   600                                 {
       
   601                                 tempArray.Append( channelData );
       
   602                                 }
       
   603                             break;
       
   604                             }
       
   605                         case TSensrvTappingData::KDataTypeId:
       
   606                             {
       
   607                             CMDXMLElement* tappingDataElement = dataItemElement->FirstChildOfType( KSsyRefTappingDataItemTag );
       
   608                             TInt direction( GetAttributeHexValue( *tappingDataElement, KSsyRefDirection ) );
       
   609                             
       
   610                             // Create channel data type item
       
   611                             TSsyRefChannelDataTapping channelData( direction, interval );
       
   612                             // add items into array
       
   613                             for ( TInt k = 0; k < countOfType; k++ )
       
   614                                 {
       
   615                                 tempArray.Append( channelData );
       
   616                                 }
       
   617                             break;
       
   618                             }
       
   619                         case TSensrvProximityData::KDataTypeId:
       
   620                             {
       
   621                             CMDXMLElement* proximityDataElement = dataItemElement->FirstChildOfType( KSsyRefProximityDataItemTag );
       
   622                             TInt state( GetAttributeIntValue( *proximityDataElement, KSsyRefProximityState ) );
       
   623                             
       
   624                             // Create channel data type item
       
   625                             TSsyRefChannelDataProximity channelData( state, interval );
       
   626                             // add items into array
       
   627                             for ( TInt k = 0; k < countOfType; k++ )
       
   628                                 {
       
   629                                 tempArray.Append( channelData );
       
   630                                 }
       
   631                             break;
       
   632                             }
       
   633                         default:
       
   634                             {
       
   635                             // Other data items are not supported
       
   636                             User::Leave( KErrGeneral );
       
   637                             }
       
   638                         }
       
   639                     }
       
   640 
       
   641                 // Get next channel data item element
       
   642                 dataItemElement = static_cast<CMDXMLElement*>( dataItemElement->NextSibling() );
       
   643                 }
       
   644 
       
   645             // Compress temp array in case there were comments
       
   646             tempArray.Compress();
       
   647 
       
   648             // copy information to param array
       
   649             aDataItemList = tempArray;
       
   650             }
       
   651         else
       
   652             {
       
   653             User::Leave( KErrNotFound );
       
   654             }
       
   655         }
       
   656     else
       
   657         {
       
   658         User::Leave( KErrNotFound );
       
   659         }
       
   660 
       
   661     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetChannelDataInformation() - return" ) ) );
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // CSsyReferenceConfig::GetElementPropertiesL
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CSsyReferenceConfig::GetElementPropertiesL( 
       
   669     CMDXMLElement& aElement, 
       
   670     RSensrvPropertyList& aPropertyList )
       
   671     {
       
   672     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetElementPropertiesL()" ) ) );
       
   673 
       
   674     // First we need 'Properties' element
       
   675     CMDXMLElement* properties = aElement.FirstChildOfType( KSsyRefProperties );
       
   676 
       
   677     if ( !properties )
       
   678         {
       
   679         // Wrong element... or properties are not defined
       
   680         User::Leave( KErrNotFound );
       
   681         }
       
   682 
       
   683     // Get first property get started
       
   684     CMDXMLElement* propertyItem = properties->FirstChildOfType( KSsyRefPropertyItem );
       
   685     TInt propertyCount( 0 );
       
   686 
       
   687     // Loop properties to get count of properties
       
   688     while ( propertyItem )
       
   689         {
       
   690         propertyCount++;
       
   691         propertyItem = static_cast<CMDXMLElement*>( propertyItem->NextSibling() ); // returns NULL if next not found
       
   692         }
       
   693     
       
   694     if ( !propertyCount )
       
   695         {
       
   696         // Check that there are properties
       
   697         User::Leave( KErrNotFound );
       
   698         }
       
   699 
       
   700     // Temporary property list now that we know the property count
       
   701     RSensrvPropertyList tempList( propertyCount );
       
   702 
       
   703     // Start loop again from the start and read each property
       
   704     propertyItem = properties->FirstChildOfType( KSsyRefPropertyItem );
       
   705     for ( TInt i = 0; i < propertyCount; i++ )
       
   706         {
       
   707         // Check element type
       
   708         if ( propertyItem->NodeType() == CMDXMLNode::EElementNode )
       
   709             {
       
   710             // Read property values
       
   711             const TSensrvPropertyId propertyId( ( TSensrvPropertyId )GetAttributeHexValue( *propertyItem, KSsyRefPropertyId ) );
       
   712             const TInt itemIndex( GetAttributeIntValue( *propertyItem, KSsyRefItemIndex ) );
       
   713             const TBool readOnly( ( TBool )GetAttributeIntValue( *propertyItem, KSsyRefReadOnly ) );
       
   714             const TSensrvPropertyType propertyType( ( TSensrvPropertyType ) GetAttributeIntValue( *propertyItem, KSsyRefPropertyType ) );
       
   715 
       
   716             // Array index must be handled in different way as it is not mandatory and it may not exist in XML file
       
   717             TInt arrayIndex( ESensrvSingleProperty );
       
   718 
       
   719             // Extra check is needed, otherwise this value is always '0' when it should be 'ESensrvSingleProperty' by default
       
   720             if ( propertyItem->IsAttributeSpecified( KSsyRefArrayIndex ) )
       
   721                 {
       
   722                 // Attribute exists, now we can read the value
       
   723                 arrayIndex = GetAttributeIntValue( *propertyItem, KSsyRefArrayIndex );
       
   724                 }
       
   725 
       
   726             // Resolve type, get correct type value and append property into list
       
   727             switch ( propertyType )
       
   728                 {
       
   729                 case ESensrvIntProperty:
       
   730                     {
       
   731                     const TInt intValue( GetAttributeIntValue( *propertyItem, KSsyRefPropertyValue ) );
       
   732                     const TInt maxValue( GetAttributeIntValue( *propertyItem, KSsyRefMaxValue ) );
       
   733                     const TInt minValue( GetAttributeIntValue( *propertyItem, KSsyRefMinValue ) );
       
   734                     TSensrvProperty property( propertyId, itemIndex, intValue, maxValue, minValue, readOnly, propertyType );
       
   735                     property.SetArrayIndex( arrayIndex );
       
   736                     tempList.Append( property );
       
   737                     break;
       
   738                     }
       
   739                  case ESensrvRealProperty:
       
   740                     {
       
   741                     const TReal intValue( GetAttributeRealValue( *propertyItem, KSsyRefPropertyValue ) );
       
   742                     const TReal maxValue( GetAttributeRealValue( *propertyItem, KSsyRefMaxValue ) );
       
   743                     const TReal minValue( GetAttributeRealValue( *propertyItem, KSsyRefMinValue ) );
       
   744                     TSensrvProperty property( propertyId, itemIndex, intValue, maxValue, minValue, readOnly, propertyType );
       
   745                     property.SetArrayIndex( arrayIndex );
       
   746                     tempList.Append( property );
       
   747                     break;
       
   748                     }
       
   749                  case ESensrvBufferProperty:
       
   750                     {
       
   751                     TBuf8<KSensrvPropertyTextBufferSize> desValue;
       
   752                     GetAttributeStrValue( *propertyItem, KSsyRefPropertyValue, desValue );
       
   753                     TSensrvProperty property( propertyId, itemIndex, desValue, readOnly, propertyType );
       
   754                     property.SetArrayIndex( arrayIndex );
       
   755                     tempList.Append( property );
       
   756                     break;
       
   757                     }
       
   758                 default:
       
   759                     {
       
   760                     // Unknown property type -> leave
       
   761                     User::Leave( KErrArgument );    
       
   762                     }
       
   763                 }
       
   764             }
       
   765 
       
   766         // Next property
       
   767         propertyItem = static_cast<CMDXMLElement*>( propertyItem->NextSibling() ); // returns NULL if next not found
       
   768         }
       
   769 
       
   770     // Compress temp list in case there were comment nodes
       
   771     tempList.Compress();
       
   772 
       
   773     // copy temp list to parameter list
       
   774     aPropertyList = tempList;
       
   775 
       
   776     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetElementPropertiesL() - return" ) ) );
       
   777     }
       
   778 
       
   779 // ---------------------------------------------------------------------------
       
   780 // CSsyReferenceConfig::ChannelElement
       
   781 // ---------------------------------------------------------------------------
       
   782 //
       
   783 CMDXMLElement* CSsyReferenceConfig::ChannelElement( const TInt aSrvChannelId )
       
   784     {
       
   785     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ChannelElement()" ) ) );
       
   786 
       
   787     const TInt configId( ConfigChannelId( aSrvChannelId ) );
       
   788     TBool channelFound( EFalse );
       
   789     
       
   790     // Loop channel group and match configId for the channel ID in element
       
   791     CMDXMLElement* channelItemElement = iChannelGroupElement->FirstChildOfType( KSsyRefChannelItemTag );
       
   792     
       
   793     for ( TInt i = 0; i < iChannelCount && !channelFound; i++ )
       
   794         {
       
   795         TInt channelId( GetAttributeIntValue( *channelItemElement, KSsyRefChannelId ) );
       
   796         if ( configId == channelId  )
       
   797             {
       
   798             // Channel found, no  need to loop
       
   799             channelFound = ETrue;
       
   800             }
       
   801         else
       
   802             {
       
   803             // Take next channel
       
   804             channelItemElement = static_cast<CMDXMLElement*>( channelItemElement->NextSibling() );
       
   805             }
       
   806         }
       
   807 
       
   808     // If not found, return NULL
       
   809     if ( !channelFound )
       
   810         {
       
   811         channelItemElement = NULL;
       
   812         }
       
   813 
       
   814     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ChannelElement() - return" ) ) );
       
   815     return channelItemElement;
       
   816     }
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // CSsyReferenceConfig::UpdateChannelIds
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 void CSsyReferenceConfig::UpdateChannelIds( RSensrvChannelInfoList aChannelList )
       
   823     {
       
   824     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::UpdateChannelIds()" ) ) );
       
   825     
       
   826 
       
   827     if ( ChannelCount() == aChannelList.Count() )
       
   828         {
       
   829         for ( TInt i = 0; i < aChannelList.Count(); i++ )
       
   830             {
       
   831             iChannelPairArray[i].SetServerId( aChannelList[i].iChannelId );
       
   832             }
       
   833         }
       
   834     
       
   835     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::UpdateChannelIds() - return" ) ) );
       
   836     }
       
   837 
       
   838 // ---------------------------------------------------------------------------
       
   839 // CSsyReferenceConfig::ConfigChannelId
       
   840 // ---------------------------------------------------------------------------
       
   841 //
       
   842 TInt CSsyReferenceConfig::ConfigChannelId( const TInt aSrvChannelId ) const
       
   843     {
       
   844     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ConfigChannelId()" ) ) );    
       
   845     TInt returnValue( 0 );
       
   846     
       
   847     for ( TInt i = 0; i < iChannelPairArray.Count(); i++ )
       
   848         {
       
   849         if ( iChannelPairArray[i].ServerId() == aSrvChannelId )
       
   850             {
       
   851             returnValue = iChannelPairArray[i].ConfigId();
       
   852             }
       
   853         }
       
   854     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::ConfigChannelId() - return" ) ) );
       
   855     return returnValue;
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CSsyReferenceConfig::GetSensorPropertiesL
       
   860 // ---------------------------------------------------------------------------
       
   861 //
       
   862 void CSsyReferenceConfig::GetSensorPropertiesL( RSensrvPropertyList& aPropertyList )
       
   863     {
       
   864     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetSensorPropertiesL()" ) ) );
       
   865 
       
   866     // We already have SsyGeneralInformation element, read properties from that
       
   867     GetElementPropertiesL( *iGenralInfoElement, aPropertyList );
       
   868 
       
   869     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetSensorPropertiesL() - return" ) ) );
       
   870     }
       
   871 
       
   872 // ---------------------------------------------------------------------------
       
   873 // CSsyReferenceConfig::GetChannelPropertiesL
       
   874 // ---------------------------------------------------------------------------
       
   875 //
       
   876 void CSsyReferenceConfig::GetChannelPropertiesL( 
       
   877     const TInt aSrvChannelId, 
       
   878     RSensrvPropertyList& aPropertyList )
       
   879     {
       
   880     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetChannelPropertiesL()" ) ) );
       
   881 
       
   882     // Get channel element first
       
   883     CMDXMLElement* channelElement = ChannelElement( aSrvChannelId );
       
   884 
       
   885     if ( !channelElement )
       
   886         {
       
   887         // Leave, channel element is not found
       
   888         User::Leave( KErrNotFound );
       
   889         }
       
   890 
       
   891     // Get properties of this channel element
       
   892     GetElementPropertiesL( *channelElement, aPropertyList );
       
   893 
       
   894     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceConfig::GetChannelPropertiesL() - return" ) ) );
       
   895     }
       
   896