sbLibraryChangeset.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2011 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
29 #include "sbLibraryChangeset.h"
30 
31 #include <nsIClassInfoImpl.h>
32 #include <nsIProgrammingLanguage.h>
33 #include <sbIMediaItem.h>
34 #include <sbIMediaList.h>
35 
36 #include <nsIMutableArray.h>
37 #include <nsMemory.h>
38 
39 //-----------------------------------------------------------------------------
40 // sbPropertyChange
41 //-----------------------------------------------------------------------------
42 
45 
46 NS_INTERFACE_MAP_BEGIN(sbPropertyChange)
47  NS_IMPL_QUERY_CLASSINFO(sbPropertyChange)
48  //XXXAus: static_cast does not work in this case,
49  //reinterpret_cast to nsISupports is necessary
50  if ( aIID.Equals(NS_GET_IID(sbPropertyChange)) )
51  foundInterface = reinterpret_cast<nsISupports*>(this);
52  else
53  NS_INTERFACE_MAP_ENTRY(sbIPropertyChange)
54  NS_INTERFACE_MAP_ENTRY(sbIChangeOperation)
55  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, sbIPropertyChange)
56 NS_INTERFACE_MAP_END
57 
61 
62 NS_DECL_CLASSINFO(sbPropertyChange)
63 NS_IMPL_THREADSAFE_CI(sbPropertyChange)
64 
65 sbPropertyChange::sbPropertyChange()
67 {
68 
69 }
70 
71 sbPropertyChange::~sbPropertyChange()
72 {
73 }
74 
75 nsresult sbPropertyChange::InitWithValues(PRUint32 aOperation,
76  const nsAString &aID,
77  const nsAString &aOldValue,
78  const nsAString &aNewValue)
79 {
80  mOperation = aOperation;
81  mID = aID;
82  mOldValue = aOldValue;
83  mNewValue = aNewValue;
84 
85  return NS_OK;
86 }
87 
88 nsresult sbPropertyChange::SetOperation(PRUint32 aOperation)
89 {
90  mOperation = aOperation;
91  return NS_OK;
92 }
93 
94 nsresult sbPropertyChange::SetID(const nsAString &aID)
95 {
96  mID = aID;
97  return NS_OK;
98 }
99 
100 nsresult sbPropertyChange::SetOldValue(const nsAString &aOldValue)
101 {
102  mOldValue = aOldValue;
103  return NS_OK;
104 }
105 
106 nsresult sbPropertyChange::SetNewValue(const nsAString &aNewValue)
107 {
108  mNewValue = aNewValue;
109  return NS_OK;
110 }
111 
112 /* readonly attribute unsigned long operation; */
113 NS_IMETHODIMP sbPropertyChange::GetOperation(PRUint32 *aOperation)
114 {
115  NS_ENSURE_ARG_POINTER(aOperation);
116  *aOperation = mOperation;
117 
118  return NS_OK;
119 }
120 
121 /* readonly attribute AString id; */
122 NS_IMETHODIMP sbPropertyChange::GetId(nsAString & aId)
123 {
124  aId.Assign(mID);
125 
126  return NS_OK;
127 }
128 
129 /* readonly attribute AString oldValue; */
130 NS_IMETHODIMP sbPropertyChange::GetOldValue(nsAString & aOldValue)
131 {
132  aOldValue.Assign(mOldValue);
133 
134  return NS_OK;
135 }
136 
137 /* readonly attribute AString newValue; */
138 NS_IMETHODIMP sbPropertyChange::GetNewValue(nsAString & aNewValue)
139 {
140  aNewValue.Assign(mNewValue);
141  return NS_OK;
142 }
143 
144 
145 //-----------------------------------------------------------------------------
146 // sbLibraryChange
147 //-----------------------------------------------------------------------------
148 
149 NS_IMPL_THREADSAFE_ADDREF(sbLibraryChange)
150 NS_IMPL_THREADSAFE_RELEASE(sbLibraryChange)
151 
152 NS_INTERFACE_MAP_BEGIN(sbLibraryChange)
153  NS_IMPL_QUERY_CLASSINFO(sbLibraryChange)
154  //XXXAus: static_cast does not work in this case,
155  //reinterpret_cast to nsISupports is necessary
156  if ( aIID.Equals(NS_GET_IID(sbLibraryChange)) )
157  foundInterface = reinterpret_cast<nsISupports*>(this);
158  else
159  NS_INTERFACE_MAP_ENTRY(sbILibraryChange)
160  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, sbILibraryChange)
161 NS_INTERFACE_MAP_END
162 
166 
167 NS_DECL_CLASSINFO(sbLibraryChange)
168 NS_IMPL_THREADSAFE_CI(sbLibraryChange)
169 
170 sbLibraryChange::sbLibraryChange()
171 : mOperation(sbIChangeOperation::UNKNOWN)
172 , mTimestamp(0)
173 {
174 }
175 
176 sbLibraryChange::~sbLibraryChange()
177 {
178 }
179 
180 
181 nsresult sbLibraryChange::InitWithValues(PRUint32 aOperation,
182  PRUint64 aTimestamp,
183  sbIMediaItem *aSourceItem,
184  sbIMediaItem *aDestinationItem,
185  nsIArray *aProperties,
186  nsIArray *aListItems)
187 {
188  mOperation = aOperation;
189  mTimestamp = aTimestamp;
190  mSourceItem = aSourceItem;
191  mDestinationItem = aDestinationItem;
192  mProperties = aProperties;
193  mListItems = aListItems;
194  return NS_OK;
195 }
196 
197 nsresult sbLibraryChange::SetOperation(PRUint32 aOperation)
198 {
199  mOperation = aOperation;
200 
201  return NS_OK;
202 }
203 
204 nsresult sbLibraryChange::SetTimestamp(PRUint64 aTimestamp)
205 {
206  mTimestamp = aTimestamp;
207 
208  return NS_OK;
209 }
210 
211 nsresult sbLibraryChange::SetListItems(nsIArray *aListItems)
212 {
213  mListItems = aListItems;
214 
215  return NS_OK;
216 }
217 
219  sbIMediaItem *aDestinationItem)
220 {
221  NS_ENSURE_ARG_POINTER(aSourceItem);
222 
223  mSourceItem = aSourceItem;
224  mDestinationItem = aDestinationItem ? aDestinationItem : aSourceItem;
225 
226  return NS_OK;
227 }
228 
229 nsresult sbLibraryChange::SetProperties(nsIArray *aProperties)
230 {
231  NS_ENSURE_ARG_POINTER(aProperties);
232 
233  mProperties = aProperties;
234 
235  return NS_OK;
236 }
237 
238 /* readonly attribute unsigned long operation; */
239 NS_IMETHODIMP sbLibraryChange::GetOperation(PRUint32 *aOperation)
240 {
241  NS_ENSURE_ARG_POINTER(aOperation);
242 
243  *aOperation = mOperation;
244 
245  return NS_OK;
246 }
247 
248 /* readonly attribute unsigned long long timestamp; */
249 NS_IMETHODIMP sbLibraryChange::GetTimestamp(PRUint64 *aTimestamp)
250 {
251  NS_ENSURE_ARG_POINTER(aTimestamp);
252 
253  *aTimestamp = mTimestamp;
254 
255  return NS_OK;
256 }
257 
258 /* readonly attribute sbIMediaItem sourceItem; */
259 NS_IMETHODIMP sbLibraryChange::GetSourceItem(sbIMediaItem * *aItem)
260 {
261  NS_ENSURE_ARG_POINTER(aItem);
262  NS_IF_ADDREF(*aItem = mSourceItem);
263 
264  return *aItem ? NS_OK : NS_ERROR_NOT_AVAILABLE;
265 }
266 
267 /* readonly attribute sbIMediaItem destinationItem; */
268 NS_IMETHODIMP sbLibraryChange::GetDestinationItem(sbIMediaItem * *aItem)
269 {
270  NS_ENSURE_ARG_POINTER(aItem);
271 
272  NS_IF_ADDREF(*aItem = mDestinationItem);
273 
274  return *aItem ? NS_OK : NS_ERROR_NOT_AVAILABLE;
275 }
276 
277 /* readonly attribute boolean itemIsList; */
278 NS_IMETHODIMP sbLibraryChange::GetItemIsList(PRBool *aItemIsList)
279 {
280  NS_ENSURE_ARG_POINTER(aItemIsList);
281 
282  nsresult rv;
283 
284  nsCOMPtr<sbIMediaList> mediaList;
285  if (mSourceItem) {
286  mediaList = do_QueryInterface(mSourceItem, &rv);
287  } else {
288  // no source, use dest
289  mediaList = do_QueryInterface(mDestinationItem, &rv);
290  }
291 
292  if(rv == NS_ERROR_NO_INTERFACE) {
293  *aItemIsList = PR_FALSE;
294  return NS_OK;
295  }
296  else if(mediaList != 0) {
297  *aItemIsList = PR_TRUE;
298  return NS_OK;
299  }
300 
301  return NS_ERROR_UNEXPECTED;
302 }
303 
304 /* readonly attribute nsIArray listItems; */
305 NS_IMETHODIMP sbLibraryChange::GetListItems(nsIArray **aListItems)
306 {
307  NS_ENSURE_ARG_POINTER(aListItems);
308 
309  PRBool isList;
310  nsresult rv = GetItemIsList(&isList);
311  NS_ENSURE_SUCCESS(rv, rv);
312 
313  if (!isList)
314  return NS_ERROR_FAILURE;
315 
316  NS_IF_ADDREF(*aListItems = mListItems);
317 
318  return NS_OK;
319 }
320 
321 /* readonly attribute nsIArray properties; */
322 NS_IMETHODIMP sbLibraryChange::GetProperties(nsIArray * *aProperties)
323 {
324  NS_ENSURE_ARG_POINTER(aProperties);
325 
326  NS_IF_ADDREF(*aProperties = mProperties);
327 
328  return *aProperties ? NS_OK : NS_ERROR_NOT_AVAILABLE;
329 }
330 
331 //-----------------------------------------------------------------------------
332 // sbLibraryChangeset
333 //-----------------------------------------------------------------------------
334 
335 
336 NS_IMPL_THREADSAFE_ADDREF(sbLibraryChangeset)
337 NS_IMPL_THREADSAFE_RELEASE(sbLibraryChangeset)
338 
339 NS_INTERFACE_MAP_BEGIN(sbLibraryChangeset)
340  NS_IMPL_QUERY_CLASSINFO(sbLibraryChangeset)
341  //XXXAus: static_cast does not work in this case,
342  //reinterpret_cast to nsISupports is necessary
343  if ( aIID.Equals(NS_GET_IID(sbLibraryChangeset)) )
344  foundInterface = reinterpret_cast<nsISupports*>(this);
345  else
346  NS_INTERFACE_MAP_ENTRY(sbILibraryChangeset)
347  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, sbILibraryChangeset)
348 NS_INTERFACE_MAP_END
349 
350 NS_IMPL_CI_INTERFACE_GETTER1(sbLibraryChangeset,
352 
353 NS_DECL_CLASSINFO(sbLibraryChangeset)
354 NS_IMPL_THREADSAFE_CI(sbLibraryChangeset)
355 
356 sbLibraryChangeset::sbLibraryChangeset()
357 {
358 }
359 
360 sbLibraryChangeset::~sbLibraryChangeset()
361 {
362 }
363 
364 nsresult sbLibraryChangeset::InitWithValues(nsIArray *aSourceLists,
365  sbIMediaList *aDestinationList,
366  nsIArray *aChanges)
367 {
368  NS_ENSURE_ARG_POINTER(aSourceLists);
369  NS_ENSURE_ARG_POINTER(aDestinationList);
370  NS_ENSURE_ARG_POINTER(aChanges);
371 
372 
373  mSourceLists = aSourceLists;
374  mDestinationList = aDestinationList;
375  mChanges = aChanges;
376 
377  return NS_OK;
378 }
379 
380 nsresult sbLibraryChangeset::SetSourceLists(nsIArray *aSourceLists)
381 {
382  NS_ENSURE_ARG_POINTER(aSourceLists);
383 
384  mSourceLists = aSourceLists;
385 
386  return NS_OK;
387 }
388 
390 {
391  NS_ENSURE_ARG_POINTER(aDestinationList);
392 
393  mDestinationList = aDestinationList;
394 
395  return NS_OK;
396 }
397 
398 NS_IMETHODIMP sbLibraryChangeset::SetChanges(nsIArray *aChanges)
399 {
400  NS_ENSURE_ARG_POINTER(aChanges);
401 
402  mChanges = aChanges;
403 
404  return NS_OK;
405 }
406 
407 /* readonly attribute sbIMediaList sourceList; */
408 NS_IMETHODIMP sbLibraryChangeset::GetSourceLists(nsIArray * *aSourceLists)
409 {
410  NS_ENSURE_ARG_POINTER(aSourceLists);
411 
412  NS_IF_ADDREF(*aSourceLists = mSourceLists);
413 
414  return *aSourceLists ? NS_OK : NS_ERROR_NOT_AVAILABLE;
415 }
416 
417 /* readonly attribute sbIMediaList destinationList; */
418 NS_IMETHODIMP sbLibraryChangeset::GetDestinationList(sbIMediaList * *aDestinationList)
419 {
420  NS_ENSURE_ARG_POINTER(aDestinationList);
421 
422  NS_IF_ADDREF(*aDestinationList = mDestinationList);
423 
424  return *aDestinationList ? NS_OK : NS_ERROR_NOT_AVAILABLE;
425 }
426 
427 /* readonly attribute nsIArray changes; */
428 NS_IMETHODIMP sbLibraryChangeset::GetChanges(nsIArray * *aChanges)
429 {
430  NS_ENSURE_ARG_POINTER(aChanges);
431 
432  NS_IF_ADDREF(*aChanges = mChanges);
433 
434  return *aChanges ? NS_OK : NS_ERROR_NOT_AVAILABLE;
435 }
nsresult SetOldValue(const nsAString &aOldValue)
return NS_OK
nsresult SetOperation(PRUint32 aOperation)
nsCOMPtr< nsIArray > mProperties
else NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER2(sbPropertyChange, sbIPropertyChange, sbIChangeOperation) sbPropertyChange
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
sbLibraryChangeset Definition.
nsCOMPtr< nsIArray > mChanges
nsresult SetID(const nsAString &aID)
A brief description of the contents of this interface.
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
PRUint32 mOperation
NS_DEFINE_STATIC_IID_ACCESSOR(sbPropertyChange,{0x2cb3d75f, 0xfd37, 0x4ae0,{0xa7, 0xf1, 0xe8, 0x5c, 0x7b, 0xb9, 0xd1, 0x7b}}) class sbLibraryChange nsresult InitWithValues(PRUint32 aOperation, PRUint64 aTimestamp, sbIMediaItem *aSourceItem, sbIMediaItem *aDestinationItem, nsIArray *aProperties, nsIArray *aListItems)
nsresult SetItems(sbIMediaItem *aSourceItem, sbIMediaItem *aDestinationItem)
else
nsCOMPtr< sbIMediaItem > mSourceItem
nsresult SetListItems(nsIArray *aProperties)
this _document this
Definition: FeedWriter.js:1085
nsresult SetNewValue(const nsAString &aNewValue)
PRUint64 mTimestamp
nsresult SetSourceLists(nsIArray *aSourceLists)
nsCOMPtr< sbIMediaList > mDestinationList
nsCOMPtr< nsIArray > mSourceLists
nsresult InitWithValues(PRUint32 aOperation, const nsAString &aID, const nsAString &aOldValue, const nsAString &aNewValue)
sbIJobCancelable NS_DECL_CLASSINFO(sbGstreamerMediaInspector)
nsresult SetOperation(PRUint32 aOperation)
else NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(sbLibraryChangeset, sbILibraryChangeset) sbLibraryChangeset
nsCOMPtr< nsIMutableArray > mListItems
Interface that defines a single item of media in the system.
nsresult SetTimestamp(PRUint64 aTimestamp)
nsresult SetProperties(nsIArray *aProperties)
nsresult SetDestinationList(sbIMediaList *aDestinationList)
nsCOMPtr< sbIMediaItem > mDestinationItem
if(aIID.Equals(NS_GET_IID(sbPropertyChange))) foundInterface