sbMediacoreEvent.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
31 #include "sbMediacoreEvent.h"
32 
33 #include <nsAutoPtr.h>
34 
39 #ifdef PR_LOGGING
40 static PRLogModuleInfo * MediacoreEvent() {
41  static PRLogModuleInfo* gMediacoreEvent = PR_NewLogModule("sbMediacoreEvent");
42  return gMediacoreEvent;
43 }
44 
45 #define TRACE(args) PR_LOG(MediacoreEvent() , PR_LOG_DEBUG, args)
46 #define LOG(args) PR_LOG(MediacoreEvent() , PR_LOG_WARN, args)
47 #else
48 #define TRACE(args) /* nothing */
49 #define LOG(args) /* nothing */
50 #endif
51 
54 
56 : mLock(nsnull)
57 , mType(sbIMediacoreEvent::UNINTIALIZED)
58 , mDispatched(PR_FALSE)
59 {
60  MOZ_COUNT_CTOR(sbMediacoreEvent);
61 
62  TRACE(("sbMediacoreEvent[0x%x] - Created", this));
63 }
64 
66 {
67  TRACE(("sbMediacoreEvent[0x%x] - Destroyed", this));
68 
69  MOZ_COUNT_DTOR(sbMediacoreEvent);
70 
71  if(mLock) {
72  nsAutoLock::DestroyLock(mLock);
73  }
74 }
75 
76 nsresult
77 sbMediacoreEvent::Init(PRUint32 aType,
78  sbIMediacoreError *aError,
79  nsIVariant *aData,
80  sbIMediacore *aOrigin)
81 {
82  TRACE(("sbMediacoreEvent[0x%x] - Init", this));
83 
84  mLock = nsAutoLock::NewLock("sbMediacoreEvent::mLock");
85  NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
86 
87  mType = aType;
88  mError = aError;
89  mData = aData;
90  mOrigin = aOrigin;
91 
92  return NS_OK;
93 }
94 
95 nsresult
97 {
98  TRACE(("sbMediacoreEvent[0x%x] - SetTarget", this));
99 
100  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
101  NS_ENSURE_ARG_POINTER(aTarget);
102 
103  nsAutoLock lock(mLock);
104  mTarget = aTarget;
105 
106  return NS_OK;
107 }
108 
109 void
111 {
112  TRACE(("sbMediacoreEvent[0x%x] - Dispatch", this));
113 
114  nsAutoLock lock(mLock);
115  mDispatched = PR_TRUE;
116 }
117 
118 PRBool
120 {
121  TRACE(("sbMediacoreEvent[0x%x] - WasDispatched", this));
122 
123  nsAutoLock lock(mLock);
124  return mDispatched;
125 }
126 
127 NS_IMETHODIMP
128 sbMediacoreEvent::GetType(PRUint32 *aType)
129 {
130  TRACE(("sbMediacoreEvent[0x%x] - GetType", this));
131 
132  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
133  nsAutoLock lock(mLock);
134 
135  *aType = mType;
136 
137  return NS_OK;
138 }
139 
140 NS_IMETHODIMP
141 sbMediacoreEvent::GetError(sbIMediacoreError * *aError)
142 {
143  TRACE(("sbMediacoreEvent[0x%x] - GetError", this));
144 
145  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
146  nsAutoLock lock(mLock);
147 
148  NS_IF_ADDREF(*aError = mError);
149 
150  return NS_OK;
151 }
152 
153 NS_IMETHODIMP
154 sbMediacoreEvent::GetData(nsIVariant * *aData)
155 {
156  TRACE(("sbMediacoreEvent[0x%x] - GetData", this));
157 
158  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
159  nsAutoLock lock(mLock);
160 
161  NS_IF_ADDREF(*aData = mData);
162 
163  return NS_OK;
164 }
165 
166 NS_IMETHODIMP
167 sbMediacoreEvent::GetOrigin(sbIMediacore * *aOrigin)
168 {
169  TRACE(("sbMediacoreEvent[0x%x] - GetOrigin", this));
170 
171  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
172  nsAutoLock lock(mLock);
173 
174  NS_IF_ADDREF(*aOrigin = mOrigin);
175 
176  return NS_OK;
177 }
178 
179 NS_IMETHODIMP
180 sbMediacoreEvent::GetTarget(sbIMediacoreEventTarget * *aTarget)
181 {
182  TRACE(("sbMediacoreEvent[0x%x] - GetTarget", this));
183 
184  NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
185  nsAutoLock lock(mLock);
186 
187  NS_IF_ADDREF(*aTarget = mTarget);
188 
189  return NS_OK;
190 }
191 
192 nsresult
194  sbIMediacoreError * aError,
195  nsIVariant *aData,
196  sbIMediacore *aOrigin,
197  sbIMediacoreEvent **retval)
198 {
199  nsresult rv;
200  nsRefPtr<sbMediacoreEvent> event = new sbMediacoreEvent();
201  NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
202 
203  rv = event->Init(aType, aError, aData, aOrigin);
204  NS_ENSURE_SUCCESS(rv, rv);
205 
206  NS_IF_ADDREF(*retval = event);
207 
208  return NS_OK;
209 }
NS_IMPL_THREADSAFE_ISUPPORTS1(sbMediacoreEvent, sbIMediacoreEvent) sbMediacoreEvent
nsCOMPtr< nsIVariant > mData
return NS_OK
Songbird Mediacore Event Definition.
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIACOREEVENT sbMediacoreEvent()
var event
nsresult Init(PRUint32 aType, sbIMediacoreError *aError, nsIVariant *aData, sbIMediacore *aOrigin)
Definition of the sbIMediacoreEvent interface.
nsresult SetTarget(sbIMediacoreEventTarget *aTarget)
virtual ~sbMediacoreEvent()
static nsresult CreateEvent(PRUint32 aType, sbIMediacoreError *aError, nsIVariant *aData, sbIMediacore *aOrigin, sbIMediacoreEvent **retval)
nsCOMPtr< sbIMediacore > mOrigin
#define TRACE(args)
nsCOMPtr< sbIMediacoreError > mError
nsCOMPtr< sbIMediacoreEventTarget > mTarget
_updateTextAndScrollDataForFrame aData