datasourcemodules/locationapesuplpsy/src/suplpsygenericinfouser.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 2005 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:  This is SUPL PSY HGenericPositionInfo helper class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32cmn.h>
       
    22 #include "suplpsygenericinfouser.h"
       
    23 #include "suplpsylogging.h"
       
    24 #include "suplpsypanic.h"
       
    25 #include "suplpsy.hrh"
       
    26 
       
    27 // Defines data type
       
    28 enum TFieldDataType
       
    29     {
       
    30     EFieldTypeTInt8,
       
    31     EFieldTypeTInt16,
       
    32     EFieldTypeTInt32,
       
    33     EFieldTypeTInt64,
       
    34     EFieldTypeTUint8,
       
    35     EFieldTypeTUint16,
       
    36     EFieldTypeTUint32,
       
    37     EFieldTypeTReal32,
       
    38     EFieldTypeTReal64,
       
    39     EFieldTypeTTime,
       
    40     EFieldTypeTTimeIntervalMicroSeconds,
       
    41     EFieldTypeDes8,
       
    42     EFieldTypeDes16
       
    43     };
       
    44 
       
    45 // Defines struct of fields and data type
       
    46 struct TFieldIdAndType
       
    47     {
       
    48     TInt  iFieldId;   //Id
       
    49     TInt  iFieldType; //Field type
       
    50     TBool iIsList;    //Field is a list
       
    51     };
       
    52 
       
    53 // Defines all the fields that requestd by SUPL PSY
       
    54 const struct TFieldIdAndType KSuplPsyFields[]=
       
    55     {
       
    56         {EPositionFieldHorizontalSpeed,         EFieldTypeTReal32, EFalse},
       
    57         {EPositionFieldHorizontalSpeedError,    EFieldTypeTReal32, EFalse},
       
    58         {EPositionFieldVerticalSpeed,           EFieldTypeTReal32, EFalse},
       
    59         {EPositionFieldVerticalSpeedError,      EFieldTypeTReal32, EFalse}
       
    60     };
       
    61 
       
    62 
       
    63 // =========================== == OCAL FUNCTIONS ===============================
       
    64 
       
    65 
       
    66 // ========================== == EMBER FUNCTIONS ===============================
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // SuplPsyGenericInfoUser::SupportedFieldsCount
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 TInt SuplPsyGenericInfoUser::SupportedFieldsCount()
       
    74     {
       
    75     return sizeof( KSuplPsyFields ) / sizeof( TFieldIdAndType );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // SuplPsyGenericInfoUser::SupportedFieldAt
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt SuplPsyGenericInfoUser::SupportedFieldAt( TInt aIndex )
       
    83     {
       
    84     return KSuplPsyFields[aIndex].iFieldId;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // SuplPsyGenericInfoUser::CopyHGenericInfo
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TInt SuplPsyGenericInfoUser::CopyHGenericInfo( 
       
    92             const HPositionGenericInfo& aSrc,
       
    93             HPositionGenericInfo& aDes )
       
    94     {
       
    95     TRACESTRING( "SuplPsyGenericInfoUser::CopyHGenericInfo start" )
       
    96     TRACEHEX2( reinterpret_cast < const TUint8* >( &aSrc ), aSrc.PositionClassSize() )
       
    97     //Set position
       
    98     TPosition position;
       
    99     aSrc.GetPosition( position );
       
   100     aDes.SetPosition( position );
       
   101         
       
   102     TInt err( KErrNone );
       
   103     TInt fieldId = aDes.FirstRequestedFieldId();
       
   104     while ( fieldId != EPositionFieldNone )
       
   105         {
       
   106         TRACESTRING2( "FieldId=%d", fieldId )
       
   107 
       
   108         if ( aSrc.IsFieldAvailable( fieldId ) )
       
   109             {
       
   110             err = CopyField( aSrc, aDes, fieldId );
       
   111             if ( err != KErrNone )
       
   112                 {
       
   113                 return err;
       
   114                 }
       
   115             }
       
   116         fieldId = aDes.NextRequestedFieldId( fieldId );
       
   117         }
       
   118     TRACESTRING( "SuplPsyGenericInfoUser::CopyHGenericInfo end" )
       
   119     return err;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // SuplPsyGenericInfoUser::CopyField
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt SuplPsyGenericInfoUser::CopyField( 
       
   127             const HPositionGenericInfo& aSrc,
       
   128             HPositionGenericInfo& aDes,
       
   129             TInt aFieldId )
       
   130     {
       
   131     //Get field data type
       
   132     TInt dataType;
       
   133     TBool isList;
       
   134     TInt err( KErrNone );
       
   135     err = FieldDataType( aFieldId, dataType, isList );
       
   136     if ( err != KErrNone )
       
   137         {
       
   138         return err;
       
   139         }
       
   140         
       
   141     if ( isList )
       
   142         {
       
   143         //copy list
       
   144         TUint8 count; //length of the list
       
   145         err = aSrc.GetValue( aFieldId, count );
       
   146         if ( err != KErrNone )
       
   147             {
       
   148             return err;
       
   149             }
       
   150         for ( TInt i = 0; i < count; i++ )
       
   151             {
       
   152             err = CopyDataByType( aSrc, aDes, aFieldId + 1 + i, dataType );
       
   153             if ( err != KErrNone )
       
   154                 {
       
   155                 return err;
       
   156                 }
       
   157             }
       
   158             
       
   159         err = aDes.SetValue( aFieldId, count );
       
   160         }
       
   161     else
       
   162         {
       
   163         err = CopyDataByType( aSrc, aDes, aFieldId, dataType );
       
   164         }
       
   165         
       
   166     return err;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // SuplPsyGenericInfoUser::FiledDataType
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt SuplPsyGenericInfoUser::FieldDataType( 
       
   174         TInt aFieldId,
       
   175         TInt& aFieldDataType, 
       
   176         TBool& aIsList )
       
   177     {
       
   178     TInt count = SupportedFieldsCount();
       
   179     for ( TInt i = 0; i < count; i++ )
       
   180         {
       
   181         if ( SupportedFieldAt( i ) == aFieldId )
       
   182             {
       
   183             aFieldDataType = KSuplPsyFields[i].iFieldType;
       
   184             aIsList = KSuplPsyFields[i].iIsList;
       
   185             return KErrNone;
       
   186             }
       
   187         }
       
   188     return KErrNotFound;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // SuplPsyGenericInfoUser::CopyDataByType
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt SuplPsyGenericInfoUser::CopyDataByType( 
       
   196             const HPositionGenericInfo& aSrc,
       
   197             HPositionGenericInfo& aDes,
       
   198             TInt aFieldId,
       
   199             TInt aDataType )
       
   200     {
       
   201     TInt err( KErrNone );
       
   202     switch ( aDataType )
       
   203         {
       
   204         case EFieldTypeTReal32:
       
   205             err = CopyData < TReal32 >( aSrc, aDes, aFieldId );
       
   206             break;
       
   207         default:
       
   208             err = KErrNotSupported;
       
   209             break;
       
   210         }
       
   211     return err;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // SuplPsyGenericInfoUser::CopyData
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 template < class T > TInt SuplPsyGenericInfoUser::CopyData( 
       
   219             const HPositionGenericInfo& aSrc,
       
   220             HPositionGenericInfo& aDes,
       
   221             TInt aFieldId )
       
   222     {
       
   223     T data;
       
   224     TInt err( KErrNone );
       
   225     err = aSrc.GetValue( aFieldId, data );
       
   226     if ( err != KErrNone )
       
   227         {
       
   228         return err;
       
   229         }
       
   230     return aDes.SetValue( aFieldId, data );
       
   231     }
       
   232 
       
   233 
       
   234 //  End of File