multimediacommscontroller/mmcccontroller/src/mccresourceiterators.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mccresourceiterators.h"
       
    22 #include "mccresourcecontainer.h"
       
    23 #include "mccresourceitem.h"
       
    24 #include <mmf/server/mmfdatasink.h>
       
    25 #include <mmf/server/mmfdatasource.h>
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 
       
    30 // CONTAINER ITERATOR
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // TMccResourceContainerIterator::TMccResourceContainerIterator
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 TMccResourceContainerIterator::TMccResourceContainerIterator( 
       
    37     const RPointerArray<CMccResourceContainer>& aContainers ) : 
       
    38     iContainers( aContainers ),
       
    39     iCurrentIndex( 0 ),
       
    40     iResourceParams( NULL ),
       
    41     iEndpointId( 0 )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // TMccResourceContainerIterator::TMccResourceContainerIterator
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 TMccResourceContainerIterator::TMccResourceContainerIterator( 
       
    50     const RPointerArray<CMccResourceContainer>& aContainers,
       
    51     TMccResourceParams& aResourceParams ) : 
       
    52     iContainers( aContainers ),
       
    53     iCurrentIndex( 0 ),
       
    54     iResourceParams( &aResourceParams ),
       
    55     iEndpointId( 0 )
       
    56     {
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // TMccResourceContainerIterator::TMccResourceContainerIterator
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TMccResourceContainerIterator::TMccResourceContainerIterator( 
       
    64     const RPointerArray<CMccResourceContainer>& aContainers,
       
    65     TUint32 aEndpointId ) : 
       
    66     iContainers( aContainers ),
       
    67     iCurrentIndex( 0 ),
       
    68     iResourceParams( NULL ),
       
    69     iEndpointId( aEndpointId )
       
    70     {
       
    71     }
       
    72     
       
    73 // -----------------------------------------------------------------------------
       
    74 // TMccResourceContainerIterator::Current
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TInt TMccResourceContainerIterator::Current()
       
    78     {
       
    79     TInt current = KErrNotFound;
       
    80     
       
    81     if ( iContainers.Count() > 0 )
       
    82         {
       
    83         current = iCurrentIndex-1;
       
    84         current = current < 0 ? 0 : current;
       
    85         }
       
    86     return current;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // TMccResourceContainerIterator::IsEof
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TBool TMccResourceContainerIterator::IsEof()
       
    94     {
       
    95     return iContainers.Count() == 0 || iCurrentIndex >= iContainers.Count();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // TMccResourceContainerIterator::Next
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TBool TMccResourceContainerIterator::Next( 
       
   103     CMccResourceContainer*& aCandidate,
       
   104     TMccIteratorMatchType aMatchType )
       
   105     {
       
   106     CMccResourceContainer* next = NULL;
       
   107     TBool negation = aMatchType == ExactMatch ? EFalse : ETrue;
       
   108     
       
   109     while( !next && !IsEof() )
       
   110         {
       
   111         CMccResourceContainer* container = iContainers[ iCurrentIndex ];
       
   112         TBool condition = EFalse;
       
   113 
       
   114         if ( iResourceParams )
       
   115             {
       
   116             if ( iResourceParams->iLinkId )
       
   117                 {
       
   118                 condition = ( container->LinkId() == iResourceParams->iLinkId );
       
   119                 }
       
   120             else if ( iResourceParams->iStreamId )
       
   121                 {
       
   122                 condition = ( container->StreamId() == iResourceParams->iStreamId );
       
   123                 }
       
   124             else if ( iEndpointId )
       
   125                 {
       
   126                 condition = ( container->FindResourceItem( iEndpointId ) != NULL );
       
   127                 }
       
   128             else
       
   129                 {
       
   130                 }
       
   131             }
       
   132         else
       
   133             {
       
   134             condition = ETrue;
       
   135             }
       
   136             
       
   137         next = ( ( negation && !condition ) ||
       
   138                ( !negation && condition ) ) ? container : NULL;
       
   139                
       
   140         iCurrentIndex++;                            
       
   141         }
       
   142     
       
   143     aCandidate = next;
       
   144     return aCandidate != NULL;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // TMccResourceContainerIterator::Delete
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 TInt TMccResourceContainerIterator::Delete( RPointerArray<CMccResourceContainer>& aContainers )
       
   152     {
       
   153     TInt currentIndex = Current();
       
   154     
       
   155     if ( currentIndex != KErrNotFound && currentIndex < aContainers.Count() )
       
   156         {
       
   157         delete aContainers[ currentIndex ];
       
   158         aContainers.Remove( currentIndex );
       
   159         iCurrentIndex = currentIndex;
       
   160         }
       
   161     
       
   162     return currentIndex;
       
   163     }
       
   164     
       
   165 // -----------------------------------------------------------------------------
       
   166 // TMccResourceContainerIterator::Reset
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void TMccResourceContainerIterator::Reset()
       
   170     {
       
   171     iCurrentIndex = 0;
       
   172     }
       
   173 
       
   174 
       
   175 // RESOURCE ITEM ITERATOR
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // TMccResourceItemIterator::TMccResourceItemIterator
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TMccResourceItemIterator::TMccResourceItemIterator( 
       
   182     const RPointerArray<CMccResourceItem>& aItems,
       
   183     TBool aOnlyInternals,
       
   184     TBool aOnlySinks,
       
   185     TBool aOnlySources ) : 
       
   186     iItems( aItems ),
       
   187     iCurrentIndex( 0 ),
       
   188     iOnlyInternals( aOnlyInternals ),
       
   189     iOnlySinks( aOnlySinks ),
       
   190     iOnlySources( aOnlySources ),
       
   191     iUid( KNullUid ),
       
   192     iResourceParams( NULL ),
       
   193     iEndpointId( 0 )
       
   194     {
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // TMccResourceItemIterator::TMccResourceItemIterator
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TMccResourceItemIterator::TMccResourceItemIterator( 
       
   202     const RPointerArray<CMccResourceItem>& aItems, 
       
   203     TUid aUid ) : 
       
   204     iItems( aItems ),
       
   205     iCurrentIndex( 0 ),
       
   206     iOnlyInternals( EFalse ),
       
   207     iOnlySinks( EFalse ),
       
   208     iOnlySources( EFalse ),
       
   209     iUid( aUid ),
       
   210     iResourceParams( NULL ),
       
   211     iEndpointId( 0 )
       
   212     {
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // TMccResourceItemIterator::TMccResourceItemIterator
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 TMccResourceItemIterator::TMccResourceItemIterator( 
       
   220     const RPointerArray<CMccResourceItem>& aItems,
       
   221     TUid aUid,
       
   222     TMccResourceParams& aResourceParams ) :
       
   223     iItems( aItems ),
       
   224     iCurrentIndex( 0 ),
       
   225     iOnlyInternals( EFalse ),
       
   226     iOnlySinks( EFalse ),
       
   227     iOnlySources( EFalse ),
       
   228     iUid( aUid ),
       
   229     iResourceParams( &aResourceParams ),
       
   230     iEndpointId( 0 )    
       
   231     {
       
   232     }
       
   233     
       
   234 // -----------------------------------------------------------------------------
       
   235 // TMccResourceItemIterator::TMccResourceItemIterator
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TMccResourceItemIterator::TMccResourceItemIterator( 
       
   239     const RPointerArray<CMccResourceItem>& aItems,
       
   240     TMccResourceParams& aResourceParams ) : 
       
   241     iItems( aItems ),
       
   242     iCurrentIndex( 0 ),
       
   243     iOnlyInternals( EFalse ),
       
   244     iOnlySinks( EFalse ),
       
   245     iOnlySources( EFalse ),
       
   246     iUid( KNullUid ),
       
   247     iResourceParams( &aResourceParams ),
       
   248     iEndpointId( 0 )
       
   249     {
       
   250     }
       
   251     
       
   252 // -----------------------------------------------------------------------------
       
   253 // TMccResourceItemIterator::TMccResourceItemIterator
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TMccResourceItemIterator::TMccResourceItemIterator( 
       
   257     const RPointerArray<CMccResourceItem>& aItems,
       
   258     TUint32 aEndpointId ) : 
       
   259     iItems( aItems ),
       
   260     iCurrentIndex( 0 ),
       
   261     iOnlyInternals( EFalse ),
       
   262     iOnlySinks( EFalse ),
       
   263     iOnlySources( EFalse ),
       
   264     iUid( KNullUid ),
       
   265     iResourceParams(NULL ),
       
   266     iEndpointId( aEndpointId )
       
   267     {
       
   268     }
       
   269        
       
   270 // -----------------------------------------------------------------------------
       
   271 // TMccResourceItemIterator::Current
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 TInt TMccResourceItemIterator::Current()
       
   275     {
       
   276     TInt current = KErrNotFound;
       
   277     
       
   278     if ( iItems.Count() > 0 )
       
   279         {
       
   280         current = iCurrentIndex-1;
       
   281         current = current < 0 ? 0 : current;
       
   282         }
       
   283     return current;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // TMccResourceItemIterator::IsEof
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 TBool TMccResourceItemIterator::IsEof()
       
   291     {
       
   292     return iItems.Count() == 0 || iCurrentIndex >= iItems.Count();
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // TMccResourceItemIterator::Next
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 TBool TMccResourceItemIterator::Next( 
       
   300     CMccResourceItem*& aCandidate,
       
   301     TMccIteratorMatchType aMatchType )
       
   302     {
       
   303     CMccResourceItem* next = NULL;
       
   304     TBool negation = aMatchType == ExactMatch ? EFalse : ETrue;
       
   305     
       
   306     while( !next && !IsEof() )
       
   307         {
       
   308         CMccResourceItem* item = iItems[ iCurrentIndex ];
       
   309         TBool condition = EFalse;
       
   310         
       
   311         if ( iUid != KNullUid )
       
   312             {
       
   313             condition = ( item->IsSink() && item->Sink()->DataSinkType() == iUid ) ||
       
   314                         ( item->IsSource() && item->Source()->DataSourceType() == iUid );
       
   315             if ( condition && iResourceParams )
       
   316                 {
       
   317                 condition = item->MatchSession( iResourceParams->iSessionId );
       
   318                 }
       
   319             }
       
   320         else if ( iResourceParams )
       
   321             {
       
   322             condition = item->Match( *iResourceParams );
       
   323             }
       
   324         else if ( iEndpointId )
       
   325             {
       
   326             condition = iEndpointId == item->EndpointId();
       
   327             }
       
   328         else
       
   329             {
       
   330             condition = ( !iOnlySinks || item->IsSink() ) &&
       
   331                         ( !iOnlySources || item->IsSource() ) &&
       
   332                         ( !iOnlyInternals || item->IsInternal() );
       
   333             }
       
   334             
       
   335         next = ( ( negation && !condition ) ||
       
   336                ( !negation && condition ) ) ? item : NULL;
       
   337                
       
   338         iCurrentIndex++;                            
       
   339         }
       
   340     
       
   341     aCandidate = next;
       
   342     return aCandidate != NULL;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // TMccResourceItemIterator::Reset
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void TMccResourceItemIterator::Reset()
       
   350     {
       
   351     iCurrentIndex = 0;
       
   352     }
       
   353       
       
   354 // End of file
       
   355