localconnectivityservice/generichid/src/hidreporttranslator.cpp
branchRCL_3
changeset 42 0aa8cc770c8a
equal deleted inserted replaced
40:453dfc402455 42:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Report base class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 
       
    21 #include "hidtranslate.h"
       
    22 #include "hidreportroot.h"
       
    23 #include "hidinterfaces.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C TReportTranslator::TReportTranslator(
       
    32     const TDesC8& aData,
       
    33     const CField *aField)
       
    34     : iData(aData), iField(aField)
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // GetValue()
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C TInt TReportTranslator::GetValue(TInt& aValue, TInt aUsageId,
       
    43     TInt aControlOffset /*= 0*/) const
       
    44     {
       
    45     TInt usageIndex = 0;
       
    46 
       
    47     if ( iField && TReportUtils::GetIndexOfUsage(iField, aUsageId, usageIndex) )
       
    48         {
       
    49         if ( iField->IsArray() )
       
    50             {
       
    51             // Convert usage ID to logical value
       
    52             TInt logicalValue = usageIndex + iField->LogicalMin();
       
    53 
       
    54             // Find logical value in the array
       
    55             for ( TInt i = 0; i < iField->Count(); i++ )
       
    56                 {
       
    57                 TInt value = 0;
       
    58                 TInt error = TReportUtils::ReadData(iData, iField, i, value);
       
    59 
       
    60                 if ( KErrNone != error )
       
    61                     {
       
    62                     return error;
       
    63                     }
       
    64 
       
    65                 if ( value == logicalValue )
       
    66                     {
       
    67                     aValue = ETrue;
       
    68                     return KErrNone;
       
    69                     }
       
    70                 }
       
    71 
       
    72             aValue = EFalse;
       
    73             return KErrNone;
       
    74             }
       
    75         else
       
    76             {
       
    77             return TReportUtils::ReadData(iData, iField, usageIndex + aControlOffset, aValue);
       
    78             }
       
    79         }
       
    80 
       
    81     return KErrUsageNotFound;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // ValueL()
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C TInt TReportTranslator::ValueL(TInt aUsageId,
       
    89     TInt aControlOffset /*= 0*/) const
       
    90     {
       
    91     TInt value = 0;
       
    92 
       
    93     User::LeaveIfError(GetValue(value, aUsageId, aControlOffset));
       
    94 
       
    95     return value;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // GetUsageId()
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C TInt TReportTranslator::GetUsageId(TInt& aUsageId, TInt aIndex) const
       
   103     {
       
   104     TInt logicalValue = 0;
       
   105     TInt error = KErrNoMemory;
       
   106 
       
   107     if ( iField )
       
   108         {
       
   109         error = TReportUtils::ReadData(iData, iField, aIndex, logicalValue);
       
   110 
       
   111         if ( KErrNone == error )
       
   112             {
       
   113             if ( iField->IsArray() )
       
   114                 {
       
   115                 // The logical value is a usage index
       
   116                 aUsageId = TReportUtils::UsageAtIndex(iField, logicalValue -
       
   117                     iField->LogicalMin());
       
   118                 }
       
   119             else
       
   120                 {
       
   121                 // Treat the logical value as an on/off control for the usage
       
   122                 aUsageId = ( logicalValue ) ? TReportUtils::UsageAtIndex(iField, 
       
   123                     aIndex) : 0;
       
   124                 }
       
   125             }
       
   126         }
       
   127 
       
   128     return error;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // GetUsageId()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C TInt TReportTranslator::UsageIdL(TInt aIndex) const
       
   136     {
       
   137     TInt usageId = 0;
       
   138 
       
   139     User::LeaveIfError(GetUsageId(usageId, aIndex));
       
   140 
       
   141     return usageId;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // RawValueL()
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C TInt TReportTranslator::RawValueL(TInt aIndex) const
       
   149     {
       
   150     TInt value = 0;
       
   151     User::LeaveIfNull(const_cast<CField*>(iField));
       
   152     User::LeaveIfError(TReportUtils::ReadData(iData, iField, aIndex, value));
       
   153     return value;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Count()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TInt TReportTranslator::Count() const
       
   161     {
       
   162     TInt count = 0;
       
   163 
       
   164     if (iField)
       
   165         {
       
   166         count = iField->Count();
       
   167         }
       
   168 
       
   169     return count;
       
   170     }