omaprovisioning/provisioning/ProvisioningEngine/Src/CWPParameter.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002 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:  One parameter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <s32file.h>
       
    21 #include "CWPParameter.h"
       
    22 #include "MWPVisitor.h"
       
    23 #include "WPElementFactory.h"
       
    24 
       
    25 // CONSTANTS
       
    26 /// Number of bits in half-word
       
    27 const TInt KBitsPerWord = 16;
       
    28 /// Mask to extract a half-word
       
    29 const TInt KWordMask = 0xffff;
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CWPParameter::CWPParameter
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CWPParameter::CWPParameter()
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CWPParameter::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CWPParameter::ConstructL()
       
    49     {
       
    50     iValue = KNullDesC().AllocL();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CWPRoot::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C CWPParameter* CWPParameter::NewL()
       
    59     {
       
    60     CWPParameter* self = NewLC();
       
    61     CleanupStack::Pop();
       
    62     
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CWPRoot::NewLC
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CWPParameter* CWPParameter::NewLC()
       
    72     {
       
    73     CWPParameter* self = new( ELeave ) CWPParameter;
       
    74     
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     
       
    78     return self;
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 CWPParameter::~CWPParameter()
       
    83     {
       
    84     delete iName;
       
    85     delete iValue;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CWPParameter::CallVisitorL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CWPParameter::CallVisitorL( MWPVisitor& aVisitor )
       
    93     {
       
    94     aVisitor.VisitL( *this );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CWPParameter::InternalizeL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CWPParameter::InternalizeL(RReadStream& aStream)
       
   102     {
       
   103     TInt parameterID( aStream.ReadInt32L() );
       
   104     TUint length( aStream.ReadInt32L() );
       
   105     // Lengths packed into one 32-bit word for compatibility
       
   106     TInt valueLength( length & KWordMask );
       
   107     TInt nameLength( (length >> KBitsPerWord) & KWordMask );
       
   108     
       
   109     HBufC* value = HBufC::NewL( aStream, valueLength );
       
   110     delete iValue;
       
   111     iValue = value;
       
   112     
       
   113     if( nameLength > 0 )
       
   114         {
       
   115         HBufC* name = HBufC::NewL( aStream, nameLength );
       
   116         delete iName;
       
   117         iName = name;
       
   118         }
       
   119 
       
   120     iParameterID = parameterID;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CWPParameter::ExternalizeL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void CWPParameter::ExternalizeL(RWriteStream& aStream) const
       
   128     {
       
   129     aStream.WriteInt32L( iParameterID );
       
   130 
       
   131     // Lengths packed into one 32-bit word for compatibility
       
   132     TUint length( 0 );
       
   133     if( iValue )
       
   134         {
       
   135         length += iValue->Length();
       
   136         }
       
   137     if( iName )
       
   138         {
       
   139         length += iName->Length() << KBitsPerWord;
       
   140         }
       
   141 
       
   142     aStream.WriteUint32L( length );
       
   143 
       
   144     aStream << *iValue;
       
   145 
       
   146     if( iName )
       
   147         {
       
   148         aStream << *iName;
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CWPParameter::Type
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C TInt CWPParameter::Type() const
       
   157     {
       
   158     return KWPParameter;
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CWPParameter::SetID
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void CWPParameter::SetID( TInt aID )
       
   166     {
       
   167     iParameterID = aID;
       
   168     }
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CWPParameter::ID
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C TInt CWPParameter::ID() const
       
   176     {
       
   177     return iParameterID;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CWPParameter::SetNameL
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C void CWPParameter::SetNameL( const TDesC& aName )
       
   185     {
       
   186     HBufC* name = aName.AllocL();
       
   187     delete iName;
       
   188     iName = name;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CWPParameter::Name
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C const TDesC& CWPParameter::Name() const
       
   196     {
       
   197     if( iName )
       
   198         {
       
   199         return *iName;
       
   200         }
       
   201     else
       
   202         {
       
   203         return KNullDesC;
       
   204         }
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CWPParameter::SetValueL
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C void CWPParameter::SetValueL( const TDesC& aValue )
       
   212     {
       
   213     HBufC* value = aValue.AllocL();
       
   214     delete iValue;
       
   215     iValue = value;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CWPParameter::Value
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C const TDesC& CWPParameter::Value() const
       
   223     {
       
   224     if( iValue )
       
   225         {
       
   226         return *iValue;
       
   227         }
       
   228     else
       
   229         {
       
   230         return KNullDesC;
       
   231         }
       
   232     }
       
   233 
       
   234 
       
   235 //  End of File