sbIPDSysDevice.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 
27 //------------------------------------------------------------------------------
28 //
29 // iPod system dependent device services.
30 //
31 //------------------------------------------------------------------------------
32 
38 //------------------------------------------------------------------------------
39 //
40 // iPod system dependent device imported services.
41 //
42 //------------------------------------------------------------------------------
43 
44 // Self imports.
45 #include "sbIPDSysDevice.h"
46 
47 // Local imports.
48 #include "sbIPDLog.h"
49 
50 // Mozilla imports.
51 #include <nsIPropertyBag.h>
52 #include <nsIPropertyBag2.h>
53 #include <nsIWritablePropertyBag.h>
54 
55 // Songbird imports
57 #include <sbDebugUtils.h>
58 
59 
60 //------------------------------------------------------------------------------
61 //
62 // iPod system dependent device sbIDevice services.
63 //
64 //------------------------------------------------------------------------------
65 
70 NS_IMETHODIMP
72 {
73  // call the parent
74  nsresult rv = sbIPDDevice::Eject();
75  NS_ENSURE_SUCCESS(rv, rv);
76 
77  OSErr osErr;
78 
79  // Eject the device volume.
80  pid_t dissenterPID;
81  osErr = FSEjectVolumeSync(mVolumeRefNum, 0, &dissenterPID);
82  NS_ENSURE_TRUE(osErr == noErr, NS_ERROR_FAILURE);
83 
84  return NS_OK;
85 }
86 
87 
88 //------------------------------------------------------------------------------
89 //
90 // iPod system dependent device services.
91 //
92 //------------------------------------------------------------------------------
93 
101 sbIPDSysDevice::sbIPDSysDevice(const nsID& aControllerID,
102  nsIPropertyBag* aProperties) :
103  sbIPDDevice(aControllerID, aProperties),
104  mProperties(aProperties)
105 {
106  // Validate parameters.
107  NS_ASSERTION(aProperties, "aProperties is null");
108 
110 
111  // Log progress.
112  LOG("Enter: sbIPDSysDevice::sbIPDSysDevice\n");
113 }
114 
115 
121 {
122  // Log progress.
123  LOG("Enter: sbIPDSysDevice::~sbIPDSysDevice\n");
124 
125  // Finalize the iPod system dependent device object.
126  Finalize();
127 }
128 
129 
134 nsresult
136 {
137  nsresult rv;
138 
139  // Get the device properties.
140  nsCOMPtr<nsIPropertyBag2> properties = do_QueryInterface(mProperties, &rv);
141  NS_ENSURE_SUCCESS(rv, rv);
142  nsCOMPtr<nsIWritablePropertyBag> writeProperties =
143  do_QueryInterface(mProperties, &rv);
144  NS_ENSURE_SUCCESS(rv, rv);
145 
146  // Add the device manufacturer and model number properties.
147  rv = writeProperties->SetProperty
148  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MANUFACTURER),
149  sbIPDVariant("Apple").get());
150  NS_ENSURE_SUCCESS(rv, rv);
151  rv = writeProperties->SetProperty(NS_LITERAL_STRING(SB_DEVICE_PROPERTY_MODEL),
152  sbIPDVariant("iPod").get());
153  NS_ENSURE_SUCCESS(rv, rv);
154 
155  // Get the Firewire GUID property.
156  nsAutoString firewireGUID;
157  NS_ENSURE_SUCCESS(rv, rv);
158  rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("FirewireGUID"),
159  firewireGUID);
160  NS_ENSURE_SUCCESS(rv, rv);
161 
162  // Get the device volume reference number.
163  nsCOMPtr<nsIVariant> propVariant;
164  rv = properties->Get(NS_LITERAL_STRING("VolumeRefNum"),
165  getter_AddRefs(propVariant));
166  NS_ENSURE_SUCCESS(rv, rv);
167  rv = sbIPDVariant::GetValue(propVariant, &mVolumeRefNum);
168  NS_ENSURE_SUCCESS(rv, rv);
169 
170  // Add the device serial number property.
171  //XXXeps use Firewire GUID for now.
172  rv = writeProperties->SetProperty
173  (NS_LITERAL_STRING(SB_DEVICE_PROPERTY_SERIAL_NUMBER),
174  sbIPDVariant(firewireGUID).get());
175  NS_ENSURE_SUCCESS(rv, rv);
176 
177  // Initialize the iPod device object.
179  NS_ENSURE_SUCCESS(rv, rv);
180 
181  return NS_OK;
182 }
183 
184 
189 void
191 {
192  // Finalize the iPod device object.
194 }
195 
196 
#define SB_PRLOG_SETUP(x)
Definition: sbDebugUtils.h:115
return NS_OK
#define LOG(args)
nsCOMPtr< nsIArray > mProperties
#define SB_DEVICE_PROPERTY_MANUFACTURER
sbIPDSysDevice(const nsID &aControllerID, nsIPropertyBag *aProperties)
NS_IMETHOD Eject(void)
Songbird iPod Device Logging Definitions.
readonly attribute sbIDeviceProperties properties
Definition: sbIDevice.idl:168
nsresult Eject()
#define SB_DEVICE_PROPERTY_SERIAL_NUMBER
nsresult Initialize()
nsresult Initialize()
#define SB_DEVICE_PROPERTY_MODEL
static nsresult GetValue(nsIVariant *aVariant, PRInt16 *aValue)
Definition: sbIPDUtils.h:233