ximpfw/presence/srcpresencedatamodel/presentitygroups/grouplistsubscriptionitem.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 <badesca.h>
       
    20 
       
    21 #include "grouplistsubscriptionitem.h"
       
    22 #include "presenceinfofilterimp.h"
       
    23 #include "ximpitemparent.h"
       
    24 #include "ximppanics.h"
       
    25 #include "ximppsccontext.h"
       
    26 #include "documentutils.h"
       
    27 #include "presentitygrouplisteventimp.h"
       
    28 #include "presencetypehelpers.h"
       
    29 #include "presentitygroupinfoimp.h"
       
    30 //#include "ximpapieventbase.h"
       
    31 
       
    32 #include "ximptrace.h"
       
    33 // ---------------------------------------------------------------------------
       
    34 // CGroupListSubscriptionItem::CGroupListSubscriptionItem()
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CGroupListSubscriptionItem::CGroupListSubscriptionItem( MXIMPItemParentBase& aParent )
       
    38 : CXIMPSubscriptionItemBase( aParent )
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CGroupListSubscriptionItem::ConstructL()
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void CGroupListSubscriptionItem::ConstructL()
       
    48     {
       
    49     BaseConstructL();
       
    50     // empty lists must always exist
       
    51     iCurrentList = new ( ELeave) RPrGrpInfoImpArray;
       
    52 
       
    53     iCreated = new ( ELeave ) RPrGrpInfoImpArray;
       
    54     iUpdated = new ( ELeave ) RPrGrpInfoImpArray;
       
    55     iDeleted = new ( ELeave ) RPrGrpInfoImpArray;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CGroupListSubscriptionItem::NewL()
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CGroupListSubscriptionItem* CGroupListSubscriptionItem::NewLC( MXIMPItemParentBase& aParent )
       
    64     {
       
    65     CGroupListSubscriptionItem* self = new( ELeave ) CGroupListSubscriptionItem( aParent );
       
    66     CleanupClosePushL( *self );
       
    67     self->ConstructL();
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CGroupListSubscriptionItem::~CGroupListSubscriptionItem()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CGroupListSubscriptionItem::~CGroupListSubscriptionItem()
       
    77     {
       
    78         MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
    79     presCache->RemoveMe( this );
       
    80 
       
    81     if( iCurrentList )
       
    82         {
       
    83         iCurrentList->Close();
       
    84         }
       
    85     delete iCurrentList;
       
    86 
       
    87     Clean();
       
    88     // just in case
       
    89     delete iCreated;
       
    90     delete iDeleted;
       
    91     delete iUpdated;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CGroupListSubscriptionItem::SynthesiseSubscriptionEventTo()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CGroupListSubscriptionItem::SynthesiseSubscriptionEventToL(
       
    99         MXIMPPscContext* aContext, TBool aForceEvent )
       
   100     {
       
   101     TRACE_1( _L("CGroupListSubscriptionItem::SynthesiseSubscriptionEventTo() aForce=%d"), aForceEvent );
       
   102     CXIMPDataSubscriptionStateImp* status = StatusLC( aContext );
       
   103 
       
   104     if( status->DataState() == MXIMPDataSubscriptionState::EDataAvailable || aForceEvent )
       
   105         {
       
   106         CPresentityGroupListEventImp* newEvent = CPresentityGroupListEventImp::NewL(
       
   107                 iCreated,
       
   108                 iUpdated,
       
   109                 iDeleted,
       
   110                 aForceEvent ? iCurrentList : NULL,
       
   111                 status
       
   112                 );
       
   113         CleanupStack::Pop( status );
       
   114         CleanupStack::PushL( newEvent );
       
   115         
       
   116         MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT));
       
   117         presCache->AddEventL( *newEvent, aContext );
       
   118         
       
   119         }
       
   120     CleanupStack::PopAndDestroy(); //status || newEvent. Depending on branch.
       
   121     }
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CGroupListSubscriptionItem::SetNewListL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CGroupListSubscriptionItem::SetNewListL(
       
   129         RPrGrpInfoImpArray* aGroupList )
       
   130     {
       
   131     TRACE_1( _L("CGroupListSubscriptionItem::SetNewListL() aGroupList Count=%d"), aGroupList->Count() );
       
   132     // we will eventually take ownership to this
       
   133     RPrGrpInfoImpArray* tmp = aGroupList;
       
   134     CleanupDeletePushL( tmp );
       
   135 
       
   136     // the list is already sorted. when a copy was made in datacacheimp, the
       
   137     // InsertInOrder method was used
       
   138 
       
   139     // The below algorithm has complexity of (roughly):
       
   140     //   - aGroupList length M
       
   141     //   - iCurrentList final length N
       
   142     //
       
   143     //   Final complexity:
       
   144     //     M*(    1     // indexed accessor
       
   145     //          + logN  // find (ordered)
       
   146     //          + logN  // insert in order (find+insert)
       
   147     //          + O(1)  // delete
       
   148     //          + O(1)  // remove
       
   149     //        ) + O(1)  // updating iDeleted and iCurrentList
       
   150     //     = M(2logN+3) + 2MlogN+3M = O(cMlogM).
       
   151     //
       
   152     // Should be fast enough. The complexity is not fully accurate because
       
   153     // array size grows as we insert into it.
       
   154     //
       
   155     TLinearOrder<CPresentityGroupInfoImp>
       
   156         linearOrder( CPresentityGroupInfoImp::GroupIdLinearOrder );
       
   157 
       
   158     for ( TInt i = 0; i < tmp->Count(); i++ )
       
   159         {
       
   160         // compare against current list
       
   161         CPresentityGroupInfoImp* info = (*tmp)[ i ];
       
   162         TInt pos = iCurrentList->FindInOrder( info, linearOrder );
       
   163 
       
   164         if ( pos == KErrNotFound )
       
   165             {
       
   166             // not found in current list
       
   167             // so must be a fresh created list name
       
   168             iCreated->InsertInOrderL( info, linearOrder );
       
   169             }
       
   170         else
       
   171             {
       
   172             // found in current list, so it must be an updated list name
       
   173             iUpdated->InsertInOrderL( info, linearOrder );
       
   174 
       
   175             delete (*iCurrentList)[ pos ];
       
   176             iCurrentList->Remove( pos );
       
   177 
       
   178             // we must remove the found ones from iCurrentList,
       
   179             // otherwise we will not know what was left. and finding out
       
   180             // the deleted items will be difficult.
       
   181             }
       
   182         }
       
   183 
       
   184     // what's left in iCurrentList contains the deleted ones.
       
   185     delete iDeleted;
       
   186     iDeleted = iCurrentList;
       
   187 
       
   188     // the given list becomes the new list
       
   189     iCurrentList = tmp;
       
   190     CleanupStack::Pop( tmp );
       
   191     iSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable );
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CGroupListSubscriptionItem::SetCreatedListL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CGroupListSubscriptionItem::SetCreatedListL(
       
   199         RPrGrpInfoImpArray* aGroupList )
       
   200     {
       
   201     TRACE_1( _L("CGroupListSubscriptionItem::SetCreatedListL() aGroupList Count=%d"), aGroupList->Count() );
       
   202     // we took ownership to the given list
       
   203     RPrGrpInfoImpArray* tmp = aGroupList;
       
   204     CleanupDeletePushL( tmp );
       
   205 
       
   206     // see also SetNewListL.
       
   207 
       
   208     // the list is already sorted. when a copy was made in datacacheimp, the
       
   209     // InsertInOrder method was used
       
   210     TLinearOrder<CPresentityGroupInfoImp>
       
   211         linearOrder( CPresentityGroupInfoImp::GroupIdLinearOrder );
       
   212 
       
   213     // update the list of created and updated groups
       
   214     for ( TInt i = 0; i < tmp->Count(); i++ )
       
   215         {
       
   216         // compare against current list
       
   217         CPresentityGroupInfoImp* info = (*tmp)[ i ];
       
   218         TInt pos = iCurrentList->FindInOrder( info, linearOrder );
       
   219 
       
   220         if ( pos == KErrNotFound )
       
   221             {
       
   222             // not found in current list
       
   223             // so must be a fresh created list name.
       
   224             // this cannot come when the HandleDisplayNameUpdatedListL method
       
   225             // is called.
       
   226             iCurrentList->InsertInOrderL( info, linearOrder );
       
   227             ( *tmp )[ i ] = NULL;
       
   228             iCreated->InsertInOrderL( info, linearOrder );
       
   229             }
       
   230         else
       
   231             {
       
   232             // This can be checked if really had changed if needed. Now
       
   233             // we trust server that changes are reasonable.
       
   234 
       
   235             // change the display name of the updated group in the current list
       
   236             (*iCurrentList)[ pos ]->SetGroupDisplayNameL( info->GroupDisplayName() );
       
   237 
       
   238             // found in current list, so it must be an updated list name
       
   239             iUpdated->InsertInOrderL( (*iCurrentList)[ pos ], linearOrder );
       
   240             }
       
   241         }
       
   242 
       
   243     // current list may get updated display name to the existing elements,
       
   244     // otherwise the list is unchanged. list of deleted groups stays empty.
       
   245     // updated and created lists were updated. the input parameter list can be
       
   246     // deleted
       
   247     CleanupStack::PopAndDestroy( tmp );
       
   248     iSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CGroupListSubscriptionItem::SetDeletedListL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C void CGroupListSubscriptionItem::SetDeletedListL(
       
   256         RPrGrpInfoImpArray* aGroupList )
       
   257     {
       
   258     TRACE_1( _L("CGroupListSubscriptionItem::SetDeletedListL() aGroupList Count=%d"), aGroupList->Count() );
       
   259     // we will eventually take ownership to this
       
   260     RPrGrpInfoImpArray* tmp = aGroupList;
       
   261     CleanupDeletePushL( tmp );
       
   262 
       
   263     // see also SetNewListL.
       
   264 
       
   265     // the list is already sorted. when a copy was made in datacacheimp, the
       
   266     // InsertInOrder method was used
       
   267     TLinearOrder<CPresentityGroupInfoImp>
       
   268         linearOrder( CPresentityGroupInfoImp::GroupIdLinearOrder );
       
   269 
       
   270     // remove the deleted ones from the current list
       
   271     for ( TInt i = 0; i < tmp->Count(); i++ )
       
   272         {
       
   273         // compare against current list
       
   274         CPresentityGroupInfoImp* info = (*tmp)[ i ];
       
   275         TInt pos = iCurrentList->FindInOrder( info, linearOrder );
       
   276 
       
   277         // found in current list, so it must be a deleted list name
       
   278         if ( pos != KErrNotFound )
       
   279             {
       
   280             // remove from current list
       
   281             delete (*iCurrentList)[ pos ];
       
   282             iCurrentList->Remove( pos );
       
   283             }
       
   284         }
       
   285 
       
   286     // the given list becomes the new list of
       
   287     // deleted ones
       
   288     delete iDeleted;
       
   289     iDeleted = tmp;
       
   290     CleanupStack::Pop( tmp );
       
   291     iSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable );
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CGroupListSubscriptionItem::Clean
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 EXPORT_C void CGroupListSubscriptionItem::Clean()
       
   299     {
       
   300     TRACE( _L("CGroupListSubscriptionItem::Clean()") );
       
   301     // empty the lists.
       
   302     // the lists must stay valid for use
       
   303 
       
   304     // iCreated and iUpdated are collection from currentlist. Do not delete items.
       
   305     // iDeleted is only place for items. Delete those.
       
   306 
       
   307     iCreated->Reset();
       
   308     iUpdated->Reset();
       
   309     iDeleted->Close();
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CGroupListSubscriptionItem::CleanExpired()
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 void CGroupListSubscriptionItem::CleanExpired()
       
   317     {
       
   318 
       
   319     }
       
   320 // End of file