localconnectivityservice/generichid/src/hidcollection.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     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:  HID collection implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <e32des8.h>
       
    22 #include <e32svr.h>
       
    23 
       
    24 #include "hidreportroot.h"
       
    25 #include "debug.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // NewLC()
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CCollection* CCollection::NewLC()
       
    34     {
       
    35     CCollection* self = new (ELeave) CCollection();
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     return self;
       
    39     }
       
    40 // -----------------------------------------------------------------------------
       
    41 // NewL()
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CCollection* CCollection::NewL()
       
    45     {
       
    46     CCollection* self=NewLC();
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // ConstructL()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CCollection::ConstructL()
       
    56     {
       
    57     // Nothing to do here
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCollection()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CCollection::CCollection()
       
    65     {
       
    66     // Nothing to do here
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // ~CCollection()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CCollection::~CCollection()
       
    74     {
       
    75     iCollections.ResetAndDestroy();
       
    76     iFields.ResetAndDestroy();
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Type()
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C TUint32 CCollection::Type() const
       
    84     {
       
    85     return iType;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // UsagePage()
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C TInt CCollection::UsagePage() const
       
    93     {
       
    94     return iUsagePage;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Usage()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C TInt CCollection::Usage() const
       
   102     {
       
   103     return iUsage;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CollectionCount()
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C TInt CCollection::CollectionCount() const
       
   111     {
       
   112     return iCollections.Count();
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // FieldCount()
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C TInt CCollection::FieldCount() const
       
   120     {
       
   121     return iFields.Count();
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CollectionByIndex
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C const CCollection* CCollection::CollectionByIndex(TInt aIndex) const
       
   129     {
       
   130     return (0 <= aIndex && aIndex < iCollections.Count()) ?
       
   131         iCollections[aIndex] : NULL;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // FieldByIndex
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C const CField* CCollection::FieldByIndex(TInt aIndex) const
       
   139     {
       
   140     return (0 <= aIndex && aIndex < iFields.Count()) ?
       
   141         iFields[aIndex] : NULL;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // IsPhysical()
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C TBool CCollection::IsPhysical() const
       
   149     {
       
   150     return iType == EPhysical;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // IsApplication()
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C TBool CCollection::IsApplication() const
       
   158     {
       
   159     return iType == EApplication;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // IsLogical()
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C TBool CCollection::IsLogical() const
       
   167     {
       
   168     return iType == ELogical;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // IsReport()
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C TBool CCollection::IsReport() const
       
   176     {
       
   177     return iType == EReport;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // IsNamedArray()
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C TBool CCollection::IsNamedArray() const
       
   185     {
       
   186     return iType == ENamedArray;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // IsUsageSwitch()
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C TBool CCollection::IsUsageSwitch() const
       
   194     {
       
   195     return iType == EUsageSwitch;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // IsUsageModifier()
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C TBool CCollection::IsUsageModifier() const
       
   203     {
       
   204     return iType == EUsageModifier;
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // SetType()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CCollection::SetType(TUint32 aType)
       
   212     {
       
   213     iType = aType;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // SetUsagePage()
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CCollection::SetUsagePage(TInt aUsagePage)
       
   221     {
       
   222     iUsagePage = aUsagePage;
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // SetUsage()
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CCollection::SetUsage(TInt aUsage)
       
   230     {
       
   231     iUsage = aUsage;
       
   232     }
       
   233 // -----------------------------------------------------------------------------
       
   234 // AddFieldL()
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 CField* CCollection::AddFieldL()
       
   238     {
       
   239     CField* field = CField::NewL();
       
   240     CleanupStack::PushL(field);
       
   241     User::LeaveIfError(iFields.Append(field));
       
   242     CleanupStack::Pop(field);
       
   243     return field;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // AddCollectionL()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 CCollection* CCollection::AddCollectionL()
       
   251     {
       
   252     CCollection* collection = CCollection::NewL();
       
   253     CleanupStack::PushL(collection);
       
   254     User::LeaveIfError(iCollections.Append(collection));
       
   255     CleanupStack::Pop(collection);
       
   256     return collection;
       
   257     }
       
   258 
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // Match()
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 TBool TReportSize::Match(const TReportSize& aFirst,
       
   268     const TReportSize& aSecond)
       
   269     {
       
   270     return (aFirst.iReportId == aSecond.iReportId) &&
       
   271         (aFirst.iType == aSecond.iType);
       
   272     }
       
   273 
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // TReportSize()
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TReportSize::TReportSize(TInt aReportId, CField::TType aType)
       
   280     : iReportId(aReportId), iType(aType), iSize(0)
       
   281     {
       
   282     // Nothing else to do
       
   283     }
       
   284