mpx/commonframework/common/src/mpxsubscription.cpp
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     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:  MPX subscription class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <mpxlog.h>
       
    21 #include "mpxmediaarray.h"
       
    22 #include "mpxsubscriptiondefs.h"
       
    23 #include "mpxsubscription.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ==============================
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // CMPXSubscription::NewL
       
    29 // ----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CMPXSubscription* CMPXSubscription::NewL()
       
    32     {
       
    33     CMPXSubscription* self = static_cast<CMPXSubscription*>(CMPXMedia::NewL());
       
    34     CleanupStack::PushL(self);
       
    35     self->InitializeL();
       
    36     CleanupStack::Pop(self); 
       
    37     return self; 
       
    38     }
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CMPXSubscription::NewL
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CMPXSubscription* CMPXSubscription::NewL(
       
    45     CMPXMediaArray& aMediaArray)
       
    46     {
       
    47     CMPXSubscription* self = static_cast<CMPXSubscription*>(CMPXMedia::NewL());
       
    48     CleanupStack::PushL(self);
       
    49     self->InitializeL(aMediaArray);
       
    50     CleanupStack::Pop(self); 
       
    51     return self; 
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CMPXSubscription::AddItemL
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C void CMPXSubscription::AddItemL(
       
    59     const CMPXSubscriptionItem& aItem)
       
    60     {
       
    61     // append the subscription item to the media array
       
    62     CMPXMediaArray* items = Value<CMPXMediaArray>(KMPXSubscriptionItems);
       
    63     User::LeaveIfNull(items);
       
    64     items->AppendL(aItem);
       
    65     }
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CMPXSubscription::Items
       
    69 // ----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C const CMPXMediaArray* CMPXSubscription::ItemsL() const
       
    72     {
       
    73     MPX_ASSERT(IsSupported(KMPXSubscriptionItems));
       
    74     CMPXMediaArray* array = Value<CMPXMediaArray>(KMPXSubscriptionItems);
       
    75     User::LeaveIfNull(array);
       
    76     return array;
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // CMPXSubscription::operator==
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C TBool CMPXSubscription::operator==(
       
    84     const CMPXSubscription& aSubscription) const
       
    85     {
       
    86     TBool match(ETrue);
       
    87  
       
    88     const CMPXMediaArray* array1 = aSubscription.ItemsL();
       
    89     const CMPXMediaArray* array2 = ItemsL();
       
    90 
       
    91     TInt count(array1->Count());
       
    92     if (count != array2->Count())
       
    93         {
       
    94         match = EFalse;
       
    95         }
       
    96     else
       
    97         {
       
    98         for (TInt index = 0; (index < count) && match; ++index)
       
    99             {
       
   100             CMPXSubscriptionItem* subItem1( array1->AtL(index) );
       
   101             CMPXSubscriptionItem* subItem2( array2->AtL(index) );
       
   102  
       
   103             TInt attrCount(subItem1->Count());
       
   104             if (attrCount != subItem2->Count())
       
   105                 {
       
   106                 match = EFalse;
       
   107                 break;
       
   108                 }
       
   109  
       
   110             for (TInt attrIndex = 0; attrIndex < attrCount; ++attrIndex) 
       
   111                 {
       
   112                 const TMPXAttribute& attr( subItem1->Attribute( attrIndex ));
       
   113                 if ( !subItem1->Match( *subItem2, attr ) )
       
   114                     {
       
   115                     match = EFalse;
       
   116                     break;
       
   117                     }
       
   118                 }
       
   119             }
       
   120         }
       
   121  
       
   122     return match; 
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CMPXSubscription::InitializeL
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 void CMPXSubscription::InitializeL()
       
   130     {
       
   131     // create an empty subscription item array
       
   132     CMPXMediaArray* dummy = CMPXMediaArray::NewL();
       
   133     CleanupStack::PushL(dummy); 
       
   134     SetCObjectValueL(KMPXSubscriptionItems, dummy); 
       
   135     CleanupStack::PopAndDestroy(dummy);
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CMPXSubscription::InitializeL
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void CMPXSubscription::InitializeL(
       
   143     CMPXMediaArray& aMediaArray)
       
   144     {
       
   145     SetCObjectValueL(KMPXSubscriptionItems, &aMediaArray); 
       
   146     }
       
   147 
       
   148 // ----------------------------------------------------------------------------
       
   149 // CMPXSubscription::DebugPrint
       
   150 // ----------------------------------------------------------------------------
       
   151 //
       
   152 void CMPXSubscription::DebugPrint() const
       
   153     {
       
   154     const CMPXMediaArray* array(NULL);
       
   155     TRAPD(err,  array = ItemsL());
       
   156     if (KErrNone == err)
       
   157         {
       
   158         MPX_ASSERT(array);
       
   159         TInt count(array->Count());
       
   160         for (TInt index = 0; index < count; ++index)
       
   161             {
       
   162             CMPXSubscriptionItem* subItem = (*array)[index];
       
   163             if (subItem)
       
   164                 {
       
   165                 TInt attrCount(subItem->Count());
       
   166  
       
   167                 for (TInt attrIndex = 0; attrIndex < attrCount; ++attrIndex)
       
   168                     {
       
   169                     const TMPXAttribute& attr = subItem->Attribute(attrIndex);
       
   170                     MPX_DEBUG3("Attr: %x, %x", attr.ContentId(), attr.AttributeId());
       
   171                     }
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 break;
       
   176                 }
       
   177             }
       
   178         }
       
   179     }
       
   180 
       
   181 // End of File