ximpfw/presence/srcpresencedatamodel/presencewatching/presentitypresencesubscriptionitem.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:  Presence Service Connection group list subscription implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "presentitypresencesubscriptionitem.h"
       
    20 #include "presenceinfofilterimp.h"
       
    21 #include "ximpitemparent.h"
       
    22 #include "ximppanics.h"
       
    23 #include "ximppsccontext.h"
       
    24 #include "documentutils.h"
       
    25 #include "presentitypresenceeventimp.h"
       
    26 #include "ximpdatasubscriptionstateimp.h"
       
    27 #include "ximpidentityimp.h"
       
    28 #include "ximpobjecthelpers.h"
       
    29 #include <presencecachewriter.h>
       
    30 #include <presencebuddyinfo.h>
       
    31 
       
    32 #include "ximptrace.h"
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CPresentityPresenceSubscriptionItem::CPresentityPresenceSubscriptionItem()
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CPresentityPresenceSubscriptionItem::CPresentityPresenceSubscriptionItem( MXIMPItemParentBase& aParent )
       
    39 : CXIMPSubscriptionItemBase( aParent )
       
    40     {
       
    41     }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CPresentityPresenceSubscriptionItem::ConstructL()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CPresentityPresenceSubscriptionItem::ConstructL( const CXIMPIdentityImp& aIdentity )
       
    49     {
       
    50     BaseConstructL();
       
    51     
       
    52     iIdentity = TXIMPObjectCloner< CXIMPIdentityImp >::CloneL( aIdentity );
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CPresentityPresenceSubscriptionItem::NewLC()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CPresentityPresenceSubscriptionItem*
       
    61     CPresentityPresenceSubscriptionItem::NewLC( MXIMPItemParentBase& aParent, const CXIMPIdentityImp& aIdentity )
       
    62     {
       
    63     CPresentityPresenceSubscriptionItem* self =
       
    64         new( ELeave ) CPresentityPresenceSubscriptionItem( aParent );
       
    65     CleanupClosePushL( *self );
       
    66     self->ConstructL( aIdentity );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CPresentityPresenceSubscriptionItem::~CPresentityPresenceSubscriptionItem()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CPresentityPresenceSubscriptionItem::~CPresentityPresenceSubscriptionItem()
       
    76     {
       
    77     // Remove it also from the external cache
       
    78     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
    79     if(presCache)
       
    80         {
       
    81             MPresenceCacheWriter* extCache = presCache->ExternalCache();
       
    82             if(extCache && iIdentity)
       
    83                 TRAP_IGNORE( extCache->DeletePresenceL( *iIdentity ) );
       
    84             presCache->RemoveMe( this );
       
    85         }
       
    86     delete iIdentity;
       
    87     delete iPresenceInfo;
       
    88     delete iPif;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CPresentityPresenceSubscriptionItem::SubscriptionPif()
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C CPresenceInfoFilterImp&
       
    96             CPresentityPresenceSubscriptionItem::SubscriptionPif()
       
    97     {
       
    98     TRACE(_L("CPresentityPresenceSubscriptionItem::SubscriptionPif" ) );
       
    99     // assert removed
       
   100     return *iPif;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CPresentityPresenceSubscriptionItem::SetSubscriptionPif()
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void CPresentityPresenceSubscriptionItem::SetSubscriptionPif(
       
   108                                                 CPresenceInfoFilterImp* aPif )
       
   109     {
       
   110     TRACE(_L("CPresentityPresenceSubscriptionItem::SetSubscriptionPif" ) );
       
   111     if ( !aPif )
       
   112         {
       
   113         TRACE(_L("CPresentityPresenceSubscriptionItem::SetSubscriptionPif aPif NULL" ) );
       
   114         }
       
   115     delete iPif;
       
   116     iPif = aPif;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CPresentityPresenceSubscriptionItem::CollectSubscriptionPifWithoutCtxL()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C CPresenceInfoFilterImp*
       
   124     CPresentityPresenceSubscriptionItem::CollectSubscriptionPifWithoutCtxL(
       
   125                                                         MXIMPPscContext* aContext )
       
   126     {
       
   127     TRACE(_L("CPresentityPresenceSubscriptionItem::CollectSubscriptionPifWithoutCtxL" ) );
       
   128     RPointerArray< CPresenceInfoFilterImp > arrayOfPifs;
       
   129     CleanupClosePushL( arrayOfPifs );
       
   130 
       
   131     TInt count = iContexts.Count();
       
   132     for( TInt a = 0; a < count; ++a )
       
   133         {
       
   134         if( iContexts[ a ] != aContext )
       
   135             {
       
   136             CPresenceInfoFilterImp* filter = iContexts[ a ]->PresenceInfoFilter( 
       
   137                         MXIMPPscContext::EPresentityPresenceFilter, iIdentity );
       
   138             if ( filter )
       
   139                 {
       
   140                 arrayOfPifs.AppendL( filter );
       
   141                 }
       
   142             }
       
   143         }
       
   144     CPresenceInfoFilterImp* pifWithoutCtx = DocumentUtils::InfoFilterUnionL( arrayOfPifs );
       
   145     CleanupStack::PopAndDestroy(); // arrayOfPifs
       
   146     return pifWithoutCtx;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CPresentityPresenceSubscriptionItem::SetPresenceInfoL()
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CPresentityPresenceSubscriptionItem::SetPresenceInfoL(
       
   154                                             CPresenceInfoImp* aPresenceInfo )
       
   155     {
       
   156     TRACE(_L("CPresentityPresenceSubscriptionItem::SetPresenceInfoL" ) );
       
   157     delete iPresenceInfo;
       
   158     iPresenceInfo = aPresenceInfo;
       
   159     iSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable );
       
   160     
       
   161     // Now let's update the external presence cache
       
   162     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   163     MPresenceCacheWriter* extCache = presCache->ExternalCache();
       
   164     MPresenceBuddyInfo* buddyPresence = extCache->NewBuddyPresenceInfoLC();
       
   165     
       
   166     // we need to clonce the parameters since the ownership is transfered
       
   167     CXIMPIdentityImp* identity = TXIMPObjectCloner<CXIMPIdentityImp>::CloneL(*iIdentity);
       
   168     buddyPresence->SetBuddyId( identity );
       
   169     
       
   170     CPresenceInfoImp* presenceInfo = TXIMPObjectCloner<CPresenceInfoImp>::CloneL(*iPresenceInfo);
       
   171     buddyPresence->SetPresenceInfo( presenceInfo );
       
   172 
       
   173     // No harm to do this, because the internal cache is still working
       
   174     // we just lose the external update
       
   175     TRAP_IGNORE( extCache->WritePresenceL( buddyPresence ) );
       
   176 
       
   177     CleanupStack::PopAndDestroy( 1 ); // buddyPresence
       
   178     
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CPresentityPresenceSubscriptionItem::Order()
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C TInt CPresentityPresenceSubscriptionItem::Order(
       
   186                         const CPresentityPresenceSubscriptionItem& aA,
       
   187                         const CPresentityPresenceSubscriptionItem& aB )
       
   188     {
       
   189     return IdentityOrder( aA.iIdentity, aB );
       
   190     }
       
   191 // ---------------------------------------------------------------------------
       
   192 // CPresentityPresenceSubscriptionItem::Order()
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C TInt CPresentityPresenceSubscriptionItem::IdentityOrder(
       
   196                         const CXIMPIdentityImp* aA,
       
   197                         const CPresentityPresenceSubscriptionItem& aB )
       
   198     {
       
   199     return aA->Compare( *aB.iIdentity );
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CPresentityPresenceSubscriptionItem::Identity()
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C const MXIMPIdentity& CPresentityPresenceSubscriptionItem::Identity() const
       
   208     {
       
   209     return *iIdentity;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CPresentityPresenceSubscriptionItem::GroupIdentity()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C const MXIMPIdentity* CPresentityPresenceSubscriptionItem::GroupIdentity() const
       
   217     {
       
   218     return iGroupIdentity;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CPresentityPresenceSubscriptionItem::SetIdentity()
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 EXPORT_C void CPresentityPresenceSubscriptionItem::SetIdentity(
       
   226                                             CXIMPIdentityImp* aIdentity )
       
   227     {
       
   228     delete iIdentity;
       
   229     iIdentity = aIdentity;
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CPresentityPresenceSubscriptionItem::SetGroupIdentity()
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CPresentityPresenceSubscriptionItem::SetGroupIdentity(
       
   238                                             CXIMPIdentityImp* aGroup )
       
   239     {
       
   240     delete iGroupIdentity;
       
   241     iGroupIdentity = aGroup;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // From class MXIMPSubscriptionItem.
       
   246 // CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventTo()
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL(
       
   250                                                     MXIMPPscContext* aContext,
       
   251                                                     TBool aForceEvent )
       
   252     {
       
   253     TRACE_1( _L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventTo() aForce=%d"), aForceEvent );
       
   254     CXIMPDataSubscriptionStateImp* status = StatusLC( aContext ); // << status
       
   255 
       
   256     CPresentityPresenceEventImp* newEvent = NULL;
       
   257     if( status->DataState() == MXIMPDataSubscriptionState::EDataAvailable )
       
   258         {
       
   259         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 2" ) );
       
   260         __ASSERT_ALWAYS( iPresenceInfo, User::Panic( NXIMPPrivPanic::KCategory,
       
   261                                             NXIMPPrivPanic::EPresentityPresencePresenceInfoDoesNotExist ) );
       
   262         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 3" ) );
       
   263 		// ERIK TODO: Logic is the following:
       
   264 		// 1 - Find all the groups where the iIdentity belongs to
       
   265 		// 2 - Collect the filters from those groups
       
   266 		// 3 - collect the filter from the individual subscription item also own
       
   267 		// 4 - make a union of the filters
       
   268         
       
   269         CPresenceInfoFilterImp* groupPif = NULL;
       
   270         if ( iGroupIdentity ) 
       
   271             { 
       
   272             groupPif = aContext->PresenceInfoFilter( MXIMPPscContext::EPresentityGroupMemberPresenceFilter, iGroupIdentity );
       
   273             if ( !iPif )
       
   274                 {
       
   275                 TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL ownPif found" ) );
       
   276                 iPif = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneLC( *groupPif );
       
   277                 CleanupStack::Pop();
       
   278                 }
       
   279             }
       
   280         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 4_0" ) );
       
   281         CPresenceInfoFilterImp* ownPif = aContext->PresenceInfoFilter( MXIMPPscContext::EOwnPresenceFilter, iIdentity );
       
   282         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 4_1" ) );
       
   283         CPresenceInfoFilterImp* presentityPif = aContext->PresenceInfoFilter( MXIMPPscContext::EPresentityPresenceFilter, iIdentity );
       
   284         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 4_2" ) );
       
   285     	RPointerArray< CPresenceInfoFilterImp > arrayOfPifs;    // << arrayOfPifs
       
   286     	CleanupClosePushL( arrayOfPifs );
       
   287     
       
   288         if ( groupPif )
       
   289             {
       
   290             TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL groupPif found" ) );
       
   291             arrayOfPifs.AppendL( groupPif );
       
   292             if ( !iPif )
       
   293                 {
       
   294                 TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL iPif created" ) );
       
   295                 SetSubscriptionPif( groupPif );
       
   296                 //iPif = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneLC( groupPif );
       
   297                 //CleanupStack::Pop();
       
   298                 }
       
   299             }
       
   300         if ( ownPif )
       
   301             {
       
   302             TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL ownPif found" ) );
       
   303             arrayOfPifs.AppendL( ownPif );
       
   304             }
       
   305         if ( presentityPif )
       
   306             {
       
   307             TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL presentityPif found" ) );
       
   308             arrayOfPifs.AppendL( presentityPif );
       
   309             }
       
   310         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 4_3" ) );
       
   311 		CPresenceInfoFilterImp* unionPif = NULL;
       
   312     	unionPif = DocumentUtils::InfoFilterUnionL( arrayOfPifs );    
       
   313     	if ( unionPif ) 
       
   314     	    {
       
   315     	    TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL unionPif found" ) );
       
   316     	    }
       
   317     	CleanupStack::PopAndDestroy(); // >>> arrayOfPifs
       
   318     	CleanupStack::PushL( unionPif );    // << unionPif
       
   319 
       
   320         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 5" ) );
       
   321         CPresenceInfoImp* filteredPresenceInfo = 
       
   322                 DocumentUtils::CollectFilteredPresenceInfoLC(
       
   323                     *unionPif, 
       
   324                     *iPresenceInfo );   // << filteredPresenceInfo
       
   325         
       
   326         CleanupStack::Pop( filteredPresenceInfo ); // >> filteredPresenceInfo
       
   327         CleanupStack::PopAndDestroy( unionPif );    // >>> unionPif
       
   328         CleanupStack::PushL( filteredPresenceInfo );    // << filteredPresenceInfo
       
   329         TRACE(_L("CPresentityPresenceSubscriptionItem::SynthesiseSubscriptionEventToL 6" ) );
       
   330         newEvent = CPresentityPresenceEventImp::NewL( status ); // CSI: 35 # Event is put to cleanupstack in next branch.
       
   331         newEvent->SetPresenceInfo( filteredPresenceInfo );
       
   332         CleanupStack::Pop( filteredPresenceInfo ); // >> filteredPresenceInfo
       
   333         CleanupStack::Pop( status );    // >> status
       
   334         newEvent->SetIdentityL( *iIdentity );
       
   335         }
       
   336     else if( aForceEvent )
       
   337         {
       
   338         newEvent = CPresentityPresenceEventImp::NewL( status ); // CSI: 35 # Event is put to cleanupstack in next branch.
       
   339         CleanupStack::Pop( status );
       
   340         newEvent->SetIdentityL( *iIdentity );
       
   341         }
       
   342 
       
   343     if( newEvent )
       
   344         {
       
   345         CleanupStack::PushL( newEvent );
       
   346         MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   347         presCache->AddEventL( *newEvent, aContext );
       
   348         }
       
   349     CleanupStack::PopAndDestroy(); //status || newEvent depending on branch
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // CPresentityPresenceSubscriptionItem::CleanExpired()
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void CPresentityPresenceSubscriptionItem::CleanExpired()
       
   357     {
       
   358 
       
   359     }
       
   360 
       
   361 // End of file