contentstorage/srvsrc/casrvnotifier.cpp
branchRCL_3
changeset 113 0efa10d348c0
equal deleted inserted replaced
111:053c6c7c14f3 113:0efa10d348c0
       
     1 /*
       
     2  * Copyright (c) 2008 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:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include <badesca.h>
       
    19 #include "casrvnotifier.h"
       
    20 #include "cainnernotifierfilter.h"
       
    21 #include "cainnerentry.h"
       
    22 #include "casrvdef.h"
       
    23 #include "cautils.h"
       
    24 #include "caarraycleanup.inl"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // 
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CCaSrvNotifier::~CCaSrvNotifier()
       
    34     {
       
    35     Complete( KErrCancel );
       
    36     iBufArrayInfo.ResetAndDestroy();
       
    37     iArrayChangeType.Close();
       
    38     delete iFilter;
       
    39     }
       
    40 
       
    41 #ifdef COVERAGE_MEASUREMENT
       
    42 #pragma CTC SKIP
       
    43 #endif //COVERAGE_MEASUREMENT (only NewLC used in code)
       
    44 // -----------------------------------------------------------------------------
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CCaSrvNotifier* CCaSrvNotifier::NewL()
       
    49     {
       
    50     CCaSrvNotifier* self = CCaSrvNotifier::NewLC();
       
    51     CleanupStack::Pop();
       
    52     return self;
       
    53     }
       
    54 #ifdef COVERAGE_MEASUREMENT
       
    55 #pragma CTC ENDSKIP
       
    56 #endif //COVERAGE_MEASUREMENT
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CCaSrvNotifier* CCaSrvNotifier::NewLC()
       
    63     {
       
    64     CCaSrvNotifier* self = new ( ELeave ) CCaSrvNotifier();
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // 
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CCaSrvNotifier::CCaSrvNotifier()
       
    75     {
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CCaSrvNotifier::ConstructL()
       
    83     {
       
    84     iFilter = CCaInnerNotifierFilter::NewL(
       
    85             CCaInnerNotifierFilter::EEntryChangedWithId );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CCaSrvNotifier::NotifyL( const RMessage2& aMessage )
       
    93     {
       
    94     PanicIfPendingL( aMessage );
       
    95     SetPendingL( aMessage ); // No leaving after this!
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // 
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CCaSrvNotifier::Cancel()
       
   104     {
       
   105     Complete( KErrCancel );
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // 
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CCaSrvNotifier::SetPendingL( const RMessage2 &aMessage )
       
   113     {
       
   114     __ASSERT_DEBUG( !iPending, User::Invariant() );
       
   115     iMessage = aMessage;
       
   116     iPending = ETrue;
       
   117     if( iBufArrayInfo.Count() > 0 )
       
   118         {
       
   119         Complete();
       
   120         }
       
   121     else
       
   122         {
       
   123         MenuUtils::InternalizeObjectL( aMessage, *iFilter );
       
   124         }
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CCaSrvNotifier::PanicIfPendingL( const RMessage2& aMessage )
       
   132     {
       
   133     if( iPending )
       
   134         {
       
   135         // Another message is already being served.
       
   136         aMessage.Panic( KCaSrvName, KErrInUse );
       
   137         User::Leave( KErrInUse );
       
   138         }
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // 
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CCaSrvNotifier::Complete( TInt aReason )
       
   146     {
       
   147     if( iPending )
       
   148         {
       
   149         if( aReason != KErrNone )
       
   150             {
       
   151             iMessage.Complete( aReason );
       
   152             iBufArrayInfo.ResetAndDestroy();
       
   153             iArrayChangeType.Close();
       
   154             }
       
   155         else
       
   156             {
       
   157             if( iBufArrayInfo.Count() > 0 )
       
   158                 {
       
   159                 TPckgBuf<TInt> sizeDes( iBufArrayInfo[0]->Size() );
       
   160                 iMessage.Write( KOutputPosition, sizeDes );
       
   161                 }
       
   162             iMessage.Complete( KErrNone );
       
   163             }
       
   164         iPending = EFalse;
       
   165         }
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // 
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CCaSrvNotifier::EntryChangedL( const CCaInnerEntry* aEntry,
       
   173         TChangeType aChangeType, const RArray<TInt>& aParentIds )
       
   174     {
       
   175     if( iFilter && CheckFilterForEntry( aEntry, aParentIds ) )
       
   176         {
       
   177         if( iFilter->GetNotifierType()
       
   178                 == CCaInnerNotifierFilter::EEntryChangedWithEntry )
       
   179             {
       
   180             HBufC8* bufInfo = MenuUtils::MarshalDataL( 
       
   181                     *aEntry, KDefaultExpandSize );
       
   182             CleanupStack::PushL( bufInfo );
       
   183             iBufArrayInfo.AppendL( bufInfo );
       
   184             CleanupStack::Pop( bufInfo );
       
   185             iArrayChangeType.AppendL( aChangeType );
       
   186             Complete();
       
   187             }
       
   188         else if( iFilter->GetNotifierType()
       
   189                 == CCaInnerNotifierFilter::EEntryChangedWithId )
       
   190             {
       
   191             AddEntryWithIdL( aEntry->GetId() );
       
   192             iArrayChangeType.AppendL( aChangeType );
       
   193             Complete();
       
   194             }
       
   195         }
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // 
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CCaSrvNotifier::EntryTouchedL( TInt aId )
       
   203     {
       
   204     if( iFilter && iFilter->GetNotifierType()
       
   205             == CCaInnerNotifierFilter::EEntryTouched && CheckIds(
       
   206             iFilter->GetIds(), aId ) )
       
   207         {
       
   208         AddEntryWithIdL( aId );
       
   209         Complete();
       
   210         }
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // 
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CCaSrvNotifier::GroupContentChangedL( const RArray<TInt>& aParentIds )
       
   218     {
       
   219     if( iFilter && iFilter->GetNotifierType()
       
   220             == CCaInnerNotifierFilter::EGroupContentChanged )
       
   221         {
       
   222         if( iFilter->GetParentId() == 0 && aParentIds.Count() > 0 )
       
   223             {
       
   224             for( TInt i( 0 ); i < aParentIds.Count(); i++ )
       
   225                 {
       
   226                 AddEntryWithIdL( aParentIds[i] );
       
   227                 }
       
   228             Complete();
       
   229             }
       
   230         else if( aParentIds.Find( iFilter->GetParentId() ) != KErrNotFound )
       
   231             {
       
   232             AddEntryWithIdL( iFilter->GetParentId() );
       
   233             Complete();
       
   234             }
       
   235         }
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------
       
   239 // 
       
   240 // ---------------------------------------------------------
       
   241 //
       
   242 void CCaSrvNotifier::GetChangeInfoL( const RMessage2& aMessage )
       
   243     {
       
   244     if( iBufArrayInfo.Count() > 0 )
       
   245         {
       
   246         aMessage.WriteL( KInputPosition1, iBufArrayInfo[0]->Des() );
       
   247         if( iArrayChangeType.Count() > 0 )
       
   248             {
       
   249             TPckg<TChangeType> changeTypePckg( iArrayChangeType[0] );
       
   250             aMessage.WriteL( KInputPosition2, changeTypePckg );
       
   251             iArrayChangeType.Remove( 0 );
       
   252             }
       
   253         delete iBufArrayInfo[0];
       
   254         iBufArrayInfo.Remove( 0 );
       
   255         }
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // 
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TBool CCaSrvNotifier::CheckFilterForEntry( const CCaInnerEntry* aEntry,
       
   263         const RArray<TInt>& aParentIds )
       
   264     {
       
   265     TBool filterCorrect = CheckIds( iFilter->GetIds(), aEntry->GetId() );
       
   266     if( filterCorrect )
       
   267         {
       
   268         filterCorrect = ( static_cast<TUint> ( iFilter->GetEntryRole() )
       
   269                 == ENoneEntryRole
       
   270                 || static_cast<TUint> ( iFilter->GetEntryRole() )
       
   271                         == aEntry->GetRole() );
       
   272         }
       
   273     if( filterCorrect )
       
   274         {
       
   275         filterCorrect = CheckTypeName( iFilter->GetTypeNames(),
       
   276                 aEntry->GetEntryTypeName() );
       
   277         }
       
   278     if( filterCorrect && iFilter->GetParentId() > 0 )
       
   279         {
       
   280         filterCorrect = ( iFilter->GetParentId() == aEntry->GetId()
       
   281                 || aParentIds.Find( iFilter->GetParentId() )
       
   282                         != KErrNotFound );
       
   283         }
       
   284     return filterCorrect;
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // 
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CCaSrvNotifier::AddEntryWithIdL( TInt aId )
       
   292     {
       
   293     CCaInnerEntry* entry = CCaInnerEntry::NewLC();
       
   294     entry->SetId( aId );
       
   295     HBufC8* bufInfo = MenuUtils::MarshalDataL( *entry, KDefaultExpandSize );
       
   296     CleanupStack::PushL( bufInfo );
       
   297     iBufArrayInfo.AppendL( bufInfo );
       
   298     CleanupStack::Pop( bufInfo );
       
   299     CleanupStack::PopAndDestroy( entry );
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // 
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 TBool CCaSrvNotifier::CheckIds( const RArray<TInt>& aIds, TInt aId )
       
   307     {
       
   308     TBool result( ETrue );
       
   309     if( aIds.Count() > 0 && aIds.Find( aId ) == KErrNotFound )
       
   310         {
       
   311         result = EFalse;
       
   312         }
       
   313     return result;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // 
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 TBool CCaSrvNotifier::CheckTypeName( const CDesC16ArrayFlat* aTypeNames,
       
   321         const RBuf& aTypeName )
       
   322     {
       
   323     TBool result( ETrue );
       
   324     TInt position( 0 );
       
   325     if( aTypeNames->Count() > 0 && aTypeNames->Find( aTypeName, position )
       
   326             != KErrNone )
       
   327         {
       
   328         result = EFalse;
       
   329         }
       
   330     return result;
       
   331     }
       
   332