upnpharvester/common/cmlibrary/src/cmfillrule.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-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:      Capsulating fill rule
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <s32mem.h>
       
    26 #include "cmmediaserver.h"
       
    27 #include "cmfillrule.h"
       
    28 #include "cmrule.h"
       
    29 #include "msdebug.h"
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KArrayGranularity = 16;
       
    33 const TInt KArrayGranularityContainer = 8;
       
    34 
       
    35 // ======== LOCAL FUNCTIONS ========
       
    36 // ---------------------------------------------------------------------------
       
    37 // NewL
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CCmFillRule* CCmFillRule::NewL()
       
    41     {   
       
    42     CCmFillRule* self = CCmFillRule::NewLC();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46  
       
    47 // ---------------------------------------------------------------------------
       
    48 // NewLC
       
    49 // ---------------------------------------------------------------------------
       
    50 //    
       
    51 EXPORT_C CCmFillRule* CCmFillRule::NewLC()
       
    52     {    
       
    53     CCmFillRule* self = new ( ELeave ) CCmFillRule();
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;  
       
    57     }    
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Destructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CCmFillRule::~CCmFillRule()
       
    64     {
       
    65     delete iName;
       
    66 
       
    67     iRuleArray.ResetAndDestroy();
       
    68     iRuleArray.Close();
       
    69     iMediaServerArray.ResetAndDestroy();
       
    70     iMediaServerArray.Close();
       
    71     
       
    72     iExcPlayLists->Reset();
       
    73     iExcAlbums->Reset();
       
    74             
       
    75     delete iExcPlayLists;
       
    76     delete iExcAlbums;             
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Add new rule into FillRule
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C TInt CCmFillRule::AddRuleL( TCmMetadataField aDataField, 
       
    84     TCmOperatorType aOperator )
       
    85     {
       
    86     CCmRule* rule = CCmRule::NewLC();
       
    87     rule->SetMetadataField(aDataField);
       
    88     rule->SetOperator(aOperator);
       
    89     iRuleArray.AppendL( rule ); // transfer ownership
       
    90     CleanupStack::Pop( rule );
       
    91     TInt index = iRuleArray.Count() - 1;    
       
    92     return index;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Get rule
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void CCmFillRule::RuleL( TInt aIndex, TCmMetadataField* aDataField, 
       
   100     TCmOperatorType* aOperator, TInt* aParamCount )
       
   101     {
       
   102     // check parameter
       
   103     if ( aIndex < 0 || aIndex >= iRuleArray.Count() ) 
       
   104         {
       
   105         User::Leave( KErrArgument );
       
   106         }
       
   107         
       
   108     iRuleArray[aIndex]->Rule( aDataField, aOperator, aParamCount );
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Delete rule
       
   113 // ---------------------------------------------------------------------------
       
   114 //    
       
   115 EXPORT_C void CCmFillRule::DeleteRule( TCmMetadataField aDataField,
       
   116     TCmOperatorType aOper )
       
   117     {
       
   118     TCmMetadataField dataField; TCmOperatorType oper;
       
   119     TInt count;
       
   120     for( TInt i = 0; i < iRuleArray.Count(); i++ )
       
   121         {
       
   122         iRuleArray[i]->Rule( &dataField, &oper, &count );
       
   123         if( dataField == aDataField && oper == aOper )
       
   124             {
       
   125             delete iRuleArray[i];
       
   126             iRuleArray.Remove(i);
       
   127             iRuleArray.Compress();            
       
   128             }
       
   129         }
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // Delete rule
       
   134 // ---------------------------------------------------------------------------
       
   135 //    
       
   136 EXPORT_C void CCmFillRule::DeleteRule( TCmMetadataField aDataField )
       
   137     {
       
   138     TCmMetadataField dataField; TCmOperatorType oper;
       
   139     TInt count;
       
   140     for( TInt i = 0; i < iRuleArray.Count(); i++ )
       
   141         {
       
   142         iRuleArray[i]->Rule( &dataField, &oper, &count );
       
   143         if( dataField == aDataField )
       
   144             {
       
   145             delete iRuleArray[i];
       
   146             iRuleArray.Remove(i);
       
   147             iRuleArray.Compress();            
       
   148             }
       
   149         }
       
   150     }    
       
   151 // ---------------------------------------------------------------------------
       
   152 // Add new rule param into FillRule
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C TInt CCmFillRule::AddRuleParamL( TInt aIndex, const TDesC8& aParam )
       
   156     {
       
   157     // check parameter
       
   158     if ( aIndex < 0 || aIndex >= iRuleArray.Count() ) 
       
   159         {
       
   160         User::Leave( KErrArgument );
       
   161         }
       
   162         
       
   163     return iRuleArray[aIndex]->AddRuleParamL( aParam );
       
   164     }    
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Add new rule param into FillRule ( Indexed param )
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C TInt CCmFillRule::AddRuleParamL( TInt aIndex, TInt aParam )
       
   171     {
       
   172     // check parameter
       
   173     if ( aIndex < 0 || aIndex >= iRuleArray.Count() ) 
       
   174         {
       
   175         User::Leave( KErrArgument );
       
   176         }
       
   177         
       
   178     return iRuleArray[aIndex]->AddRuleParamL( aParam );
       
   179     } 
       
   180     
       
   181 // ---------------------------------------------------------------------------
       
   182 // Get rule param
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C void CCmFillRule::RuleParamL( TInt aRuleIndex, TInt aParamIndex, 
       
   186     TPtrC8* aParam )
       
   187     {
       
   188     // check parameter
       
   189     if ( aRuleIndex < 0 || aRuleIndex >= iRuleArray.Count() ) 
       
   190         {
       
   191         User::Leave( KErrArgument );
       
   192         }
       
   193         
       
   194     iRuleArray[aRuleIndex]->RuleParamL( aParamIndex, aParam );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // Get rule param
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C void CCmFillRule::RuleParamL( TInt aRuleIndex, TInt aParamIndex, 
       
   202     TInt& aParam )
       
   203     {
       
   204     // check parameter
       
   205     if ( aRuleIndex < 0 || aRuleIndex >= iRuleArray.Count() ) 
       
   206         {
       
   207         User::Leave( KErrArgument );
       
   208         }
       
   209         
       
   210     iRuleArray[aRuleIndex]->RuleParamL( aParamIndex, aParam );
       
   211     }
       
   212         
       
   213 // ---------------------------------------------------------------------------
       
   214 // Add new media server into FillRule
       
   215 // ---------------------------------------------------------------------------
       
   216 //    
       
   217 EXPORT_C TInt CCmFillRule::AddMediaServerL( const TDesC8& aUDN )
       
   218     {
       
   219     CCmMediaServer* server = CCmMediaServer::NewLC();
       
   220     server->SetUDNL( aUDN );
       
   221     iMediaServerArray.AppendL( server );
       
   222     TInt index = iMediaServerArray.Count() - 1;    
       
   223     CleanupStack::Pop(server);
       
   224     return index;        
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // Add new media server into FillRule
       
   229 // ---------------------------------------------------------------------------
       
   230 //    
       
   231 EXPORT_C TInt CCmFillRule::AddMediaServerL( TInt aDbId )
       
   232     {
       
   233     CCmMediaServer* server = CCmMediaServer::NewLC();
       
   234     server->SetDbId( aDbId );
       
   235     iMediaServerArray.AppendL( server );
       
   236     TInt index = iMediaServerArray.Count() - 1;    
       
   237     CleanupStack::Pop(server);
       
   238     return index;        
       
   239     }
       
   240     
       
   241 // ---------------------------------------------------------------------------
       
   242 // Delete media server from the fill rule
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C void CCmFillRule::DeleteMediaServer( const TDesC8& aUDN )
       
   246     {
       
   247     TBool deleted( EFalse );
       
   248     for( TInt i = 0; i < iMediaServerArray.Count() && !deleted; i++ )
       
   249         {
       
   250         if( KErrNone == iMediaServerArray[i]->MediaServer().Compare(aUDN) )
       
   251             {
       
   252             delete iMediaServerArray[i];
       
   253             iMediaServerArray.Remove(i);
       
   254             iMediaServerArray.Compress();
       
   255             deleted = ETrue;
       
   256             }
       
   257         }
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // Delete media server from the fill rule
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 EXPORT_C void CCmFillRule::DeleteMediaServer( TInt aDbId )
       
   265     {
       
   266     TBool deleted( EFalse );
       
   267     for( TInt i = 0; i < iMediaServerArray.Count() && !deleted; i++ )
       
   268         {
       
   269         if( iMediaServerArray[i]->DbId() == aDbId )
       
   270             {
       
   271             delete iMediaServerArray[i];
       
   272             iMediaServerArray.Remove(i);
       
   273             iMediaServerArray.Compress();
       
   274             deleted = ETrue;
       
   275             }
       
   276         }
       
   277     }
       
   278     
       
   279 // ---------------------------------------------------------------------------
       
   280 // Adds one album into excluded list
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C void CCmFillRule::AddExcAlbumL( const TDesC& aAlbum )
       
   284     {
       
   285     iExcAlbums->AppendL( aAlbum );
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // Adds one playlist into excluded list
       
   290 // ---------------------------------------------------------------------------
       
   291 //    
       
   292 EXPORT_C void CCmFillRule::AddExcPlayListL( const TDesC& aPlayList )
       
   293     {
       
   294     iExcPlayLists->AppendL( aPlayList );
       
   295     }    
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // Removes defined album from the excluded list
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 EXPORT_C void CCmFillRule::RemoveExcAlbum( const TDesC& aAlbum )
       
   302     {
       
   303     TInt pos( KErrNone );
       
   304     TInt err( iExcAlbums->Find( aAlbum, pos ) );
       
   305     if( err == KErrNone )
       
   306         {
       
   307         iExcAlbums->Delete( pos );
       
   308         }
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // Removes defined playlist from the excluded list
       
   313 // ---------------------------------------------------------------------------
       
   314 //    
       
   315 EXPORT_C void CCmFillRule::RemoveExcPlayList( const TDesC& aPlayList )
       
   316     {
       
   317     TInt pos( KErrNone );
       
   318     TInt err( iExcPlayLists->Find( aPlayList, pos ) );
       
   319     if( err == KErrNone )
       
   320         {
       
   321         iExcPlayLists->Delete( pos );
       
   322         }    
       
   323     }    
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // Returns excluded albums
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 EXPORT_C CDesCArray& CCmFillRule::ExcAlbums() const
       
   330     {
       
   331     return *iExcAlbums;
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // Returns excluded playlists
       
   336 // ---------------------------------------------------------------------------
       
   337 //    
       
   338 EXPORT_C CDesCArray& CCmFillRule::ExcPlayLists() const
       
   339     {
       
   340     return *iExcPlayLists;
       
   341     }
       
   342         
       
   343 // ---------------------------------------------------------------------------
       
   344 // Get media server
       
   345 // ---------------------------------------------------------------------------
       
   346 //    
       
   347 EXPORT_C const TDesC8& CCmFillRule::MediaServerL( TInt aIndex )
       
   348     {
       
   349     // check parameter
       
   350     if ( aIndex < 0 || aIndex >= iMediaServerArray.Count() ) 
       
   351         {
       
   352         User::Leave( KErrArgument );
       
   353         }
       
   354         
       
   355     return iMediaServerArray[aIndex]->MediaServer();
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // Get media server
       
   360 // ---------------------------------------------------------------------------
       
   361 //    
       
   362 EXPORT_C void CCmFillRule::MediaServerL( TInt aIndex, TInt& aServer )
       
   363     {
       
   364     // check parameter
       
   365     if ( aIndex < 0 || aIndex >= iMediaServerArray.Count() ) 
       
   366         {
       
   367         User::Leave( KErrArgument );
       
   368         }
       
   369         
       
   370     aServer = iMediaServerArray[aIndex]->DbId();
       
   371     }
       
   372         
       
   373 // ---------------------------------------------------------------------------
       
   374 // Returns count of rules
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C TInt CCmFillRule::RuleCount() const
       
   378     {
       
   379     return iRuleArray.Count();
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // Returns count of media servers
       
   384 // ---------------------------------------------------------------------------
       
   385 //    
       
   386 EXPORT_C TInt CCmFillRule::MediaServerCount() const
       
   387     {
       
   388     return iMediaServerArray.Count();
       
   389     }    
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // returns count of params ( in specific rule )
       
   393 // ---------------------------------------------------------------------------
       
   394 //
       
   395 EXPORT_C TInt CCmFillRule::ParamCountL( TInt aIndex ) const
       
   396     {
       
   397     // check parameter
       
   398     if ( aIndex < 0 || aIndex >= iRuleArray.Count() ) 
       
   399         {
       
   400         User::Leave( KErrArgument );
       
   401         }
       
   402         
       
   403     return iRuleArray[aIndex]->RuleParamsCount();
       
   404     }
       
   405     
       
   406 // ---------------------------------------------------------------------------
       
   407 // Sets FillRule name
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 EXPORT_C TInt CCmFillRule::SetNameL( const TDesC8& aName )
       
   411     {
       
   412     delete iName;
       
   413     iName = NULL;
       
   414     iName = aName.AllocL();
       
   415     return KErrNone;        
       
   416     }
       
   417     
       
   418 // ---------------------------------------------------------------------------
       
   419 // Get Name
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 EXPORT_C TDesC8& CCmFillRule::Name() const
       
   423     {
       
   424     return *iName;
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // Sets list id, when storing data into db this values isn't used as a 
       
   429 // db list id
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 EXPORT_C void CCmFillRule::SetListId( const TUint aId )
       
   433     {
       
   434     iId = aId;
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // Get list id
       
   439 // ---------------------------------------------------------------------------
       
   440 //    
       
   441 EXPORT_C TUint CCmFillRule::ListId() const
       
   442     {
       
   443     return iId;
       
   444     }
       
   445     
       
   446 // ---------------------------------------------------------------------------
       
   447 // Sets amount
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 EXPORT_C void CCmFillRule::SetAmount( TUint32 aAmount )
       
   451     {
       
   452     iAmount = aAmount;
       
   453     }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // Returns amount
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 EXPORT_C TUint32 CCmFillRule::Amount() const
       
   460     {
       
   461     return iAmount;
       
   462     }
       
   463         
       
   464 // ---------------------------------------------------------------------------
       
   465 // Sets limit type ( MB or pcs. )
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 EXPORT_C void CCmFillRule::SetLimitType( TCmLimitType aLimitType )
       
   469     {
       
   470     iLimitType = aLimitType;
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // Returns limit type
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 EXPORT_C TCmLimitType CCmFillRule::LimitType() const
       
   478     {
       
   479     return iLimitType;
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // Sets media type
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 EXPORT_C void CCmFillRule::SetMediaType( TCmMediaType aMediaType )
       
   487     {
       
   488     iMediaType = aMediaType;
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // Returns media type
       
   493 // ---------------------------------------------------------------------------
       
   494 //    
       
   495 EXPORT_C TCmMediaType CCmFillRule::MediaType() const
       
   496     {
       
   497     return iMediaType;
       
   498     }    
       
   499         
       
   500 // ---------------------------------------------------------------------------
       
   501 // Sets method ( random, newest, oldest etc. )
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 EXPORT_C void CCmFillRule::SetMethod( TCmFillMethod aMethod )
       
   505     {
       
   506     iMethod = aMethod;
       
   507     }
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 // Returns method
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 EXPORT_C TCmFillMethod CCmFillRule::Method() const
       
   514     {
       
   515     return iMethod;
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // Sets selected state
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 EXPORT_C void CCmFillRule::SetSelected( TCmFillRuleStatus aSelected )
       
   523     {
       
   524     iSelected = aSelected;
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // Returns method
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 EXPORT_C TCmFillRuleStatus CCmFillRule::Selected() const
       
   532     {
       
   533     return iSelected;
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // 
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 EXPORT_C void CCmFillRule::SetStatus( TCmListItemStatus aStatus )
       
   541     {
       
   542     iStatus = aStatus;
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 // 
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 EXPORT_C TCmListItemStatus CCmFillRule::Status() const
       
   550     {
       
   551     return iStatus;
       
   552     }
       
   553     
       
   554 // ---------------------------------------------------------------------------
       
   555 // Set priority
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 EXPORT_C void CCmFillRule::SetPriority( TUint8 aPriority )
       
   559     {
       
   560     iPriority = aPriority;
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // Returns priority
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 EXPORT_C TUint8 CCmFillRule::Priority() const
       
   568     {
       
   569     return iPriority;
       
   570     }    
       
   571     
       
   572 // ---------------------------------------------------------------------------
       
   573 // Set template id
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 EXPORT_C void CCmFillRule::SetTemplateId( TUint8 aTemplateId )
       
   577     {
       
   578     iTemplateId = aTemplateId;
       
   579     }
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // Returns template id
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 EXPORT_C TUint8 CCmFillRule::TemplateId() const
       
   586     {
       
   587     return iTemplateId;
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // Set list's real size in Bytes
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 EXPORT_C void CCmFillRule::SetListRealSizeInBytes( TUint32 aRealSize )
       
   595     {
       
   596     iRealSize = aRealSize;
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // Returns list's real size in Bytes
       
   601 // ---------------------------------------------------------------------------
       
   602 //
       
   603 EXPORT_C TUint32 CCmFillRule::ListRealSizeInBytes() const
       
   604     {
       
   605     return iRealSize;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // Set list's real size in pieces
       
   610 // ---------------------------------------------------------------------------
       
   611 //
       
   612 EXPORT_C void CCmFillRule::SetListRealCount( TUint32 aRealCount )
       
   613     {
       
   614     iRealCount = aRealCount;
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------------------------
       
   618 // Returns ist's real size in pieces
       
   619 // ---------------------------------------------------------------------------
       
   620 //
       
   621 EXPORT_C TUint32 CCmFillRule::ListRealCount() const
       
   622     {
       
   623     return iRealCount;
       
   624     }
       
   625                 
       
   626 // ---------------------------------------------------------------------------
       
   627 // CCmFillRule::ExternalizeL
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 void CCmFillRule::ExternalizeL( RWriteStream& aStream ) const
       
   631     {
       
   632     aStream.WriteInt32L( iName->Length() );
       
   633     if ( iName )
       
   634         {
       
   635         aStream << *iName;
       
   636         }
       
   637     else
       
   638         {
       
   639         aStream << KNullDesC8();
       
   640         }      
       
   641     aStream.WriteInt32L( iAmount );
       
   642     aStream.WriteInt32L( iRealSize );
       
   643     aStream.WriteInt32L( iRealCount );
       
   644     aStream.WriteInt16L( (TInt)iLimitType );
       
   645     aStream.WriteInt16L( (TInt)iMethod );
       
   646     aStream.WriteInt16L( (TInt)iMediaType );
       
   647     aStream.WriteInt16L((TInt)iSelected );
       
   648     aStream.WriteInt16L((TInt)iStatus );
       
   649     aStream.WriteInt8L(iPriority);
       
   650     aStream.WriteInt8L( iTemplateId );
       
   651     aStream.WriteInt32L( iId );
       
   652     
       
   653     aStream.WriteInt16L( iRuleArray.Count() );
       
   654     for ( TInt index(0); index < iRuleArray.Count(); index++ )
       
   655         {
       
   656         iRuleArray[index]->ExternalizeL( aStream );
       
   657         }
       
   658         
       
   659     aStream.WriteInt16L( iMediaServerArray.Count() );
       
   660     for ( TInt index(0); index < iMediaServerArray.Count(); index++ )
       
   661         {
       
   662         iMediaServerArray[index]->ExternalizeL( aStream );
       
   663         }
       
   664 
       
   665     aStream.WriteInt16L( iExcAlbums->Count() );
       
   666     for ( TInt index(0); index < iExcAlbums->Count(); index++ )
       
   667         {
       
   668         aStream.WriteInt32L( iExcAlbums[index].Length() );
       
   669         aStream << iExcAlbums->MdcaPoint(index);
       
   670         }
       
   671         
       
   672     aStream.WriteInt16L( iExcPlayLists->Count() );
       
   673     for ( TInt index(0); index < iExcPlayLists->Count(); index++ )
       
   674         {
       
   675         aStream.WriteInt32L( iExcPlayLists[index].Length() );
       
   676         aStream << iExcPlayLists->MdcaPoint(index);
       
   677         }             
       
   678     }
       
   679         
       
   680 // ---------------------------------------------------------------------------
       
   681 // CCmFillRule::InternalizeL
       
   682 // ---------------------------------------------------------------------------
       
   683 //
       
   684 void CCmFillRule::InternalizeL( RReadStream& aStream )
       
   685     {
       
   686     // Content
       
   687     delete iName;
       
   688     iName = NULL;
       
   689 
       
   690     TInt bufLength = aStream.ReadInt32L();    
       
   691     iName = HBufC8::NewL( aStream, bufLength );
       
   692     
       
   693     // cleanup
       
   694     iRuleArray.ResetAndDestroy();
       
   695     
       
   696     iAmount = aStream.ReadInt32L();
       
   697     iRealSize = aStream.ReadInt32L();
       
   698     iRealCount = aStream.ReadInt32L();
       
   699     iLimitType = (TCmLimitType)aStream.ReadInt16L();
       
   700     iMethod = (TCmFillMethod)aStream.ReadInt16L();
       
   701     iMediaType = (TCmMediaType)aStream.ReadInt16L();
       
   702     iSelected = (TCmFillRuleStatus)aStream.ReadInt16L();
       
   703     iStatus = (TCmListItemStatus)aStream.ReadInt16L();
       
   704     iPriority = (TUint8)aStream.ReadInt8L();
       
   705     iTemplateId = (TUint8)aStream.ReadInt8L();
       
   706     iId = (TUint)aStream.ReadInt32L();
       
   707     
       
   708     // rule count 
       
   709     TInt ruleCount = aStream.ReadInt16L();
       
   710     
       
   711     // Then internalize them from the stream one by one
       
   712     for (TInt index = 0; index < ruleCount; index++ )
       
   713         {
       
   714         CCmRule* newRule = CCmRule::NewLC();
       
   715         newRule->InternalizeL( aStream );   
       
   716         iRuleArray.AppendL( newRule );
       
   717         CleanupStack::Pop( newRule ); 
       
   718         newRule = NULL;
       
   719         }
       
   720         
       
   721     // cleanup
       
   722     iMediaServerArray.ResetAndDestroy();
       
   723     
       
   724     // media Server count
       
   725     TInt mediaServerCount = aStream.ReadInt16L();
       
   726     
       
   727     // Then internalize them from the stream one by one
       
   728     for (TInt index = 0; index < mediaServerCount; index++ )
       
   729         {
       
   730         CCmMediaServer* newServer = CCmMediaServer::NewLC();
       
   731         newServer->InternalizeL( aStream );     
       
   732         iMediaServerArray.AppendL( newServer );
       
   733         CleanupStack::Pop( newServer ); 
       
   734         newServer = NULL;
       
   735         }
       
   736         
       
   737     TInt excAlbumsCount( aStream.ReadInt16L() );
       
   738     bufLength = KErrNone;
       
   739     HBufC* temp = NULL;
       
   740     for ( TInt index(0); index < excAlbumsCount ; index++ )
       
   741         {
       
   742         bufLength = aStream.ReadInt32L();
       
   743         temp = HBufC::NewLC( aStream, bufLength );
       
   744         iExcAlbums->AppendL( *temp );
       
   745         CleanupStack::PopAndDestroy( temp );
       
   746         temp = NULL;
       
   747         }         
       
   748 
       
   749     TInt excPlayListCount( aStream.ReadInt16L() );
       
   750     bufLength = KErrNone;
       
   751     for ( TInt index(0); index < excPlayListCount ; index++ )
       
   752         {
       
   753         bufLength = aStream.ReadInt32L();
       
   754         temp = HBufC::NewLC( aStream, bufLength );
       
   755         iExcPlayLists->AppendL( *temp );
       
   756         CleanupStack::PopAndDestroy( temp );
       
   757         temp = NULL;
       
   758         }                         
       
   759     }
       
   760                 
       
   761 // ---------------------------------------------------------------------------
       
   762 // Default constructor
       
   763 // ---------------------------------------------------------------------------
       
   764 //    
       
   765 CCmFillRule::CCmFillRule() : 
       
   766     iRuleArray( KArrayGranularity ), 
       
   767     iMediaServerArray( KArrayGranularity )
       
   768     {
       
   769     }
       
   770 
       
   771 // ---------------------------------------------------------------------------
       
   772 // ConstructL
       
   773 // ---------------------------------------------------------------------------
       
   774 //    
       
   775 void CCmFillRule::ConstructL()
       
   776     {
       
   777     iExcAlbums = new ( ELeave ) CDesCArrayFlat( KArrayGranularityContainer );
       
   778     iExcPlayLists = 
       
   779         new ( ELeave ) CDesCArrayFlat( KArrayGranularityContainer );    
       
   780     }    
       
   781 
       
   782 // End of file