PECengine/ListLibrary2/ContactListSrc/CPEngContactListModChangeMonitor.cpp
branchRCL_3
changeset 17 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
16:6ca72c0fe49a 17:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Monitors contact list changes.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "PEngContactIdsTools.h"
       
    20 #include "CPEngContactListModChangeMonitor.h"
       
    21 #include "MPEngContactListModStore.h"
       
    22 #include "PEngListLibraryPanics.h"
       
    23 #include <s32strm.h>
       
    24 #include <e32std.h>
       
    25 
       
    26 
       
    27 // ============================= LOCAL FUNCTIONS ==============================
       
    28 /**
       
    29  * Helper to grow RBuf buffer if needed.
       
    30  */
       
    31 void GrowBufferIfRequiredL( RBuf& aBuffer, TInt aRequiredLength )
       
    32     {
       
    33     if ( aRequiredLength > aBuffer.MaxLength() )
       
    34         {
       
    35         aBuffer.ReAllocL( aRequiredLength );
       
    36         }
       
    37 
       
    38     aBuffer.Zero();
       
    39     }
       
    40 
       
    41 
       
    42 //Default granurality for change monitor arrays
       
    43 const TInt KChangeMonitorGranurality = 5;
       
    44 
       
    45 //Byte size needed to stream TInt type data => 4 bytes
       
    46 const TInt KIntStreamBytes = 4;
       
    47 
       
    48 
       
    49 
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CPEngContactListModChangeMonitor::CPEngContactListModChangeMonitor()
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CPEngContactListModChangeMonitor::CPEngContactListModChangeMonitor(
       
    58     MPEngContactListModStore& aStoreEntry )
       
    59         : iAddedContactIds( KChangeMonitorGranurality ),
       
    60         iRemovedContactIds( KChangeMonitorGranurality ),
       
    61         iStoreEntry( aStoreEntry )
       
    62     {
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CPEngContactListModChangeMonitor::NewL()
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CPEngContactListModChangeMonitor* CPEngContactListModChangeMonitor::NewL(
       
    71     MPEngContactListModStore& aStoreEntry  )
       
    72     {
       
    73     CPEngContactListModChangeMonitor* self =
       
    74         new ( ELeave ) CPEngContactListModChangeMonitor( aStoreEntry );
       
    75     return self;
       
    76     }
       
    77 
       
    78 
       
    79 
       
    80 // Destructor
       
    81 CPEngContactListModChangeMonitor::~CPEngContactListModChangeMonitor()
       
    82 
       
    83     {
       
    84     iAddedContactIds.Reset();
       
    85     iRemovedContactIds.Reset();
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPEngContactListModChangeMonitor::AddedContactIds()
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 const MDesCArray& CPEngContactListModChangeMonitor::AddedContactIds() const
       
    94     {
       
    95     return iAddedContactIds;
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CPEngContactListModChangeMonitor::RemovedContactIds()
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 const MDesCArray& CPEngContactListModChangeMonitor::RemovedContactIds() const
       
   104     {
       
   105     return iRemovedContactIds;
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CPEngContactListModChangeMonitor::CountAddedContactIds()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TInt CPEngContactListModChangeMonitor::CountAddedContactIds() const
       
   114     {
       
   115     return iAddedContactIds.Count();
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CPEngContactListModChangeMonitor::CountRemovedContactIds()
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TInt CPEngContactListModChangeMonitor::CountRemovedContactIds() const
       
   124     {
       
   125     return iRemovedContactIds.Count();
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CPEngContactListModChangeMonitor::FindContactIdInAdded()
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TInt CPEngContactListModChangeMonitor::FindContactIdInAdded(
       
   134     const TDesC& aContactId,
       
   135     const TDesC& aUserDomain ) const
       
   136     {
       
   137     return NContactIdsTools::FindContactIdInArray( iAddedContactIds,
       
   138                                                    aContactId,
       
   139                                                    aUserDomain );
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPEngContactListModChangeMonitor::FindContactIdInRemoved()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TInt CPEngContactListModChangeMonitor::FindContactIdInRemoved(
       
   148     const TDesC& aContactId,
       
   149     const TDesC& aUserDomain ) const
       
   150     {
       
   151     return NContactIdsTools::FindContactIdInArray( iRemovedContactIds,
       
   152                                                    aContactId,
       
   153                                                    aUserDomain );
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPEngContactListModChangeMonitor::ExternalizeL()
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CPEngContactListModChangeMonitor::ExternalizeArrayL(
       
   162     RWriteStream& aStream ) const
       
   163     {
       
   164     // first list of added WV IDs
       
   165     TInt count( iAddedContactIds.MdcaCount() );
       
   166     aStream.WriteInt32L( count );
       
   167     for ( TInt i( 0 ); i < count; i++ )
       
   168         {
       
   169         aStream.WriteInt32L( iAddedContactIds.MdcaPoint( i ).Length() );
       
   170         aStream.WriteL( iAddedContactIds.MdcaPoint( i ) );
       
   171         }
       
   172 
       
   173 
       
   174     // now store removed WV IDs
       
   175     count = iRemovedContactIds.Count();
       
   176     aStream.WriteInt32L( count );
       
   177     for ( TInt ii( 0 ) ; ii < count ; ii++ )
       
   178         {
       
   179         aStream.WriteInt32L( iRemovedContactIds.MdcaPoint( ii ).Length() );
       
   180         aStream.WriteL( iRemovedContactIds.MdcaPoint( ii ) );
       
   181         }
       
   182     }
       
   183 
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CPEngContactListModChangeMonitor::InternalizeL()
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CPEngContactListModChangeMonitor::InternalizeArrayL(
       
   190     RReadStream& aStream )
       
   191     {
       
   192     iAddedContactIds.Reset();
       
   193     iRemovedContactIds.Reset();
       
   194     TInt& storeSize = iStoreEntry.StoreSizeCount();
       
   195     storeSize += KIntStreamBytes * 2 ; // two counts of the arrays
       
   196 
       
   197 
       
   198     RBuf buffer;
       
   199     buffer.CleanupClosePushL();
       
   200 
       
   201 
       
   202     // internalize array of Added WV IDs
       
   203     TInt count ( aStream.ReadInt32L() );
       
   204     for ( TInt x ( 0 ); x < count; x++ )
       
   205         {
       
   206         TInt size = aStream.ReadInt32L();
       
   207         GrowBufferIfRequiredL( buffer, size );
       
   208         aStream.ReadL( buffer, size );
       
   209 
       
   210         // array was stored in order
       
   211         iAddedContactIds.AppendL( buffer );
       
   212         storeSize += size + KIntStreamBytes; // length
       
   213         }
       
   214 
       
   215 
       
   216     // internalize array of Added WV IDs
       
   217     count = aStream.ReadInt32L();
       
   218     for ( TInt y( 0 ) ; y < count; y++ )
       
   219         {
       
   220         TInt size = aStream.ReadInt32L();
       
   221         GrowBufferIfRequiredL( buffer, size );
       
   222         aStream.ReadL( buffer, size );
       
   223 
       
   224         iRemovedContactIds.AppendL( buffer );
       
   225         storeSize += size + KIntStreamBytes; // length
       
   226         }
       
   227 
       
   228 
       
   229     CleanupStack::PopAndDestroy(); // buffer
       
   230     }
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CPEngContactListModChangeMonitor::InsertAddedContactIdL()
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 TInt CPEngContactListModChangeMonitor::InsertAddedContactIdL(
       
   238     const TDesC& aContactId )
       
   239     {
       
   240     RemoveRemovedContactId( aContactId );
       
   241 
       
   242     // insert WV ID into the array
       
   243     TInt position( NContactIdsTools::AddContactIdToArrayL( iAddedContactIds,
       
   244                                                            aContactId ) );
       
   245 
       
   246     // was WV already existing
       
   247     if ( position == KErrAlreadyExists )
       
   248         {
       
   249         return NContactIdsTools::FindContactIdInArray( iAddedContactIds,
       
   250                                                        aContactId );
       
   251         }
       
   252     else
       
   253         {
       
   254         // added successfully
       
   255         TInt& entrySize = iStoreEntry.StoreSizeCount();
       
   256         entrySize += aContactId.Size() + KIntStreamBytes; // length
       
   257         return position;
       
   258         }
       
   259     }
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CPEngContactListModChangeMonitor::RemoveAddedContactId()
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CPEngContactListModChangeMonitor::RemoveAddedContactId(
       
   267     const TDesC& aContactId )
       
   268     {
       
   269     TInt err = NContactIdsTools::RemoveContactIdFromArray( iAddedContactIds,
       
   270                                                            aContactId );
       
   271     if ( err == KErrNone )
       
   272         {
       
   273         TInt& entrySize = iStoreEntry.StoreSizeCount();
       
   274         entrySize -= aContactId.Size() - KIntStreamBytes; // length
       
   275         }
       
   276     }
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CPEngContactListModChangeMonitor::ResetAddedContactId()
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CPEngContactListModChangeMonitor::ResetAddedContactId()
       
   284     {
       
   285     iAddedContactIds.Reset();
       
   286     }
       
   287 
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CPEngContactListModChangeMonitor::InsertRemovedContactIdL()
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TInt CPEngContactListModChangeMonitor::InsertRemovedContactIdL(
       
   294     const TDesC& aContactId )
       
   295     {
       
   296     RemoveAddedContactId( aContactId );
       
   297 
       
   298     // insert WV ID into the array
       
   299     TInt position = NContactIdsTools::AddContactIdToArrayL( iRemovedContactIds,
       
   300                                                             aContactId );
       
   301     // was WV already existing
       
   302     if ( position == KErrAlreadyExists )
       
   303         {
       
   304         return NContactIdsTools::FindContactIdInArray( iRemovedContactIds,
       
   305                                                        aContactId );
       
   306         }
       
   307 
       
   308     else
       
   309         {
       
   310         // added successfully
       
   311         TInt& entrySize = iStoreEntry.StoreSizeCount();
       
   312         entrySize += aContactId.Size() + KIntStreamBytes; // length
       
   313         return position;
       
   314         }
       
   315     }
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CPEngContactListModChangeMonitor::RemoveRemovedContactId()
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CPEngContactListModChangeMonitor::RemoveRemovedContactId(
       
   323     const TDesC& aContactId )
       
   324     {
       
   325     TInt err = NContactIdsTools::RemoveContactIdFromArray( iRemovedContactIds,
       
   326                                                            aContactId );
       
   327     if ( err == KErrNone )
       
   328         {
       
   329         TInt& entrySize = iStoreEntry.StoreSizeCount();
       
   330         entrySize -= aContactId.Size() - KIntStreamBytes;// length
       
   331         }
       
   332     }
       
   333 
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CPEngContactListModChangeMonitor::ResetRemovedContactIds()
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void CPEngContactListModChangeMonitor::ResetRemovedContactIds()
       
   340     {
       
   341     iRemovedContactIds.Reset();
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CPEngContactListModChangeMonitor::Reset()
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CPEngContactListModChangeMonitor::Reset()
       
   350     {
       
   351     iAddedContactIds.Reset();
       
   352     iRemovedContactIds.Reset();
       
   353     }
       
   354 
       
   355 
       
   356 //  End of File
       
   357 
       
   358 
       
   359 
       
   360 
       
   361 
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 
       
   367 
       
   368 
       
   369 
       
   370 
       
   371 
       
   372 
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 
       
   378