sensorservices/orientationssy/src/SsyProperty.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2007 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 "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Property class of Orientation SSY
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Includes
       
    20 #include "SsyConfiguration.h"
       
    21 #include "SsyProperty.h"
       
    22 #include "SsyTrace.h"
       
    23 
       
    24 
       
    25 // ----------------------------------------------------------------------------------
       
    26 // FindMatchingProperty()
       
    27 // Helper function for find a matching property in an array.
       
    28 // ----------------------------------------------------------------------------------
       
    29 // 
       
    30 TBool FindMatchingProperty
       
    31         ( const TSSyChannelProperties& aLeft,
       
    32           const TSSyChannelProperties& aRight )
       
    33 	{
       
    34     if ( ( aLeft.iPropertyId == aRight.iPropertyId ) &&
       
    35          ( aLeft.iItemIndex == aRight.iItemIndex ) )
       
    36         {
       
    37         return ETrue;
       
    38         }
       
    39 
       
    40 	return EFalse;
       
    41 	}
       
    42 
       
    43 // ----------------------------------------------------------------------------------
       
    44 // CSSYProperty::CSSYProperty()
       
    45 // ----------------------------------------------------------------------------------
       
    46 //  
       
    47 CSSYProperty::CSSYProperty( const TInt /*aSensorNumber*/, 
       
    48                             const TSSyChannelProperties* aProperties, 
       
    49                             const TInt aNumberOfProperties )
       
    50     {
       
    51     SSY_TRACE_IN();
       
    52 
       
    53     for ( TInt index = 0; index < aNumberOfProperties ; index++ )
       
    54         {
       
    55         iChannelProperties.Append( aProperties[ index ] );
       
    56         }
       
    57 
       
    58     SSY_TRACE_OUT();
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------------
       
    62 // CSSYProperty::~CSSYProperty()
       
    63 // ----------------------------------------------------------------------------------
       
    64 // 
       
    65 CSSYProperty::~CSSYProperty()
       
    66     {
       
    67     SSY_TRACE_IN();
       
    68 
       
    69     iRegisteredChannels.Reset();
       
    70     iChannelProperties.Reset();
       
    71     iChannelProperties.Close();
       
    72     iRegisteredChannels.Close();
       
    73 
       
    74     SSY_TRACE_OUT();
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------------
       
    78 // CSSYProperty::RegisterChannel()
       
    79 // ----------------------------------------------------------------------------------
       
    80 //  
       
    81 TInt CSSYProperty::RegisterChannel( const TSensrvChannelId aChannelID )
       
    82     {
       
    83     SSY_TRACE_IN();
       
    84     SSY_TRACE( EExtended, "ORIENTATIONSSY:Register channelId %d", aChannelID );
       
    85 
       
    86     for ( TInt index = 0; index < iRegisteredChannels.Count(); index++ )
       
    87         {
       
    88         if ( iRegisteredChannels[index] == aChannelID )
       
    89             {
       
    90             return KErrAlreadyExists;
       
    91             }
       
    92         }
       
    93 
       
    94     iRegisteredChannels.Append( aChannelID );
       
    95 
       
    96     SSY_TRACE_OUT();
       
    97     return KErrNone;
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------------
       
   101 // CSSYProperty::FindPropertyIndex()
       
   102 // ----------------------------------------------------------------------------------
       
   103 //  
       
   104 TInt CSSYProperty::FindPropertyIndex( const TSensrvProperty& aProperty )
       
   105     {
       
   106     SSY_TRACE_IN();
       
   107 
       
   108     // find the property
       
   109     TIdentityRelation<TSSyChannelProperties> findFunction( FindMatchingProperty );
       
   110     TSSyChannelProperties property;
       
   111     property.iPropertyId = aProperty.GetPropertyId();
       
   112     property.iItemIndex = aProperty.PropertyItemIndex();
       
   113     property.iPropertyType = aProperty.PropertyType();
       
   114 
       
   115     SSY_TRACE( EExtended, "ORIENTATIONSSY:Find property: id:%d index:%d type:%d", property.iPropertyId, property.iItemIndex, property.iPropertyType );
       
   116 
       
   117     TInt index = iChannelProperties.Find( property, findFunction );
       
   118 
       
   119     SSY_TRACE_OUT();
       
   120     return index;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------------
       
   124 // CSSYProperty::GetProperty()
       
   125 // ----------------------------------------------------------------------------------
       
   126 //  
       
   127 TInt CSSYProperty::GetProperty( TSensrvProperty& aProperty )
       
   128     {
       
   129     SSY_TRACE_IN();
       
   130 
       
   131     TInt returnValue( KErrNone );
       
   132     TInt index = FindPropertyIndex( aProperty );
       
   133     
       
   134     if ( index == KErrNotFound )
       
   135         {
       
   136         SSY_TRACE( EExtended, "ORIENTATIONSSY:Property not found" );
       
   137         returnValue = KErrNotFound;
       
   138         }
       
   139     else if( iChannelProperties.Count() >= index )
       
   140         {
       
   141         switch ( iChannelProperties[ index ].iPropertyType )
       
   142             {
       
   143             case ESensrvIntProperty:
       
   144                 {
       
   145                 TSensrvProperty property
       
   146                     (
       
   147                     iChannelProperties[ index ].iPropertyId,
       
   148                     iChannelProperties[ index ].iItemIndex,
       
   149                     iChannelProperties[ index ].iIntValue,
       
   150                     iChannelProperties[ index ].iIntMaxValue,
       
   151                     iChannelProperties[ index ].iIntMinValue,
       
   152                     iChannelProperties[ index ].iReadOnly,
       
   153                     iChannelProperties[ index ].iPropertyType
       
   154                     );
       
   155                 aProperty = property;
       
   156                 break;
       
   157                 }
       
   158             case ESensrvRealProperty:
       
   159                 {
       
   160                 TSensrvProperty property
       
   161                     (
       
   162                     iChannelProperties[ index ].iPropertyId,
       
   163                     iChannelProperties[ index ].iItemIndex,
       
   164                     iChannelProperties[ index ].iRealValue,
       
   165                     iChannelProperties[ index ].iRealMaxValue,
       
   166                     iChannelProperties[ index ].iRealMinValue,
       
   167                     iChannelProperties[ index ].iReadOnly,
       
   168                     iChannelProperties[ index ].iPropertyType
       
   169                     );
       
   170                 aProperty = property;
       
   171                 break;
       
   172                 }
       
   173             case ESensrvBufferProperty:
       
   174                 {
       
   175                 TSensrvProperty property
       
   176                     (
       
   177                     iChannelProperties[ index ].iPropertyId,
       
   178                     iChannelProperties[ index ].iItemIndex,
       
   179                     iChannelProperties[ index ].iBufValue,
       
   180                     iChannelProperties[ index ].iReadOnly,
       
   181                     iChannelProperties[ index ].iPropertyType
       
   182                     );
       
   183                 aProperty = property;
       
   184                 break;
       
   185                 }
       
   186             default:
       
   187                 {
       
   188                 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Invalid propertype type!" );
       
   189                 ASSERT_DEBUG_SSY( 0 );
       
   190                 returnValue = KErrGeneral;
       
   191                 break;
       
   192                 }
       
   193             }
       
   194         }
       
   195 
       
   196     SSY_TRACE_OUT();
       
   197     return returnValue;
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------------
       
   201 // CSSYProperty::GetAllProperties()
       
   202 // ----------------------------------------------------------------------------------
       
   203 //  
       
   204 TInt CSSYProperty::GetAllProperties( RSensrvPropertyList& aChannelPropertyList )
       
   205     {
       
   206     SSY_TRACE_IN();
       
   207     TInt returnValue( KErrNone );
       
   208     aChannelPropertyList.Reset();
       
   209     
       
   210     for ( TInt index = 0; index < iChannelProperties.Count(); index++ )
       
   211         {
       
   212         switch ( iChannelProperties[ index ].iPropertyType )
       
   213             {
       
   214             case ESensrvIntProperty:
       
   215                 {
       
   216                 TSensrvProperty property
       
   217                     (
       
   218                     iChannelProperties[ index ].iPropertyId,
       
   219                     iChannelProperties[ index ].iItemIndex,
       
   220                     iChannelProperties[ index ].iIntValue,
       
   221                     iChannelProperties[ index ].iIntMaxValue,
       
   222                     iChannelProperties[ index ].iIntMinValue,
       
   223                     iChannelProperties[ index ].iReadOnly,
       
   224                     iChannelProperties[ index ].iPropertyType
       
   225                     );
       
   226                 aChannelPropertyList.Append( property );
       
   227                 break;
       
   228                 }
       
   229             case ESensrvRealProperty:
       
   230                 {
       
   231                 TSensrvProperty property
       
   232                     (
       
   233                     iChannelProperties[ index ].iPropertyId,
       
   234                     iChannelProperties[ index ].iItemIndex,
       
   235                     iChannelProperties[ index ].iRealValue,
       
   236                     iChannelProperties[ index ].iRealMaxValue,
       
   237                     iChannelProperties[ index ].iRealMinValue,
       
   238                     iChannelProperties[ index ].iReadOnly,
       
   239                     iChannelProperties[ index ].iPropertyType
       
   240                     );
       
   241                 aChannelPropertyList.Append( property );
       
   242                 break;
       
   243                 }
       
   244             case ESensrvBufferProperty:
       
   245                 {
       
   246                 TSensrvProperty property
       
   247                     (
       
   248                     iChannelProperties[ index ].iPropertyId,
       
   249                     iChannelProperties[ index ].iItemIndex,
       
   250                     iChannelProperties[ index ].iBufValue,
       
   251                     iChannelProperties[ index ].iReadOnly,
       
   252                     iChannelProperties[ index ].iPropertyType
       
   253                     );
       
   254                 aChannelPropertyList.Append( property );
       
   255                 break;
       
   256                 }
       
   257             default:
       
   258                 {
       
   259                 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Invalid property type!" );
       
   260                 ASSERT_DEBUG_SSY( 0 );
       
   261                 returnValue = KErrGeneral;
       
   262                 break;
       
   263                 }
       
   264             }
       
   265         }
       
   266 
       
   267     SSY_TRACE_OUT();
       
   268     return returnValue;
       
   269     }
       
   270 
       
   271 // ----------------------------------------------------------------------------------
       
   272 // CSSYProperty::SetProperty()
       
   273 // ----------------------------------------------------------------------------------
       
   274 //  
       
   275 TInt CSSYProperty::SetProperty( 
       
   276     const TSensrvProperty& aProperty, 
       
   277     RSensrvChannelList& aAffectedChannels )
       
   278     {
       
   279     SSY_TRACE_IN();
       
   280 
       
   281     TInt intValue( 0 );
       
   282     TReal realValue( 0 );
       
   283     TInt returnValue( KErrNone );
       
   284     TInt index = FindPropertyIndex( aProperty );
       
   285     aAffectedChannels.Reset();
       
   286     
       
   287     if ( index == KErrNotFound )
       
   288         {
       
   289         SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Property not found: 0x%x", aProperty.GetPropertyId() );
       
   290         returnValue = KErrNotFound;
       
   291         }
       
   292     else if ( iChannelProperties[ index ].iReadOnly )
       
   293         {
       
   294         SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to set a readonly property: 0x%x", aProperty.GetPropertyId() );
       
   295         returnValue = KErrGeneral;
       
   296         }
       
   297 
       
   298     else if ( aProperty.GetPropertyId() == KSensrvPropIdDataRate )
       
   299         {
       
   300         SSY_TRACE( EExtended, "ORIENTATIONSSY: Updating data rate property" );
       
   301         // Data rate property is replaced in a different way than others.
       
   302         // Note that this can be done only once as this property is set to read only.
       
   303         aProperty.GetValue( intValue );
       
   304         // Leave value to 0, update only max value because that is the only value we can provide
       
   305         if( iChannelProperties.Count() >= index )
       
   306             {
       
   307             iChannelProperties[index].iIntMaxValue = intValue;
       
   308             iChannelProperties[index].iReadOnly = ETrue;
       
   309             }
       
   310         
       
   311         // No need to get data rate anymore as it's already got
       
   312         iDataRateUpdate = ETrue;
       
   313         }
       
   314     else if( iChannelProperties.Count() >= index )
       
   315         {
       
   316         switch ( iChannelProperties[index].iPropertyType )
       
   317             {
       
   318             case ESensrvIntProperty:
       
   319                 {
       
   320                 aProperty.GetValue( intValue );
       
   321 
       
   322                 if ( iChannelProperties[ index ].iIntValue == intValue )
       
   323                     {
       
   324                     SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to set a property to a same value that it already has: 0x%x", aProperty.GetPropertyId() );
       
   325                     returnValue = KErrAlreadyExists;
       
   326                     }
       
   327                 else
       
   328                     {
       
   329                     iChannelProperties[ index ].iIntValue = intValue;
       
   330                     }
       
   331                 break;
       
   332                 }
       
   333             case ESensrvRealProperty:
       
   334                 {
       
   335                 aProperty.GetValue( realValue );
       
   336                 iChannelProperties[ index ].iRealValue = realValue;
       
   337                 break;
       
   338                 }
       
   339             case ESensrvBufferProperty:
       
   340             default:
       
   341                 {
       
   342                 SSY_TRACE( EError, "ORIENTATIONSSY:ERROR: Trying to set a buffer property value, this is not supported at the moment: 0x%x", aProperty.GetPropertyId() );
       
   343                 // no buffer value can be set at the moment, and other values are not supported
       
   344                 returnValue = KErrArgument;
       
   345                 break;
       
   346                 }
       
   347             }
       
   348 
       
   349         if ( KErrNone == returnValue )
       
   350             {
       
   351             for ( TInt index = 0; index < iRegisteredChannels.Count(); index++ )
       
   352                 {
       
   353                 aAffectedChannels.Append( iRegisteredChannels[index] );
       
   354                 }
       
   355             }
       
   356         }
       
   357 
       
   358     SSY_TRACE_OUT();
       
   359     return returnValue;
       
   360     }
       
   361 
       
   362 // ----------------------------------------------------------------------------------
       
   363 // CSSYProperty::GetAffectedChannels()
       
   364 // ----------------------------------------------------------------------------------
       
   365 //  
       
   366 void CSSYProperty::GetAffectedChannels( RSensrvChannelList& aAffectedChannels )
       
   367     {
       
   368     SSY_TRACE_IN();
       
   369 
       
   370     aAffectedChannels.Reset();
       
   371     
       
   372     for ( TInt index = 0; index < iRegisteredChannels.Count(); index++ )
       
   373         {
       
   374         aAffectedChannels.Append( iRegisteredChannels[index] );
       
   375         }
       
   376 
       
   377     SSY_TRACE_OUT();
       
   378     }
       
   379 
       
   380 // ----------------------------------------------------------------------------------
       
   381 // CSSYProperty::DataRateUpdated()
       
   382 // ----------------------------------------------------------------------------------
       
   383 //  
       
   384 TBool CSSYProperty::DataRateUpdated()
       
   385     {
       
   386     return iDataRateUpdate;
       
   387     }
       
   388 
       
   389 // End of File