ximpfw/presence/srcpresencedatamodel/presenceinfo/servicepresenceinfoimp.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation of MServicePresenceInfo object.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "presenceinfofield.h"
       
    20 #include "servicepresenceinfoimp.h"
       
    21 #include "presenceinfofieldcollectionimp.h"
       
    22 #include "ximprbufhelpers.h"
       
    23 #include "presenceinfofilterimp.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS =============================
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CServicePresenceInfoImp::NewLC()
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CServicePresenceInfoImp* CServicePresenceInfoImp::NewLC()
       
    32     {
       
    33     CServicePresenceInfoImp* self = new( ELeave ) CServicePresenceInfoImp;
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CServicePresenceInfoImp::NewFromStreamLC()
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CServicePresenceInfoImp )
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Implement supported interface access.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CServicePresenceInfoImp,
       
    50                                      MServicePresenceInfo )
       
    51 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    52 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CServicePresenceInfoImp,
       
    53                                            MServicePresenceInfo )
       
    54 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CServicePresenceInfoImp::~CServicePresenceInfoImp()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CServicePresenceInfoImp::~CServicePresenceInfoImp()
       
    61     {
       
    62     delete iFields;
       
    63     iServiceType.Close();
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CServicePresenceInfoImp::CServicePresenceInfoImp()
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CServicePresenceInfoImp::CServicePresenceInfoImp()
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CServicePresenceInfoImp::ConstructL()
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CServicePresenceInfoImp::ConstructL()
       
    79     {
       
    80     iFields = CPresenceInfoFieldCollectionImp::NewLC();
       
    81     CleanupStack::Pop( iFields );
       
    82 
       
    83     iServiceType.CreateL( 0 );
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CServicePresenceInfoImp::ExternalizeL()
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CServicePresenceInfoImp::ExternalizeL( RWriteStream& aStream ) const
       
    91     {
       
    92     XIMPRBuf8Helper::ExternalizeL( iServiceType, aStream );
       
    93     iFields->ExternalizeL( aStream );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CServicePresenceInfoImp::InternalizeL()
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C void CServicePresenceInfoImp::InternalizeL( RReadStream& aStream )
       
   101     {
       
   102     XIMPRBuf8Helper::InternalizeL( iServiceType, aStream );
       
   103     
       
   104     // we only have a parameterless ConstructL which creates the fields structure...
       
   105     CXIMPApiDataObjBase* tmp = CPresenceInfoFieldCollectionImp::NewFromStreamLC( aStream );
       
   106     CPresenceInfoFieldCollectionImp* fields = 
       
   107         TXIMPGetImpClassOrPanic< CPresenceInfoFieldCollectionImp >::From( tmp->Base() );
       
   108     delete iFields;
       
   109     iFields = fields;
       
   110     CleanupStack::Pop( tmp );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CServicePresenceInfoImp::EqualsContent()
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TBool CServicePresenceInfoImp::EqualsContent(
       
   118         const CXIMPApiDataObjBase& aOtherInstance ) const
       
   119     {
       
   120     const CServicePresenceInfoImp* tmp =
       
   121         TXIMPGetImpClassOrPanic< const CServicePresenceInfoImp >::From(
       
   122                 aOtherInstance.Base() );
       
   123 
       
   124     TBool same = ETrue;
       
   125     TBool x;
       
   126 
       
   127     x = iFields->EqualsContent( *( tmp->iFields ) );
       
   128     same &= x;
       
   129 
       
   130     return same;
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // From MServicePresenceInfo class.
       
   136 // CServicePresenceInfoImp::ServiceType()
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 const TPtrC8 CServicePresenceInfoImp::ServiceType() const
       
   140     {
       
   141     return iServiceType;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // From MServicePresenceInfo class.
       
   146 // CServicePresenceInfoImp::SetServiceTypeL()
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CServicePresenceInfoImp::SetServiceTypeL( const TDesC8& aServiceType ) 
       
   150     {
       
   151     HBufC8* tmp = aServiceType.AllocL();
       
   152     iServiceType.Close();
       
   153     iServiceType.Assign( tmp );
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // From MServicePresenceInfo class.
       
   159 // CServicePresenceInfoImp::Fields()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 const MPresenceInfoFieldCollection& CServicePresenceInfoImp::Fields() const
       
   163     {
       
   164     return *iFields;
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // From MServicePresenceInfo class.
       
   170 // CServicePresenceInfoImp::Fields()
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 MPresenceInfoFieldCollection& CServicePresenceInfoImp::Fields()
       
   174     {
       
   175     return *iFields;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CServicePresenceInfoImp::FilterWithL()
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CServicePresenceInfoImp::FilterWithL( const CPresenceInfoFilterImp& aFilter )
       
   183     {
       
   184     TInt count = iFields->FieldCount();
       
   185 
       
   186     // must traverse backwards when removing
       
   187     for ( TInt i = count-1; i >= 0; i-- )
       
   188         {
       
   189         if ( ! aFilter.MatchServiceFilterL( 
       
   190                     iServiceType, 
       
   191                     iFields->FieldAt( i ).FieldType() ) )
       
   192             {
       
   193             // no match, so remove the field
       
   194             // the filter tells us which ones to ACCEPT
       
   195             iFields->RemoveField( i );
       
   196             }
       
   197         }
       
   198     }
       
   199 
       
   200 
       
   201 // End of file