sbIPDFairPlayEvent.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //=BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2009 POTI, Inc.
9 // http://www.songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the GPL).
13 //
14 // Software distributed under the License is distributed
15 // on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 //=END SONGBIRD GPL
25 */
26 
32 //------------------------------------------------------------------------------
33 //
34 // iPod device FairPlay event imported services.
35 //
36 //------------------------------------------------------------------------------
37 
38 // Self import.
39 #include "sbIPDFairPlayEvent.h"
40 
41 // Songbird imports.
42 #include <sbIDeviceManager.h>
43 
44 // Mozilla imports.
45 #include <nsAutoPtr.h>
46 #include <nsServiceManagerUtils.h>
47 
48 
49 //------------------------------------------------------------------------------
50 //
51 // iPod device FairPlay event nsISupports implementation.
52 //
53 //------------------------------------------------------------------------------
54 
55 //
56 // NS_IMPL_THREADSAFE_ISUPPORTS4(sbIPDFairPlayEvent,
57 // sbIIPDFairPlayEvent,
58 // sbIIPDDeviceEvent,
59 // sbIDeviceEvent,
60 // sbDeviceEvent)
61 //
62 
65 NS_INTERFACE_MAP_BEGIN(sbIPDFairPlayEvent)
66  NS_INTERFACE_MAP_ENTRY(sbIIPDFairPlayEvent)
67  NS_INTERFACE_MAP_ENTRY(sbIIPDDeviceEvent)
68  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(sbIDeviceEvent, sbIIPDDeviceEvent)
69  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, sbIIPDDeviceEvent)
70  NS_INTERFACE_MAP_ENTRY(sbDeviceEvent)
71 NS_INTERFACE_MAP_END
72 
73 
74 //------------------------------------------------------------------------------
75 //
76 // iPod device FairPlay event sbIIPDFairPlayEvent implementation.
77 //
78 //------------------------------------------------------------------------------
79 
80 //
81 // Getters/setters.
82 //
83 
88 NS_IMETHODIMP
89 sbIPDFairPlayEvent::GetUserID(PRUint32* aUserID)
90 {
91  NS_ENSURE_ARG_POINTER(aUserID);
92  *aUserID = mUserID;
93  return NS_OK;
94 }
95 
96 
101 NS_IMETHODIMP
102 sbIPDFairPlayEvent::GetAccountName(nsAString& aAccountName)
103 {
104  aAccountName.Assign(mAccountName);
105  return NS_OK;
106 }
107 
108 
113 NS_IMETHODIMP
114 sbIPDFairPlayEvent::GetUserName(nsAString& aUserName)
115 {
116  aUserName.Assign(mUserName);
117  return NS_OK;
118 }
119 
120 
125 NS_IMETHODIMP
126 sbIPDFairPlayEvent::GetMediaItem(sbIMediaItem** aMediaItem)
127 {
128  NS_ENSURE_ARG_POINTER(aMediaItem);
129  NS_IF_ADDREF(*aMediaItem = mMediaItem);
130  return NS_OK;
131 }
132 
133 
134 //------------------------------------------------------------------------------
135 //
136 // iPod device FairPlay event services.
137 //
138 //------------------------------------------------------------------------------
139 
154 /* static */
155 nsresult
157  sbIDevice* aDevice,
158  PRUint32 aType,
159  PRUint32 aUserID,
160  nsAString& aAccountName,
161  nsAString& aUserName,
162  sbIMediaItem* aMediaItem)
163 {
164  // Validate parameters.
165  NS_ENSURE_ARG_POINTER(aFairPlayEvent);
166  NS_ENSURE_ARG_POINTER(aDevice);
167 
168  // Function variables.
169  nsresult rv;
170 
171  // Create and initialize an event object.
172  nsRefPtr<sbIPDFairPlayEvent> event = new sbIPDFairPlayEvent();
173  NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
174  rv = event->InitEvent(aDevice,
175  aType,
176  aUserID,
177  aAccountName,
178  aUserName,
179  aMediaItem);
180  NS_ENSURE_SUCCESS(rv, rv);
181 
182  // Return results.
183  NS_ADDREF(*aFairPlayEvent = event);
184 
185  return NS_OK;
186 }
187 
188 
189 //------------------------------------------------------------------------------
190 //
191 // Internal iPod device FairPlay event services.
192 //
193 //------------------------------------------------------------------------------
194 
200 {
201 }
202 
203 
209 {
210 }
211 
212 
226 nsresult
227 sbIPDFairPlayEvent::InitEvent(sbIDevice* aDevice,
228  PRUint32 aType,
229  PRUint32 aUserID,
230  nsAString& aAccountName,
231  nsAString& aUserName,
232  sbIMediaItem* aMediaItem)
233 {
234  // Validate parameters.
235  NS_ASSERTION(aDevice, "aDevice is null");
236 
237  // Function variables.
238  nsresult rv;
239 
240  // Get the device manager.
241  nsCOMPtr<sbIDeviceManager2>
242  manager = do_GetService("@songbirdnest.com/Songbird/DeviceManager;2", &rv);
243  NS_ENSURE_SUCCESS(rv, rv);
244 
245  PRUint32 deviceState;
246  rv = aDevice->GetState(&deviceState);
247  NS_ENSURE_SUCCESS(rv, rv);
248 
249  // Create a device event.
250  rv = manager->CreateEvent(aType,
251  nsnull,
252  aDevice,
253  deviceState,
255  getter_AddRefs(mDeviceEvent));
256  NS_ENSURE_SUCCESS(rv, rv);
257  mSBDeviceEvent = do_QueryInterface(mDeviceEvent, &rv);
258  NS_ENSURE_SUCCESS(rv, rv);
259 
260  // Set up the FairPlay event info.
261  mUserID = aUserID;
262  mAccountName.Assign(aAccountName);
263  mUserName.Assign(aUserName);
264  mMediaItem = aMediaItem;
265 
266  return NS_OK;
267 }
268 
static sbDeviceEvent * CreateEvent()
return NS_OK
var event
Base iPod device event interface.
readonly attribute unsigned long deviceState
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
iPod device event interface for FairPlay events.
Songbird iPod Device FairPlay Event Definitions.
const unsigned long STATE_IDLE
Definition: sbIDevice.idl:220
Interface that defines a single item of media in the system.