contextframework/cfw/src/cfservices/cfcontextsourcecommandparameterimpl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2008-2008 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:  CCFContextSourceCommandParameterImpl class implementation.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <s32strm.h>
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "cfcontextsourcecommandparameterimpl.h"
       
    24 #include "cftrace.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // C++ constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CCFContextSourceCommandParameterImpl::CCFContextSourceCommandParameterImpl()
       
    33     {
       
    34     FUNC_LOG;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Symbian 2nd phase constructor.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 void CCFContextSourceCommandParameterImpl::ConstructL()
       
    42     {
       
    43     FUNC_LOG;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Symbian two phased constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CCFContextSourceCommandParameterImpl*
       
    51 CCFContextSourceCommandParameterImpl::NewL()
       
    52     {
       
    53     FUNC_LOG;
       
    54 
       
    55     CCFContextSourceCommandParameterImpl* self
       
    56             = CCFContextSourceCommandParameterImpl::NewLC();
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Symbian two phased constructor.
       
    63 // Leaves pointer in the cleanup stack.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CCFContextSourceCommandParameterImpl*
       
    67 CCFContextSourceCommandParameterImpl::NewLC()
       
    68     {
       
    69     FUNC_LOG;
       
    70 
       
    71     CCFContextSourceCommandParameterImpl* self
       
    72             = new( ELeave ) CCFContextSourceCommandParameterImpl;
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     return self;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // C++ destructor.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CCFContextSourceCommandParameterImpl::~CCFContextSourceCommandParameterImpl()
       
    83     {
       
    84     FUNC_LOG;
       
    85 
       
    86     iParameters.ResetAndDestroy();
       
    87     iAttributes.ResetAndDestroy();
       
    88     delete iName;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CCFContextSourceCommandParameterImpl::Name
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 const TDesC& CCFContextSourceCommandParameterImpl::Name() const
       
    97     {
       
    98     FUNC_LOG;
       
    99 
       
   100     if ( iName )
       
   101         {
       
   102         return *iName;
       
   103         }
       
   104     else
       
   105         {
       
   106         return KNullDesC;
       
   107         }
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCFContextSourceCommandParameterImpl::SetNameL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CCFContextSourceCommandParameterImpl::SetNameL( const TDesC& aName )
       
   115     {
       
   116     FUNC_LOG;
       
   117 
       
   118     delete iName;
       
   119     iName = NULL;
       
   120     iName = aName.AllocL();
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CCFContextSourceCommandParameterImpl::Attributes
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 const RKeyValueArray& CCFContextSourceCommandParameterImpl::Attributes() const
       
   128     {
       
   129     FUNC_LOG;
       
   130 
       
   131     return iAttributes;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CCFContextSourceCommandParameterImpl::AddAttributeL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CCFContextSourceCommandParameterImpl::AddAttributeL(
       
   139     CCFKeyValuePair* aAttribute )
       
   140     {
       
   141     FUNC_LOG;
       
   142 
       
   143     iAttributes.AppendL( aAttribute );
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CCFContextSourceCommandParameterImpl::AddAttributesL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CCFContextSourceCommandParameterImpl::AddAttributesL(
       
   151     RKeyValueArray& aAttributes )
       
   152     {
       
   153     FUNC_LOG;
       
   154 
       
   155     TInt insertPos = iAttributes.Count();
       
   156     for ( TInt i = aAttributes.Count() - 1; i >= 0; --i )
       
   157         {
       
   158         CCFKeyValuePair* attribute = aAttributes[ i ];
       
   159         aAttributes.Remove( i );
       
   160         CleanupStack::PushL( attribute );       // CLEANUP<< attribute
       
   161         iAttributes.Insert( attribute, insertPos );
       
   162         CleanupStack::Pop( attribute );         // CLEANUP>> attribute
       
   163         }
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CCFContextSourceCommandParameterImpl::Parameters
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 const RSourceCommandParameterArray&
       
   171 CCFContextSourceCommandParameterImpl::Parameters() const
       
   172     {
       
   173     FUNC_LOG;
       
   174 
       
   175     return iParameters;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CCFContextSourceCommandParameterImpl::AddParameterL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CCFContextSourceCommandParameterImpl::AddParameterL(
       
   183     CCFContextSourceCommandParameter* aParameter )
       
   184     {
       
   185     FUNC_LOG;
       
   186 
       
   187     iParameters.AppendL( aParameter );
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CCFContextSourceCommandParameterImpl::Size
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TInt CCFContextSourceCommandParameterImpl::Size() const
       
   195     {
       
   196     FUNC_LOG;
       
   197 
       
   198     TInt size = 0;
       
   199 
       
   200     // Name: length and size of iName
       
   201     size += sizeof( TInt32 );
       
   202     size += iName->Size();
       
   203 
       
   204     // Attributes: array count & data
       
   205     size += sizeof( TInt32 );
       
   206     TInt count = iAttributes.Count();
       
   207     for ( TInt i = 0; i < count; ++i )
       
   208         {
       
   209         // Key length & data
       
   210         size += sizeof( TInt32 );
       
   211         size += iAttributes[ i ]->Key().Size();
       
   212 
       
   213         // Value length & data
       
   214         size += sizeof( TInt32 );
       
   215         size += iAttributes[ i ]->Value().Size();
       
   216         }
       
   217 
       
   218     // Nested parameters: array count & data
       
   219     size += sizeof( TInt32 );
       
   220     count = iParameters.Count();
       
   221     for ( TInt i = 0; i < count; ++i )
       
   222         {
       
   223         size += iParameters[ i ]->Size();
       
   224         }
       
   225 
       
   226     return size;
       
   227     }
       
   228 
       
   229 //-----------------------------------------------------------------------------
       
   230 // CCFContextSourceCommandParameterImpl::ExternalizeL
       
   231 //-----------------------------------------------------------------------------
       
   232 //
       
   233 void CCFContextSourceCommandParameterImpl::ExternalizeL(
       
   234     RWriteStream& aStream ) const
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     // Name
       
   239     aStream.WriteInt32L( iName->Length() );
       
   240     aStream.WriteL( *iName );
       
   241 
       
   242     // Attributes
       
   243     TInt count = iAttributes.Count();
       
   244     aStream.WriteInt32L( count );
       
   245     for ( TInt i = 0; i < count; ++i )
       
   246         {
       
   247         TPtrC buf( KNullDesC );
       
   248 
       
   249         // Key length & data
       
   250         buf.Set( iAttributes[ i ]->Key() );
       
   251         aStream.WriteInt32L( buf.Length() );
       
   252         aStream.WriteL( buf, buf.Length() );
       
   253 
       
   254         // Value length & data
       
   255         buf.Set( iAttributes[ i ]->Value() );
       
   256         aStream.WriteInt32L( buf.Length() );
       
   257         aStream.WriteL( buf, buf.Length() );
       
   258         }
       
   259 
       
   260     // Nested parameters
       
   261     count = iParameters.Count();
       
   262     aStream.WriteInt32L( count );
       
   263     for ( TInt i = 0; i < count; ++i )
       
   264         {
       
   265         iParameters[ i ]->ExternalizeL( aStream );
       
   266         }
       
   267 
       
   268     // Commit stream
       
   269     aStream.CommitL();
       
   270     }
       
   271 
       
   272 //-----------------------------------------------------------------------------
       
   273 // CCFContextSourceCommandParameterImpl::InternalizeL
       
   274 //-----------------------------------------------------------------------------
       
   275 //
       
   276 void CCFContextSourceCommandParameterImpl::InternalizeL( RReadStream& aStream )
       
   277     {
       
   278     FUNC_LOG;
       
   279 
       
   280     // Clean up just in case
       
   281     delete iName;
       
   282     iName = NULL;
       
   283     iAttributes.ResetAndDestroy();
       
   284     iParameters.ResetAndDestroy();
       
   285 
       
   286     // Name
       
   287     TInt len = aStream.ReadInt32L();
       
   288     iName = HBufC::NewL( len );
       
   289     TPtr namePtr = iName->Des();
       
   290     aStream.ReadL( namePtr, len );
       
   291 
       
   292     // Attributes
       
   293     TInt count = aStream.ReadInt32L();
       
   294     for ( TInt i = 0; i < count; ++i )
       
   295         {
       
   296         // Key length & data
       
   297         len = aStream.ReadInt32L();
       
   298         HBufC* key = HBufC::NewLC( len );           // CLEANUP<< key
       
   299         TPtr keyPtr = key->Des();
       
   300         aStream.ReadL( keyPtr, len );
       
   301 
       
   302         // Value length & data
       
   303         len = aStream.ReadInt32L();
       
   304         HBufC* value = HBufC::NewLC( len );         // CLEANUP<< value
       
   305         TPtr valuePtr = value->Des();
       
   306         aStream.ReadL( valuePtr, len );
       
   307 
       
   308         // Create & append key value pair
       
   309         CCFKeyValuePair* keyValuePair = CCFKeyValuePair::NewL( key, value );
       
   310         CleanupStack::Pop( value );                 // CLEANUP>> value
       
   311         CleanupStack::Pop( key );                   // CLEANUP>> key
       
   312 
       
   313         CleanupStack::PushL( keyValuePair );        // CLEANUP<< keyValuePair
       
   314         iAttributes.AppendL( keyValuePair );
       
   315         CleanupStack::Pop( keyValuePair );          // CLEANUP>> keyValuePair
       
   316         }
       
   317 
       
   318     // Nested parameters
       
   319     count = aStream.ReadInt32L();
       
   320     for ( TInt i = 0; i < count; ++i )
       
   321         {
       
   322         // below                                    // CLEANUP<< param
       
   323         CCFContextSourceCommandParameter* param
       
   324             = CCFContextSourceCommandParameter::NewLC();
       
   325         param->InternalizeL( aStream );
       
   326         iParameters.AppendL( param );
       
   327         CleanupStack::Pop( param );                 // CLEANUP>> param
       
   328         }
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // CCFContextSourceCommandParameterImpl::CloneLC
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 CCFContextSourceCommandParameter*
       
   336 CCFContextSourceCommandParameterImpl::CloneLC() const
       
   337     {
       
   338     FUNC_LOG;
       
   339 
       
   340     // below                                        // CLEANUP<< parameter
       
   341     CCFContextSourceCommandParameterImpl* parameter
       
   342         = CCFContextSourceCommandParameterImpl::NewLC();
       
   343 
       
   344     // Copy name.
       
   345     if ( iName )
       
   346         {
       
   347         parameter->iName = iName->AllocL();
       
   348         }
       
   349 
       
   350     // Copy attributes.
       
   351     for ( TInt i = 0; i < iAttributes.Count(); ++i )
       
   352         {
       
   353         CCFKeyValuePair* keyValue = iAttributes[ i ];
       
   354         // below                                    // CLEANUP<< attribute
       
   355         CCFKeyValuePair* attribute = CCFKeyValuePair::NewLC( keyValue->Key(),
       
   356                 keyValue->Value() );
       
   357         parameter->iAttributes.AppendL( attribute );
       
   358         CleanupStack::Pop( attribute );             // CLEANUP>> attribute
       
   359         }
       
   360 
       
   361     // Copy parameters.
       
   362     for ( TInt i = 0; i < iParameters.Count(); ++i )
       
   363         {
       
   364         CCFContextSourceCommandParameter* cmdParam = iParameters[ i ];
       
   365         // below                                    // CLEANUP<< param
       
   366         CCFContextSourceCommandParameter* param = cmdParam->CloneLC();
       
   367         parameter->iParameters.AppendL( param );
       
   368         CleanupStack::Pop( param );                 // CLEANUP>> param
       
   369         }
       
   370 
       
   371     return parameter; // Left on the cleanup stack.
       
   372     }
       
   373 
       
   374 // End of file