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