omaprovisioning/provisioning/ProvisioningEngine/Src/CWPCharacteristic.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 characteristic.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "CWPCharacteristic.h"
       
    21 #include <s32std.h>
       
    22 #include <e32svr.h>
       
    23 #include "MWPVisitor.h"
       
    24 #include "CWPParameter.h"
       
    25 #include "WPElementFactory.h"
       
    26 #include "CWPEngine.pan"
       
    27 #include "WPEngineDebug.h"
       
    28 
       
    29 // CONSTANTS
       
    30 /// Default data item number in Data() and SetData(), if none supplied
       
    31 const TInt KDefaultDataNum = 0;
       
    32 /// Data array granularity
       
    33 const TInt KDataGranularity = 3;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CWPCharacteristic::CWPCharacteristic
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CWPCharacteristic::CWPCharacteristic( TInt aType )
       
    44 : iType( aType )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CWPCharacteristic::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CWPCharacteristic::ConstructL()
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CWPCharacteristic::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CWPCharacteristic* CWPCharacteristic::NewL( TInt aType )
       
    63     {
       
    64     CWPCharacteristic* self = NewLC( aType );
       
    65     CleanupStack::Pop();
       
    66     
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CWPCharacteristic::NewLC
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CWPCharacteristic* CWPCharacteristic::NewLC( TInt aType )
       
    76     {
       
    77     CWPCharacteristic* self = new( ELeave ) CWPCharacteristic( aType );
       
    78     
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     
       
    82     return self;
       
    83     }
       
    84 
       
    85 // Destructor
       
    86 CWPCharacteristic::~CWPCharacteristic()
       
    87     {
       
    88     iElements.ResetAndDestroy();
       
    89     iElements.Close();
       
    90     iLinks.Close();
       
    91     if ( iData )
       
    92         {
       
    93         iData->ResetAndDestroy();
       
    94         }
       
    95     delete iData;
       
    96     delete iName;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CWPCharacteristic::InsertL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void CWPCharacteristic::InsertL( MWPElement* aElement )
       
   104     {
       
   105     __ASSERT_DEBUG( aElement != NULL, Panic( EWPNullElement ) );
       
   106 
       
   107     User::LeaveIfError( iElements.Append( aElement ) );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CWPCharacteristic::InsertLinkL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CWPCharacteristic::InsertLinkL( CWPCharacteristic& aParameter )
       
   115     {
       
   116     __ASSERT_DEBUG( aParameter.Type() == KWPPxLogical 
       
   117         || aParameter.Type() == KWPNapDef,
       
   118         Panic( EWPIllegalLink ) );
       
   119 
       
   120     User::LeaveIfError( iLinks.Append( &aParameter ) );
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CWPCharacteristic::SetNameL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void CWPCharacteristic::SetNameL( const TDesC& aName )
       
   128     {
       
   129     HBufC* name = aName.AllocL();
       
   130     delete iName;
       
   131     iName = name;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CWPCharacteristic::Name
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C const TDesC& CWPCharacteristic::Name() const
       
   139     {
       
   140     if( iName )
       
   141         {
       
   142         return *iName;
       
   143         }
       
   144     else
       
   145         {
       
   146         return KNullDesC;
       
   147         }
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CWPCharacteristic::SetDataL
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C void CWPCharacteristic::SetDataL( const TDesC8& aData )
       
   155     {
       
   156     SetDataL( aData, KDefaultDataNum );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CWPCharacteristic::SetDataL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C void CWPCharacteristic::SetDataL( const TDesC8& aData, TInt aIndex )
       
   164     {
       
   165     HBufC8* data = aData.AllocLC();
       
   166 
       
   167     if ( !iData )
       
   168         {
       
   169         iData = new (ELeave) CArrayPtrSeg<HBufC8>( KDataGranularity );
       
   170         }
       
   171 
       
   172     // Check if there's already item in given index
       
   173     if ( iData->Count() > aIndex )
       
   174         {
       
   175         HBufC8* oldData = iData->At(aIndex);
       
   176         iData->Delete( aIndex );
       
   177         delete oldData;
       
   178         oldData = NULL;
       
   179         iData->InsertL( aIndex, data );
       
   180         CleanupStack::Pop( data );
       
   181         }
       
   182     else // Not as many items in array as pointed by index. Append as last item.
       
   183         {
       
   184         iData->AppendL( data );
       
   185         CleanupStack::Pop( data );
       
   186         }
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CWPCharacteristic::DeleteAllData
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C void CWPCharacteristic::DeleteAllData()
       
   194     {
       
   195     if ( iData )
       
   196         {
       
   197         iData->ResetAndDestroy();
       
   198         delete iData;
       
   199         iData = NULL;
       
   200         }   
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CWPCharacteristic::Data
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C const TDesC8& CWPCharacteristic::Data() const
       
   208     {
       
   209     return Data( KDefaultDataNum );
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CWPCharacteristic::Data
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C const TDesC8& CWPCharacteristic::Data( TInt aIndex ) const
       
   217     {
       
   218     if ( iData && iData->Count() > 0 && aIndex >= 0 && aIndex < iData->Count() )
       
   219         {
       
   220         return *iData->At( aIndex );
       
   221         }
       
   222     else
       
   223         {
       
   224         return KNullDesC8;
       
   225         }
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CWPCharacteristic::InternalizeL
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CWPCharacteristic::InternalizeL(RReadStream& aStream)
       
   233     {
       
   234     TInt paramCount( aStream.ReadInt32L() );
       
   235 
       
   236     for( TInt i( 0 ); i < paramCount; i++ )
       
   237         {
       
   238         TInt type( aStream.ReadInt32L() );
       
   239 
       
   240         MWPElement* newElement = WPElementFactory::CreateLC( type );
       
   241         newElement->InternalizeL( aStream );
       
   242         User::LeaveIfError( iElements.Append( newElement ) );
       
   243         CleanupStack::Pop(); // newElement
       
   244         }
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CWPCharacteristic::ExternalizeL
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CWPCharacteristic::ExternalizeL(RWriteStream& aStream) const
       
   252     {
       
   253     aStream.WriteInt32L( iElements.Count() );
       
   254 
       
   255     for( TInt i( 0 ); i < iElements.Count(); i++ )
       
   256         {
       
   257         const MWPElement* element = iElements[i];
       
   258         aStream.WriteInt32L( element->Type() );
       
   259         element->ExternalizeL( aStream );
       
   260         }
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CWPCharacteristic::CallVisitorL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void CWPCharacteristic::CallVisitorL( MWPVisitor& aVisitor )
       
   268     {
       
   269     aVisitor.VisitL( *this );
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CWPCharacteristic::Type
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TInt CWPCharacteristic::Type() const
       
   277     {
       
   278     return iType;
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CWPCharacteristic::AcceptL
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 EXPORT_C void CWPCharacteristic::AcceptL(MWPVisitor& aVisitor)
       
   286     {
       
   287     for( TInt i( 0 ); i < iElements.Count(); i++ )
       
   288         {
       
   289         iElements[i]->CallVisitorL( aVisitor );
       
   290         }
       
   291 
       
   292     for( TInt j( 0 ); j < iLinks.Count(); j++ )
       
   293         {
       
   294         aVisitor.VisitLinkL( *iLinks[j] );
       
   295         }
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CWPCharacteristic::ParameterL
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 EXPORT_C void CWPCharacteristic::ParameterL( TInt aID, 
       
   303                                             CArrayFix<TPtrC>* aParameters )
       
   304     {
       
   305     aParameters->Reset();
       
   306 
       
   307     for( TInt i( 0 ); i < iElements.Count(); i++ )
       
   308         {
       
   309         if( iElements[i]->Type() == KWPParameter )
       
   310             {
       
   311             CWPParameter* parameter = STATIC_CAST(CWPParameter*, iElements[i]);
       
   312 
       
   313             if( parameter->ID() == aID )
       
   314                 {
       
   315                 aParameters->AppendL( parameter->Value() );
       
   316                 }
       
   317             }
       
   318         }
       
   319     }
       
   320 
       
   321 //  End of File