localconnectivityservice/generichid/src/hidreportroot.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     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:  Reportroot implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32debug.h>
       
    20 
       
    21 #include "hidreportroot.h"
       
    22 #include "debug.h"
       
    23 
       
    24 const TInt KSevenBits  = 7;
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // NewLC()
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CReportRoot* CReportRoot::NewLC()
       
    33     {
       
    34     CReportRoot* self = new (ELeave) CReportRoot();
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     return self;
       
    38     }
       
    39 // -----------------------------------------------------------------------------
       
    40 // NewL()
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CReportRoot* CReportRoot::NewL()
       
    44     {
       
    45     CReportRoot* self = NewLC();
       
    46     CleanupStack::Pop(self);
       
    47     return self;
       
    48     }
       
    49 // -----------------------------------------------------------------------------
       
    50 // ~CReportRoot()
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CReportRoot::~CReportRoot()
       
    54     {
       
    55     iSizes.Reset();
       
    56     iSizes.Close();
       
    57     }
       
    58 // -----------------------------------------------------------------------------
       
    59 // CReportRoot()
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CReportRoot::CReportRoot()
       
    63     {
       
    64     // Nothing to do here
       
    65     }
       
    66 
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // IncrementReportSizeL()
       
    71 // Manage the report ID <-> size "map":
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CReportRoot::IncrementReportSizeL(TInt aReportId,
       
    75     CField::TType aType, TInt aIncrement)
       
    76     {
       
    77     TInt index = FindReportSizeIndex(aReportId, aType);
       
    78 
       
    79     if ( index == KErrNotFound )
       
    80         {
       
    81         // Add a new entry for this report ID to the "map":
       
    82         User::LeaveIfError(iSizes.Append(TReportSize(aReportId, aType)));
       
    83         index = iSizes.Count() - 1;
       
    84 
       
    85         TRACE_INFO((_L("Adding size record for report %d:%d (%d)\n"),
       
    86                   aReportId, aType, iSizes[index].iSize));
       
    87         }
       
    88     TRACE_INFO((_L("Size for report %d:%d changes %d + %d\n"),
       
    89               aReportId, aType, iSizes[index].iSize, aIncrement));
       
    90     iSizes[index].iSize += aIncrement;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // NumberOfReports()
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 TInt CReportRoot::NumberOfReports() const
       
    98     {
       
    99     return iSizes.Count();
       
   100     }
       
   101 // -----------------------------------------------------------------------------
       
   102 // ReportSize()
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 TInt CReportRoot::ReportSize(TInt aIndex) const
       
   106     {
       
   107     TInt size = 0;
       
   108 
       
   109     if (aIndex < iSizes.Count())
       
   110         {
       
   111         size = iSizes[aIndex].iSize;
       
   112         }
       
   113 
       
   114     return size;
       
   115     }
       
   116 // -----------------------------------------------------------------------------
       
   117 // ReportSize()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt CReportRoot::ReportSize(TInt aReportId, CField::TType aType) const
       
   121     {
       
   122     TInt offset = 0;
       
   123 
       
   124     TInt index = FindReportSizeIndex(aReportId, aType);
       
   125     if (index != KErrNotFound && index < iSizes.Count() )
       
   126         {
       
   127         offset = iSizes[index].iSize;
       
   128         }
       
   129     return offset;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // ReportSizeBytes()
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TInt CReportRoot::ReportSizeBytes(TInt aReportId,
       
   137     CField::TType aType) const
       
   138     {
       
   139     TInt reportBytes = (ReportSize(aReportId, aType) + KSevenBits) / KSizeOfByte;
       
   140 
       
   141     // Add an extra byte if the report ID is used
       
   142     return ( aReportId ) ? reportBytes + 1 : reportBytes;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // FindReportSizeIndex()
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TInt CReportRoot::FindReportSizeIndex(TInt aReportId, CField::TType aType) const
       
   150     {
       
   151     TIdentityRelation<TReportSize> matcher(TReportSize::Match);
       
   152     TInt index = iSizes.Find(TReportSize(aReportId, aType), matcher);
       
   153 
       
   154     TRACE_INFO((_L("FindReportSizeIndex(%d, %d) = %d\n"),
       
   155               aReportId, aType, index));
       
   156     return index;
       
   157     }