• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_basic_errorinfomessage.h"
20 #include "oscl_mem.h"
21 
PVMFBasicErrorInfoMessage()22 OSCL_EXPORT_REF PVMFBasicErrorInfoMessage::PVMFBasicErrorInfoMessage() :
23         iEventCode(0),
24         iNextMessage(NULL),
25         iRefCount(1)
26 {
27 }
28 
PVMFBasicErrorInfoMessage(int32 aCode,PVUuid & aUuid,PVMFErrorInfoMessageInterface * aNextMsg)29 OSCL_EXPORT_REF PVMFBasicErrorInfoMessage::PVMFBasicErrorInfoMessage(int32 aCode, PVUuid& aUuid, PVMFErrorInfoMessageInterface* aNextMsg) :
30         iRefCount(1)
31 {
32     // Save the event info
33     iEventCode = aCode;
34     iEventUuid = aUuid;
35     iNextMessage = aNextMsg;
36 
37     // Increment the ref count for the next message in the list
38     if (iNextMessage)
39     {
40         iNextMessage->addRef();
41     }
42 }
43 
~PVMFBasicErrorInfoMessage()44 OSCL_EXPORT_REF PVMFBasicErrorInfoMessage::~PVMFBasicErrorInfoMessage()
45 {
46     // If the destructor is called directly (instead of via removeRef())
47     // then the ref count for the next message in the list needs to decremented
48     if (iNextMessage)
49     {
50         iNextMessage->removeRef();
51         iNextMessage = NULL;
52     }
53 }
destroy()54 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::destroy()
55 {
56     OSCL_DELETE(this);
57 }
58 
SetEventCodeUUID(int32 aCode,PVUuid aUuid)59 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::SetEventCodeUUID(int32 aCode, PVUuid aUuid)
60 {
61     // Set event code and UUID
62     iEventCode = aCode;
63     iEventUuid = aUuid;
64 }
65 
SetNextMessage(PVMFErrorInfoMessageInterface & aNextMsg)66 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::SetNextMessage(PVMFErrorInfoMessageInterface& aNextMsg)
67 {
68     // Remove reference to existing one if present
69     if (iNextMessage)
70     {
71         iNextMessage->removeRef();
72     }
73 
74     // Save the reference and increment ref for it
75     iNextMessage = &aNextMsg;
76     iNextMessage->addRef();
77 }
78 
GetCodeUUID(int32 & aCode,PVUuid & aUuid)79 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::GetCodeUUID(int32& aCode, PVUuid& aUuid)
80 {
81     // Return event code and UUID
82     aCode = iEventCode;
83     aUuid = iEventUuid;
84 }
85 
GetNextMessage()86 OSCL_EXPORT_REF PVMFErrorInfoMessageInterface* PVMFBasicErrorInfoMessage::GetNextMessage()
87 {
88     // Return the next message in the list
89     return iNextMessage;
90 }
91 
addRef()92 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::addRef()
93 {
94     // Increment this object's ref count
95     ++iRefCount;
96 
97     // Increment ref count for the next message in the list
98     if (iNextMessage)
99     {
100         iNextMessage->addRef();
101     }
102 }
103 
removeRef()104 OSCL_EXPORT_REF void PVMFBasicErrorInfoMessage::removeRef()
105 {
106     // Decrement ref count for the next message in the list
107     if (iNextMessage)
108     {
109         iNextMessage->removeRef();
110     }
111 
112     // Decrement this object's ref count
113     --iRefCount;
114 
115     // If ref count reaches 0 then destroy this object automatically
116     if (iRefCount <= 0)
117     {
118         // The next message's refcount has already been decremented so
119         // set to NULL so the destructor won't decrement again.
120         iNextMessage = NULL;
121         // Destroy this instance.
122         destroy();
123     }
124 }
125 
queryInterface(const PVUuid & uuid,PVInterface * & iface)126 OSCL_EXPORT_REF bool PVMFBasicErrorInfoMessage::queryInterface(const PVUuid& uuid, PVInterface*& iface)
127 {
128     // Only returns the error/info message interface
129     if (uuid == PVMFErrorInfoMessageInterfaceUUID)
130     {
131         PVMFErrorInfoMessageInterface* myInterface = OSCL_STATIC_CAST(PVMFErrorInfoMessageInterface*, this);
132         iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
133     }
134     else
135     {
136         return false;
137     }
138 
139     return true;
140 }
141 
142