Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 
     19 #include "pvmf_metadata_infomessage.h"
     20 #include "oscl_mem.h"
     21 
     22 OSCL_EXPORT_REF PVMFMetadataInfoMessage::PVMFMetadataInfoMessage() :
     23         iEventCode(0),
     24         iRefCount(1)
     25 {
     26     iMetadataVector.reserve(14);
     27     iMetadataVector.clear();
     28 }
     29 
     30 OSCL_EXPORT_REF PVMFMetadataInfoMessage::PVMFMetadataInfoMessage(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aMetadataVector, int32 aCode, PVUuid aUuid) :
     31         iRefCount(1)
     32 {
     33     // Save the event info
     34     iEventCode = aCode;
     35     iEventUuid = aUuid;
     36     iMetadataVector.clear();
     37     iMetadataVector = aMetadataVector;
     38 }
     39 
     40 OSCL_EXPORT_REF PVMFMetadataInfoMessage::~PVMFMetadataInfoMessage()
     41 {
     42     // If the destructor is called directly (instead of via removeRef())
     43     // then the ref count for the next message in the list needs to decremented
     44     iMetadataVector.clear();
     45 }
     46 
     47 OSCL_EXPORT_REF void PVMFMetadataInfoMessage::destroy()
     48 {
     49     OSCL_DELETE(this);
     50 }
     51 
     52 OSCL_EXPORT_REF void PVMFMetadataInfoMessage::SetEventCodeUUID(int32 aCode, PVUuid aUuid)
     53 {
     54     // Set event code and UUID
     55     iEventCode = aCode;
     56     iEventUuid = aUuid;
     57 }
     58 
     59 OSCL_EXPORT_REF void PVMFMetadataInfoMessage::GetCodeUUID(int32& aCode, PVUuid& aUuid)
     60 {
     61     // Return event code and UUID
     62     aCode = iEventCode;
     63     aUuid = iEventUuid;
     64 }
     65 
     66 OSCL_EXPORT_REF Oscl_Vector<PvmiKvp, OsclMemAllocator>& PVMFMetadataInfoMessage::GetMetadataVector()
     67 {
     68     // Return the next message in the list
     69     return iMetadataVector;
     70 }
     71 
     72 OSCL_EXPORT_REF void PVMFMetadataInfoMessage::addRef()
     73 {
     74     // Increment this object's ref count
     75     ++iRefCount;
     76 }
     77 
     78 OSCL_EXPORT_REF void PVMFMetadataInfoMessage::removeRef()
     79 {
     80     // Decrement this object's ref count
     81     --iRefCount;
     82 
     83     // If ref count reaches 0 then destroy this object automatically
     84     if (iRefCount <= 0)
     85     {
     86         // The next message's refcount has already been decremented so
     87         // set to NULL so the destructor won't decrement again.
     88         // Destroy this instance.
     89         destroy();
     90     }
     91 }
     92 
     93 OSCL_EXPORT_REF bool PVMFMetadataInfoMessage::queryInterface(const PVUuid& uuid, PVInterface*& iface)
     94 {
     95     // Only returns the error/info message interface
     96     if (uuid == PVMFMetadataInfoMessageInterfaceUUID)
     97     {
     98         PVMFMetadataInfoMessageInterface* myInterface = OSCL_STATIC_CAST(PVMFMetadataInfoMessageInterface*, this);
     99         iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
    100     }
    101     else
    102     {
    103         return false;
    104     }
    105     return true;
    106 }
    107 
    108