mmappfw_plat/mpx_common_api/inc/mpxmedia.inl
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Inline functions for media object
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // -----------------------------------------------------------------------------
       
    21 // The value for a specific attribute
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 template<typename T>
       
    25 inline T CMPXMedia::ValueTObjectL(const TMPXAttribute& aAttribute) const
       
    26     {
       
    27     TPckgBuf<T> v;
       
    28     TMPXAttributeType type = GetValue(aAttribute, v);
       
    29     ASSERT(type == EMPXTypeTObject || type == EMPXTypeTInt || type == EMPXTypeUnknown);
       
    30     return v();// creates empty object if none exists!
       
    31     }
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // The value for a specific attribute
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 template<typename C>
       
    38 inline C* CMPXMedia::ValueNoNewLCObjectL(const TMPXAttribute& aAttribute) const
       
    39     {
       
    40     ASSERT(iData&&iClientHandle);
       
    41     if (Type(aAttribute)==EMPXTypeError)
       
    42         return NULL;
       
    43     TInt i=iData->Index(iClientHandle,aAttribute);
       
    44     TPtrC8 data=iData->Value(iClientHandle,i);
       
    45     C* obj=NULL;
       
    46     TInt s=data.Size();
       
    47     if (s)
       
    48         {
       
    49         CBufBase* b=CBufFlat::NewL(s);
       
    50         CleanupStack::PushL(b);
       
    51         b->ResizeL(s);
       
    52         b->Write(0,data,s);
       
    53         ::CreateFromBufferL(*b,obj);
       
    54         CleanupStack::PopAndDestroy(b);
       
    55         }
       
    56     else
       
    57         {
       
    58         // This construction is not always possible (e.g. CDesCArray)
       
    59         // obj=new(ELeave)C;
       
    60         }
       
    61     return obj;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // The value for a specific attribute
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 template<typename C>
       
    69 inline C* CMPXMedia::ValueCObjectL(const TMPXAttribute& aAttribute) const
       
    70     {
       
    71     ASSERT(iData&&iClientHandle);
       
    72     if (Type(aAttribute)==EMPXTypeError)
       
    73         return NULL;
       
    74     TInt i=iData->Index(iClientHandle,aAttribute);
       
    75     TPtrC8 data=iData->Value(iClientHandle,i);
       
    76     return ValueL<C>(data);
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMPXMedia::ValueL
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 template<typename T>
       
    84 inline T* CMPXMedia::ValueL(const TDesC8& aData) const
       
    85     {
       
    86     T* obj=NULL;
       
    87     TInt s=aData.Size();
       
    88     if (s)
       
    89         {
       
    90         CBufBase* b=CBufFlat::NewL(s);
       
    91         CleanupStack::PushL(b);
       
    92         b->ResizeL(s);
       
    93         b->Write(0,aData,s);
       
    94         ::NewFromBufferL<T>(*b,obj);
       
    95         CleanupStack::PopAndDestroy(b);
       
    96         }
       
    97     return obj;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // The value for a specific attribute
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 template<typename T>
       
   105 inline T* CMPXMedia::Value(const TMPXAttribute& aAttribute) const
       
   106     {
       
   107     if (Type(aAttribute)==EMPXTypeError)
       
   108         return NULL;
       
   109     return (T*)ValuePtr(aAttribute);
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 //  Add a new attribute value to this object, or modifies existing
       
   114 //  value if already present
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 template<typename T>
       
   118 inline void CMPXMedia::SetTObjectValueL(const TMPXAttribute& aAttribute,T aValue)
       
   119     {
       
   120     TPtrC8 value((TUint8*)&aValue,sizeof(T));
       
   121     SetValueL(aAttribute,value,EMPXTypeTObject);
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // Add a new attribute value to this object, or modifies existing
       
   126 // value if already present
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 template<typename C>
       
   130 inline void CMPXMedia::SetNoNewLCObjectL(
       
   131     const TMPXAttribute& aAttribute,C* aValue)
       
   132     {
       
   133     SetCObjectValueL(aAttribute,aValue);
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // Add a new attribute value to this object, or modifies existing
       
   138 // value if already present
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 template<typename C>
       
   142 inline void CMPXMedia::SetCObjectValueL(
       
   143     const TMPXAttribute& aAttribute,C* aValue)
       
   144     {
       
   145     if (aValue)
       
   146         {
       
   147         CBufBase* b=NULL;
       
   148         ::CreateBufferL(*aValue,b);
       
   149         CleanupStack::PushL(b);
       
   150         SetValueL(aAttribute,b->Ptr(0),EMPXTypeCObject);
       
   151         CleanupStack::PopAndDestroy(b);
       
   152         }
       
   153     else
       
   154         {
       
   155         SetValueL(aAttribute,KNullDesC8,EMPXTypeCObject);
       
   156         }
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMPXMedia::Data
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 inline TInt CMPXMedia::Data() const
       
   164     {
       
   165     return static_cast<TInt>(iDataHandle);
       
   166     }
       
   167 
       
   168 // END OF FILE