ximpfw/presence/srcpresencedatamodel/presencepublishing/presencewatcherinfoimp.cpp
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     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:  MPresenceWatcherInfo API object implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "presencewatcherinfoimp.h"
       
    20 #include "ximpidentityimp.h"
       
    21 #include "ximprbufhelpers.h"
       
    22 #include "ximpobjecthelpers.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS =============================
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CPresenceWatcherInfoImp::NewLC()
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C CPresenceWatcherInfoImp* CPresenceWatcherInfoImp::NewLC(
       
    31                             const MPresenceWatcherInfo::TWatcherType aType,
       
    32                             const MXIMPIdentity& aIdentity,
       
    33                             const TDesC16& aDisplayName )
       
    34     {
       
    35     CPresenceWatcherInfoImp* self = new( ELeave ) CPresenceWatcherInfoImp;
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL( aType, aIdentity, aDisplayName );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CPresenceWatcherInfoImp::NewLC()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C CPresenceWatcherInfoImp* CPresenceWatcherInfoImp::NewLC()
       
    46     {
       
    47     CPresenceWatcherInfoImp* self = new( ELeave ) CPresenceWatcherInfoImp;
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CPresenceWatcherInfoImp::NewL()
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C CPresenceWatcherInfoImp* CPresenceWatcherInfoImp::NewL()
       
    59     {
       
    60     CPresenceWatcherInfoImp* self = NewLC();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CPresenceWatcherInfoImp::NewFromStreamLC()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CPresenceWatcherInfoImp )
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Implement supported interface access.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CPresenceWatcherInfoImp, 
       
    77                                      MPresenceWatcherInfo )
       
    78 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    79 
       
    80 
       
    81 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CPresenceWatcherInfoImp, 
       
    82                                            MPresenceWatcherInfo )
       
    83 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CPresenceWatcherInfoImp::~CPresenceWatcherInfoImp()
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CPresenceWatcherInfoImp::~CPresenceWatcherInfoImp()
       
    90     {
       
    91     iDisplayName.Close();
       
    92     delete iIdentity;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CPresenceWatcherInfoImp::CPresenceWatcherInfoImp()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CPresenceWatcherInfoImp::CPresenceWatcherInfoImp()
       
   100     {
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CPresenceWatcherInfoImp::ConstructL()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CPresenceWatcherInfoImp::ConstructL()
       
   109     {
       
   110     iDisplayName.CreateL( 0 );
       
   111     iIdentity = CXIMPIdentityImp::NewLC();
       
   112     CleanupStack::Pop( iIdentity );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CPresenceWatcherInfoImp::ConstructL()
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CPresenceWatcherInfoImp::ConstructL(
       
   120                             const MPresenceWatcherInfo::TWatcherType aType,
       
   121                             const MXIMPIdentity& aIdentity,
       
   122                             const TDesC16& aDisplayName )
       
   123     {
       
   124     iType = aType;
       
   125 
       
   126     const CXIMPIdentityImp* sourceIdentity =
       
   127     TXIMPGetImpClassOrPanic< const CXIMPIdentityImp >::From( aIdentity );
       
   128     iIdentity = TXIMPObjectCloner< CXIMPIdentityImp >::CloneL( *sourceIdentity );
       
   129     
       
   130     iDisplayName.CreateL( aDisplayName );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CPresenceWatcherInfoImp::ExternalizeL()
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CPresenceWatcherInfoImp::ExternalizeL( RWriteStream& aStream ) const
       
   138     {
       
   139     aStream.WriteInt32L( iType );
       
   140     iIdentity->ExternalizeL( aStream );
       
   141     XIMPRBuf16Helper::ExternalizeL( iDisplayName, aStream );
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CPresenceWatcherInfoImp::InternalizeL()
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C void CPresenceWatcherInfoImp::InternalizeL( RReadStream& aStream )
       
   149     {
       
   150     iType = ( MPresenceWatcherInfo::TWatcherType ) aStream.ReadInt32L();
       
   151     iIdentity->InternalizeL( aStream );
       
   152     XIMPRBuf16Helper::InternalizeL( iDisplayName, aStream );
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // From MPresenceWatcherInfo class.
       
   157 // CPresenceWatcherInfoImp::WatcherId()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 const MXIMPIdentity& CPresenceWatcherInfoImp::WatcherId() const
       
   161     {
       
   162     return *iIdentity;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // From MPresenceWatcherInfo class.
       
   167 // CPresenceWatcherInfoImp::WatcherDisplayName()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 const TDesC16& CPresenceWatcherInfoImp::WatcherDisplayName() const
       
   171     {
       
   172     return iDisplayName;
       
   173     }
       
   174     
       
   175     
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // From MPresenceWatcherInfo class.
       
   179 // CPresenceWatcherInfoImp::WatcherType()
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 MPresenceWatcherInfo::TWatcherType CPresenceWatcherInfoImp::WatcherType() const
       
   183     {
       
   184     return iType;
       
   185     }    
       
   186     
       
   187     
       
   188 // ---------------------------------------------------------------------------
       
   189 // From MPresenceWatcherInfo class.
       
   190 // CPresenceWatcherInfoImp::SetWatcherIdL()
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CPresenceWatcherInfoImp::SetWatcherIdL( MXIMPIdentity* aIdentity )
       
   194     {
       
   195     User::LeaveIfError( aIdentity == NULL ? KErrArgument : KErrNone );
       
   196 
       
   197     CXIMPIdentityImp* identityImp =
       
   198     TXIMPGetImpClassOrPanic< CXIMPIdentityImp>::From( *aIdentity );
       
   199 
       
   200     delete iIdentity;
       
   201     iIdentity = identityImp; 
       
   202     }    
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // From MPresenceWatcherInfo class.
       
   207 // CPresenceWatcherInfoImp::SetWatcherDisplayNameL()
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CPresenceWatcherInfoImp::SetWatcherDisplayNameL( 
       
   211     const TDesC16& aDisplayName )
       
   212     {
       
   213     HBufC16* displayNameBuf = aDisplayName.AllocL();
       
   214     iDisplayName.Close();
       
   215     iDisplayName.Assign( displayNameBuf );
       
   216     }    
       
   217 
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // From MPresenceWatcherInfo class.
       
   221 // CPresenceWatcherInfoImp::SetWatcherTypeL()
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CPresenceWatcherInfoImp::SetWatcherTypeL( 
       
   225     MPresenceWatcherInfo::TWatcherType aType )
       
   226     {
       
   227     iType = aType;
       
   228     }    
       
   229 
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CPresenceWatcherInfoImp::SetIdentityL()
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C void CPresenceWatcherInfoImp::SetIdentity( CXIMPIdentityImp* aIdentity )
       
   236     {
       
   237     delete iIdentity;
       
   238     iIdentity = aIdentity;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CPresenceWatcherInfoImp::SetIdentityL()
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C void CPresenceWatcherInfoImp::SetDisplayName( HBufC16* aDisplayName )
       
   246     {
       
   247     iDisplayName.Close();
       
   248     iDisplayName.Assign( aDisplayName );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CPresenceWatcherInfoImp::GroupIdLinearOrder()
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C TInt CPresenceWatcherInfoImp::IdLinearOrder(
       
   256         const CPresenceWatcherInfoImp& aA,
       
   257         const CPresenceWatcherInfoImp& aB )
       
   258     {
       
   259     return aA.IdentityImp().Compare( aB.IdentityImp() );
       
   260     }
       
   261 // ---------------------------------------------------------------------------
       
   262 // CPresenceWatcherInfoImp::Identity()
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 EXPORT_C const CXIMPIdentityImp& CPresenceWatcherInfoImp::IdentityImp() const
       
   266     {
       
   267     return *iIdentity;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CPresenceWatcherInfoImp::EqualsContent()
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 TBool CPresenceWatcherInfoImp::EqualsContent( 
       
   275     const CXIMPApiDataObjBase& aOtherInstance ) const
       
   276     {
       
   277     const CPresenceWatcherInfoImp* tmp =
       
   278     TXIMPGetImpClassOrPanic< const CPresenceWatcherInfoImp >::From( 
       
   279                                                         aOtherInstance.Base() );
       
   280 
       
   281     TBool same = ETrue;
       
   282     TBool x;
       
   283     x = iIdentity->EqualsContent( *( tmp->iIdentity ) );
       
   284     same &= x;
       
   285 
       
   286     x = 0 == iDisplayName.Compare( tmp->iDisplayName );
       
   287     same &= x;
       
   288 
       
   289     x = iType == iType;
       
   290     same &= x;
       
   291 
       
   292     // add more comparisons in a similar way...
       
   293 
       
   294     return same;
       
   295     }
       
   296 
       
   297 // End of file