ximpfw/presence/srcpresencedatamodel/presenceauthorization/groupmemberspresenceconfigurationitem.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:  Group members presence configuration item
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "groupmemberspresenceconfigurationitem.h"
       
    20 #include "groupcontentsubscriptionitem.h"
       
    21 #include "presenceinfofilterimp.h"
       
    22 #include "ximpitemparent.h"
       
    23 #include "ximppanics.h"
       
    24 #include "ximppsccontext.h"
       
    25 #include "documentutils.h" // Perhaps this should be renamed
       
    26 #include "presentitypresenceeventimp.h"
       
    27 #include "presentitygroupmemberinfoimp.h"
       
    28 #include "ximpidentityimp.h"
       
    29 
       
    30 #include "ximptrace.h"
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CGroupMembersPresenceConfigurationItem::CGroupMembersPresenceConfigurationItem()
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CGroupMembersPresenceConfigurationItem::CGroupMembersPresenceConfigurationItem( MXIMPItemParentBase& aParent, CGroupContentSubscriptionItem& aContentItem )
       
    37 : CXIMPConfigurationItemBase( aParent ), iContentItem( aContentItem )
       
    38     {
       
    39     }
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CGroupMembersPresenceConfigurationItem::ConstructL()
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CGroupMembersPresenceConfigurationItem::ConstructL()
       
    47     {
       
    48     BaseConstructL();
       
    49     iContentItem.RegisterEventObserverL( this );
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CGroupMembersPresenceConfigurationItem::NewLC()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CGroupMembersPresenceConfigurationItem*
       
    58     CGroupMembersPresenceConfigurationItem::NewLC( MXIMPItemParentBase& aParent,
       
    59                                                    CGroupContentSubscriptionItem& aContentItem )
       
    60     {
       
    61     CGroupMembersPresenceConfigurationItem* self =
       
    62         new( ELeave ) CGroupMembersPresenceConfigurationItem( aParent, aContentItem );
       
    63     CleanupClosePushL( *self );
       
    64     self->ConstructL();
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CGroupMembersPresenceConfigurationItem::~CGroupMembersPresenceConfigurationItem()
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CGroupMembersPresenceConfigurationItem::~CGroupMembersPresenceConfigurationItem()
       
    74     {
       
    75     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
    76     presCache->RemoveMe( this );
       
    77 
       
    78 
       
    79     delete iIdentity;
       
    80 
       
    81     delete iPif;
       
    82     iContentItem.UnregisterEventObserver( this );
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CGroupMembersPresenceConfigurationItem::ConfigurationPif()
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CPresenceInfoFilterImp&
       
    90             CGroupMembersPresenceConfigurationItem::ConfigurationPif()
       
    91     {
       
    92     TRACE(_L("CGroupMembersPresenceConfigurationItem::ConfigurationPif" ) );
       
    93     __ASSERT_ALWAYS( iPif, User::Panic( NXIMPPrivPanic::KCategory,
       
    94                                         NXIMPPrivPanic::EOwnPresencePifNotSet ) );
       
    95     return *iPif;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CGroupMembersPresenceConfigurationItem::SetConfigurationPif()
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C void CGroupMembersPresenceConfigurationItem::SetConfigurationPif(
       
   103                                                 CPresenceInfoFilterImp* aPif )
       
   104     {
       
   105     TRACE(_L("CGroupMembersPresenceConfigurationItem::SetConfigurationPif" ) );
       
   106     if ( !aPif )
       
   107         {
       
   108         TRACE(_L("CGroupMembersPresenceConfigurationItem::SetConfigurationPif aPif NULL" ) );
       
   109         }
       
   110     delete iPif;
       
   111     iPif = aPif;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CGroupMembersPresenceConfigurationItem::CollectSubscriptionPifWithoutCtxL()
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C CPresenceInfoFilterImp*
       
   119     CGroupMembersPresenceConfigurationItem::CollectConfigurationPifWithoutCtxL(
       
   120                                                         MXIMPPscContext* aContext )
       
   121     {
       
   122     TRACE(_L("CGroupMembersPresenceConfigurationItem::CollectConfigurationPifWithoutCtxL" ) );
       
   123     RPointerArray< CPresenceInfoFilterImp > arrayOfPifs;
       
   124     CleanupClosePushL( arrayOfPifs );
       
   125 
       
   126     TInt count = iConfigContexts.Count();
       
   127     for( TInt a = 0; a < count; ++a )
       
   128         {
       
   129         if( iConfigContexts[ a ] != aContext )
       
   130             {
       
   131             CPresenceInfoFilterImp* filter = iConfigContexts[ a ]->PresenceInfoFilter( 
       
   132                         MXIMPPscContext::EGrantPresenceToGroupMemberFilter, iIdentity );
       
   133             if ( filter )
       
   134                 {
       
   135                 arrayOfPifs.AppendL( filter );
       
   136                 }
       
   137             }
       
   138         }
       
   139     CPresenceInfoFilterImp* pifWithoutCtx = DocumentUtils::InfoFilterUnionL( arrayOfPifs );
       
   140     CleanupStack::PopAndDestroy(); // arrayOfPifs
       
   141     TRACE(_L("CGroupMembersPresenceConfigurationItem::CollectConfigurationPifWithoutCtxL done" ) );
       
   142     return pifWithoutCtx;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CGroupMembersPresenceConfigurationItem::Order()
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C TInt CGroupMembersPresenceConfigurationItem::Order(
       
   150                         const CGroupMembersPresenceConfigurationItem& aA,
       
   151                         const CGroupMembersPresenceConfigurationItem& aB )
       
   152     {
       
   153     return IdentityOrder( aA.iIdentity, aB );
       
   154     }
       
   155 // ---------------------------------------------------------------------------
       
   156 // CGroupMembersPresenceConfigurationItem::Order()
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C TInt CGroupMembersPresenceConfigurationItem::IdentityOrder(
       
   160                         const CXIMPIdentityImp* aA,
       
   161                         const CGroupMembersPresenceConfigurationItem& aB )
       
   162     {
       
   163     return aA->Compare( *aB.iIdentity );
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CGroupMembersPresenceConfigurationItem::Identity()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C const MXIMPIdentity& CGroupMembersPresenceConfigurationItem::Identity() const
       
   171     {
       
   172     return *iIdentity;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CGroupMembersPresenceConfigurationItem::SetIdentity()
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C void CGroupMembersPresenceConfigurationItem::SetIdentity(
       
   180                                             CXIMPIdentityImp* aIdentity )
       
   181     {
       
   182     delete iIdentity;
       
   183     iIdentity = aIdentity;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // From class MXIMPSubscriptionItem.
       
   188 // CGroupMembersPresenceConfigurationItem::SynthesiseSubscriptionEventTo()
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CGroupMembersPresenceConfigurationItem::SynthesiseSubscriptionEventToL(
       
   192                                                     MXIMPPscContext* aContext,
       
   193                                                     TBool aForceEvent )
       
   194     {
       
   195     TRACE_1( _L("CGroupMembersPresenceConfigurationItem::SynthesiseSubscriptionEventTo() aForce=%d"), aForceEvent );
       
   196     // Synthesise event to all members
       
   197     TInt count = iContentItem.MemberCount();
       
   198     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   199     for( TInt a = 0; a < count; ++a )
       
   200         {
       
   201         CPresentityGroupMemberInfoImp& memberInfo = iContentItem.MemberAt( a );
       
   202         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   203 
       
   204         presCache->SynthesisePresentityPresenceSubscriptionEventToL( identity, aContext, aForceEvent );
       
   205         }
       
   206     TRACE(_L("CGroupMembersPresenceConfigurationItem::SynthesiseSubscriptionEventTo done" ) );
       
   207     }
       
   208 
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CGroupMembersPresenceConfigurationItem::ActivateSubscriberL()
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CGroupMembersPresenceConfigurationItem::ActivateSubscriberL( MXIMPPscContext* aContext )
       
   215     {
       
   216     TRACE_1( _L("CGroupMembersPresenceConfigurationItem::ActivateSubscriberL() aContext=%d"), aContext );
       
   217     CXIMPSubscriptionItemBase::ActivateSubscriberL( aContext );
       
   218 
       
   219     // Subscribe presentity presence items.
       
   220     TInt count = iContentItem.MemberCount();
       
   221     TRACE_1( _L("CGroupMembersPresenceConfigurationItem::ActivateSubscriberL( MXIMPPscContext* aContext ) : iContentItem.MemberCount = %d"), count );
       
   222     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   223     for( TInt a = 0; a < count; ++a )
       
   224         {
       
   225         TRACE_1( _L("CGroupMembersPresenceConfigurationItem::ActivateSubscriberL( MXIMPPscContext* aContext ) : a = %d"), a );
       
   226         
       
   227         CPresentityGroupMemberInfoImp& memberInfo = iContentItem.MemberAt( a );
       
   228         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   229         TInt error ( KErrNone );
       
   230         TRAP( error, presCache->ActivatePresentityPresenceSubscriberL( identity, this );)
       
   231         TRACE_1( _L("CGroupMembersPresenceConfigurationItem::ActivateSubscriberL( MXIMPPscContext* aContext ) : iParent.ActivatePresentityPresenceSubscriberL : error = %d"), error );
       
   232 
       
   233         }
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CGroupMembersPresenceConfigurationItem::CleanExpired()
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CGroupMembersPresenceConfigurationItem::CleanExpired()
       
   242     {
       
   243 
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CGroupMembersPresenceConfigurationItem::AddConfiguratorL()
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C void CGroupMembersPresenceConfigurationItem::AddConfiguratorL( MXIMPPscContext* aContext )
       
   251     {
       
   252     CXIMPConfigurationItemBase::AddConfiguratorL( aContext );
       
   253 
       
   254 	MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   255     // Subscribe presentity presence items.
       
   256     TInt count = iContentItem.MemberCount();
       
   257     for( TInt a = 0; a < count; ++a )
       
   258         {
       
   259         CPresentityGroupMemberInfoImp& memberInfo = iContentItem.MemberAt( a );
       
   260         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   261 
       
   262         presCache->AddPresenceConfiguratorL( identity, this );
       
   263         }
       
   264     }
       
   265 
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CGroupMembersPresenceConfigurationItem::RemoveConfigurator()
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C void CGroupMembersPresenceConfigurationItem::RemoveConfigurator( MXIMPPscContext* aContext )
       
   272     {
       
   273     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   274     // Subscribe presentity presence items.
       
   275     TInt count = iContentItem.MemberCount();
       
   276     for( TInt a = 0; a < count; ++a )
       
   277         {
       
   278         CPresentityGroupMemberInfoImp& memberInfo = iContentItem.MemberAt( a );
       
   279         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   280 
       
   281         presCache->RemovePresenceConfigurator( identity, this );
       
   282         }
       
   283     CXIMPConfigurationItemBase::RemoveConfigurator( aContext );
       
   284     }
       
   285 
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // CGroupMembersPresenceConfigurationItem::HandleEventL()
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CGroupMembersPresenceConfigurationItem::HandleChangeL(
       
   292                                 RPrGrpMemInfoImpArray& aAdded, RPrGrpMemInfoImpArray& aRemoved )
       
   293     {
       
   294     TRACE(_L("CGroupMembersPresenceConfigurationItem::ConfigurationPif" ) );
       
   295     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   296     TInt count = aAdded.Count();
       
   297     for( TInt a = 0; a < count; ++a )
       
   298         {
       
   299         CPresentityGroupMemberInfoImp& memberInfo = *aAdded[ a ];
       
   300         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   301 
       
   302         presCache->AddPresenceConfiguratorL( identity, this );
       
   303         }
       
   304     count = aRemoved.Count();
       
   305     for( TInt a = 0; a < count; ++a )
       
   306         {
       
   307         CPresentityGroupMemberInfoImp& memberInfo = *aRemoved[ a ];
       
   308         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   309 
       
   310         presCache->RemovePresenceConfigurator( identity, this );
       
   311         }
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CGroupMembersPresenceConfigurationItem::HandleEventL()
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CGroupMembersPresenceConfigurationItem::HandleSynthesiseL(
       
   319                                                         RPrGrpMemInfoImpArray& aTarget )
       
   320     {
       
   321     TRACE(_L("CGroupMembersPresenceConfigurationItem::ConfigurationPif" ) );
       
   322     TInt count = aTarget.Count();
       
   323     MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   324     for( TInt a = 0; a < count; ++a )
       
   325         {
       
   326         CPresentityGroupMemberInfoImp& memberInfo = *aTarget[ a ];
       
   327         const CXIMPIdentityImp& identity = memberInfo.IdentityImp();
       
   328 
       
   329         presCache->ActivatePresentityPresenceSubscriberL( identity, this );
       
   330         TInt contextCount = iContexts.Count();
       
   331         for( TInt b = 0; b < contextCount; ++b )
       
   332             {
       
   333             presCache->SynthesisePresentityPresenceSubscriptionEventToL( identity, iContexts[ a ], EFalse );
       
   334             }
       
   335         }
       
   336     }
       
   337 
       
   338 // End of file