contextframework/cfw/src/cfservices/CFActionIndicationImpl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2006-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:  CCFActionIndicationImpl class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 
       
    21 #include "CFActionIndicationImpl.h"
       
    22 #include "cftrace.h"
       
    23 
       
    24 EXPORT_C CCFActionIndicationImpl* CCFActionIndicationImpl::NewL()
       
    25     {
       
    26     FUNC_LOG;
       
    27     
       
    28     CCFActionIndicationImpl* self = CCFActionIndicationImpl::NewLC();
       
    29     CleanupStack::Pop( self );
       
    30     
       
    31     return self;
       
    32     }
       
    33 
       
    34 EXPORT_C CCFActionIndicationImpl* CCFActionIndicationImpl::NewLC()
       
    35     {
       
    36     FUNC_LOG;
       
    37     
       
    38     CCFActionIndicationImpl* self = new( ELeave ) CCFActionIndicationImpl;
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     
       
    42     return self;
       
    43     }
       
    44 
       
    45 CCFActionIndicationImpl::~CCFActionIndicationImpl()
       
    46     {
       
    47     FUNC_LOG;
       
    48     
       
    49     delete iIdentifier;
       
    50     iParameters.ResetAndDestroy();
       
    51     }
       
    52     
       
    53 CCFActionIndicationImpl::CCFActionIndicationImpl()
       
    54     {
       
    55     FUNC_LOG;    
       
    56     }
       
    57     
       
    58 void CCFActionIndicationImpl::ConstructL()
       
    59     {
       
    60     FUNC_LOG;
       
    61     
       
    62     iIdentifier = KNullDesC().AllocL();
       
    63     }
       
    64     
       
    65 // METHODS
       
    66 
       
    67 //-----------------------------------------------------------------------------
       
    68 // CCFActionIndicationImpl::SetIdentifierL
       
    69 //-----------------------------------------------------------------------------
       
    70 //
       
    71 void CCFActionIndicationImpl::SetIdentifierL(
       
    72     const TDesC& aIdentifier )
       
    73     {
       
    74     FUNC_LOG;
       
    75     
       
    76     TPtr identifierPtr = iIdentifier->Des();
       
    77     if( identifierPtr.MaxLength() >= aIdentifier.Length() )
       
    78         {
       
    79         // Just copy
       
    80         identifierPtr.Copy( aIdentifier );
       
    81         }
       
    82     else
       
    83         {
       
    84         // Delete and create a new one
       
    85         delete iIdentifier;
       
    86         iIdentifier = NULL;
       
    87         iIdentifier = aIdentifier.AllocL();
       
    88         }
       
    89     }
       
    90 
       
    91 //-----------------------------------------------------------------------------
       
    92 // CCFActionIndicationImpl::Identifier
       
    93 //-----------------------------------------------------------------------------
       
    94 //
       
    95 const TDesC& CCFActionIndicationImpl::Identifier() const
       
    96     {
       
    97     FUNC_LOG;
       
    98     
       
    99     return *iIdentifier;
       
   100     }
       
   101 
       
   102 //-----------------------------------------------------------------------------
       
   103 // CCFActionIndicationImpl::AddParameterL
       
   104 //-----------------------------------------------------------------------------
       
   105 //
       
   106 void CCFActionIndicationImpl::AddParameterL( const TDesC& aKey,
       
   107     const TDesC& aValue )
       
   108     {
       
   109     FUNC_LOG;
       
   110     
       
   111     CCFKeyValuePair* obj = CCFKeyValuePair::NewLC( aKey, aValue );
       
   112     iParameters.AppendL( obj );
       
   113     CleanupStack::Pop( obj );
       
   114     }
       
   115 
       
   116 //-----------------------------------------------------------------------------
       
   117 // CCFActionIndicationImpl::Parameters
       
   118 //-----------------------------------------------------------------------------
       
   119 //
       
   120 const RKeyValueArray& CCFActionIndicationImpl::Parameters() const
       
   121     {
       
   122     FUNC_LOG;
       
   123     
       
   124     return iParameters;
       
   125     }
       
   126 
       
   127 //-----------------------------------------------------------------------------
       
   128 // CCFActionIndicationImpl::Size
       
   129 //-----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TInt CCFActionIndicationImpl::Size() const
       
   132     {
       
   133     FUNC_LOG;
       
   134     
       
   135     TInt size = 0;
       
   136     
       
   137     // Identifier:
       
   138     // length of iIdentifier
       
   139     // Size of iIdentifier
       
   140     size += sizeof( TInt );
       
   141     size += iIdentifier->Size();
       
   142     
       
   143     // Parameters:
       
   144     // array count
       
   145     size += sizeof( TInt );
       
   146     TInt count = iParameters.Count();
       
   147     for( TInt i = 0; i < count; i++ )
       
   148         {
       
   149         // key length, key data
       
   150         size += sizeof( TInt );
       
   151         size += iParameters[i]->Key().Size();
       
   152 
       
   153         // value len, value data
       
   154         size += sizeof( TInt );
       
   155         size += iParameters[i]->Value().Size();
       
   156         }
       
   157     
       
   158     return size;
       
   159     }
       
   160 
       
   161 //-----------------------------------------------------------------------------
       
   162 // CCFActionIndicationImpl::ExternalizeL
       
   163 //-----------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void CCFActionIndicationImpl::ExternalizeL( RWriteStream& aStream )
       
   166     {
       
   167     FUNC_LOG;
       
   168     
       
   169     // Identifier
       
   170     aStream.WriteInt16L( iIdentifier->Length() );
       
   171     aStream.WriteL( *iIdentifier );
       
   172     
       
   173     // Parameters
       
   174     TPtrC buf( KNullDesC );
       
   175     TInt count = iParameters.Count();
       
   176     aStream.WriteInt16L( count );
       
   177     for( TInt i = 0; i < count; i++ )
       
   178         {
       
   179         // Key length and data
       
   180         buf.Set( iParameters[i]->Key() );
       
   181         aStream.WriteInt16L( buf.Length() );
       
   182         aStream.WriteL( buf, buf.Length() );
       
   183         
       
   184         // Value length and data
       
   185         buf.Set( iParameters[i]->Value() );
       
   186         aStream.WriteInt16L( buf.Length() );
       
   187         aStream.WriteL( buf, buf.Length() );
       
   188         }
       
   189     
       
   190     // Commit stream
       
   191     aStream.CommitL();
       
   192     }
       
   193 
       
   194 //-----------------------------------------------------------------------------
       
   195 // CCFActionIndicationImpl::InternalizeL
       
   196 //-----------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CCFActionIndicationImpl::InternalizeL( RReadStream& aStream )
       
   199     {
       
   200     FUNC_LOG;
       
   201     
       
   202     // Clean up just in case
       
   203     delete iIdentifier;
       
   204     iIdentifier = NULL;
       
   205     iParameters.ResetAndDestroy();
       
   206     
       
   207     TInt len = 0;
       
   208 
       
   209     // Identifier
       
   210     len = aStream.ReadInt16L();
       
   211     iIdentifier = ReadBufferFromStreamLC( len, aStream );
       
   212     CleanupStack::Pop( iIdentifier );
       
   213     
       
   214     // Parameters
       
   215     HBufC* key = NULL;
       
   216     HBufC* value = NULL;
       
   217     TInt count = aStream.ReadInt16L();
       
   218     for( TInt i = 0; i < count; i++ )
       
   219         {
       
   220         // Key length and data
       
   221         len = aStream.ReadInt16L();
       
   222         key = ReadBufferFromStreamLC( len, aStream );
       
   223         
       
   224         // Value length and data
       
   225         len = aStream.ReadInt16L();
       
   226         value = ReadBufferFromStreamLC( len, aStream );
       
   227         
       
   228         // Append
       
   229         CCFKeyValuePair* keyValuePair = CCFKeyValuePair::NewL( key, value );
       
   230         CleanupStack::Pop( value );
       
   231         CleanupStack::Pop( key );
       
   232 
       
   233         CleanupStack::PushL( keyValuePair );
       
   234         iParameters.AppendL( keyValuePair );
       
   235         CleanupStack::Pop( keyValuePair );
       
   236         }
       
   237     }
       
   238 
       
   239 //-----------------------------------------------------------------------------
       
   240 // CCFActionIndicationImpl::ReadBufferFromStreamLC
       
   241 //-----------------------------------------------------------------------------
       
   242 //
       
   243 HBufC* CCFActionIndicationImpl::ReadBufferFromStreamLC( TInt aLength,
       
   244     RReadStream& aStream )
       
   245     {
       
   246     FUNC_LOG;
       
   247     
       
   248     HBufC* buffer = HBufC::NewLC( aLength );
       
   249     TPtr bufferPtr = buffer->Des();
       
   250     aStream.ReadL( bufferPtr, aLength );
       
   251     
       
   252     return buffer;
       
   253     }