sbIPDUtils.h
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 #ifndef __SB_IPD_UTILS_H__
28 #define __SB_IPD_UTILS_H__
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // iPod device utility services defs.
34 //
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 
43 //------------------------------------------------------------------------------
44 //
45 // iPod device utility imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Songbird imports.
50 #include <sbMemoryUtils.h>
51 
52 // Songbird interface imports
53 #include <sbIDevice.h>
54 
55 // Mozilla imports.
56 #include <nsComponentManagerUtils.h>
57 #include <nsIIOService.h>
58 #include <nsIURI.h>
59 #include <nsIVariant.h>
60 #include <nsServiceManagerUtils.h>
61 #include <nsStringAPI.h>
62 
63 // Libgpod imports.
64 #include <itdb.h>
65 
66 // Std C imports.
67 #include <stdlib.h>
68 
69 
70 //------------------------------------------------------------------------------
71 //
72 // iPod device utility services classes.
73 //
74 //------------------------------------------------------------------------------
75 
76 //
77 // Auto-disposal class wrappers.
78 //
79 // sbAutoGMemPtr Wrapper to auto-dispose memory blocks allocated
80 // with g_malloc.
81 // sbAutoITDBTrackPtr Wrapper to auto-dispose iPod database track data
82 // records.
83 //
84 
85 SB_AUTO_CLASS(sbAutoGMemPtr, void*, mValue, g_free(mValue), mValue = NULL);
86 SB_AUTO_CLASS(sbAutoITDBTrackPtr,
87  Itdb_Track*,
88  mValue,
89  itdb_track_free(mValue),
90  mValue = NULL);
91 
92 
112 {
113 public:
114 
116  {
117  nsresult rv;
118  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
119  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
120  rv = mVariant->SetAsISupports(aValue);
121  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
122  }
123 
124  sbIPDVariant(REFNSIID aIID, nsISupports* aValue)
125  {
126  nsresult rv;
127  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
128  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
129  rv = mVariant->SetAsInterface(aIID, aValue);
130  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
131  }
132 
133  sbIPDVariant(const nsAString& aValue)
134  {
135  nsresult rv;
136  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
137  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
138  rv = mVariant->SetAsAString(aValue);
139  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
140  }
141 
142  sbIPDVariant(const nsACString& aValue,
143  PRUint16 aType = nsIDataType::VTYPE_CSTRING)
144  {
145  nsresult rv;
146  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
147  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
148  if (aType == nsIDataType::VTYPE_UTF8STRING)
149  rv = mVariant->SetAsAUTF8String(aValue);
150  else
151  rv = mVariant->SetAsACString(aValue);
152  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
153  }
154 
155  sbIPDVariant(const char* aValue)
156  {
157  nsresult rv;
158  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
159  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
160  rv = mVariant->SetAsAString(NS_ConvertASCIItoUTF16(aValue));
161  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
162  }
163 
165  {
166  nsresult rv;
167  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
168  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
169  rv = mVariant->SetAsChar(aValue);
170  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
171  }
172 
174  {
175  nsresult rv;
176  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
177  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
178  rv = mVariant->SetAsInt16(aValue);
179  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
180  }
181 
183  {
184  nsresult rv;
185  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
186  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
187  rv = mVariant->SetAsInt32(aValue);
188  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
189  }
190 
192  PRUint16 aType = nsIDataType::VTYPE_UINT32)
193  {
194  nsresult rv;
195  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
196  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
197  if (aType == nsIDataType::VTYPE_BOOL)
198  rv = mVariant->SetAsBool(aValue);
199  else
200  rv = mVariant->SetAsUint32(aValue);
201  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
202  }
203 
205  {
206  nsresult rv;
207  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
208  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
209  rv = mVariant->SetAsInt64(aValue);
210  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
211  }
212 
214  {
215  nsresult rv;
216  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
217  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
218  rv = mVariant->SetAsUint64(aValue);
219  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
220  }
221 
223  {
224  nsresult rv;
225  mVariant = do_CreateInstance("@songbirdnest.com/Songbird/Variant;1", &rv);
226  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create variant.");
227  rv = mVariant->SetAsDouble(aValue);
228  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write variant.");
229  }
230 
231  nsIVariant* get() { return (mVariant); }
232 
233  static nsresult GetValue(nsIVariant* aVariant, PRInt16* aValue) {
234  return aVariant->GetAsInt16(aValue);
235  }
236 
237 private:
238  nsCOMPtr<nsIWritableVariant> mVariant;
239 };
240 
241 
251 class sbIPDURI
252 {
253 public:
254 
255  sbIPDURI(const char* aValue)
256  {
257  nsresult rv;
258  nsCOMPtr<nsIIOService> ioService =
259  do_GetService("@mozilla.org/network/io-service;1",
260  &rv);
261  NS_ENSURE_SUCCESS(rv, /* void */);
262  rv = ioService->NewURI(nsCAutoString(aValue),
263  nsnull,
264  nsnull,
265  getter_AddRefs(mURI));
266  NS_ENSURE_SUCCESS(rv, /* void */);
267  }
268 
269  nsIURI* get() { return (mURI); }
270 
271 private:
272  nsCOMPtr<nsIURI> mURI;
273 };
274 
275 
276 //------------------------------------------------------------------------------
277 //
278 // iPod device utility services prototypes.
279 //
280 //------------------------------------------------------------------------------
281 
283  (PRUint32 aType,
284  nsIVariant* aData = nsnull,
285  nsISupports* aOrigin = nsnull,
286  PRUint32 aDeviceState = sbIDevice::STATE_IDLE,
287  PRBool aAsync = PR_FALSE);
288 
289 
290 #endif /* __SB_IPD_UTILS_H__ */
291 
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData=nsnull, nsISupports *aOrigin=nsnull, PRUint32 aDeviceState=sbIDevice::STATE_IDLE, PRBool aAsync=PR_FALSE)
Definition: sbIPDUtils.cpp:72
sbIPDVariant(REFNSIID aIID, nsISupports *aValue)
Definition: sbIPDUtils.h:124
sbIPDVariant(const nsACString &aValue, PRUint16 aType=nsIDataType::VTYPE_CSTRING)
Definition: sbIPDUtils.h:142
sbIPDVariant(const nsAString &aValue)
Definition: sbIPDUtils.h:133
onPageChanged aValue
Definition: FeedWriter.js:1395
sbIPDVariant(PRUint64 aValue)
Definition: sbIPDUtils.h:213
sbIPDVariant(const char *aValue)
Definition: sbIPDUtils.h:155
sbIPDVariant(char aValue)
Definition: sbIPDUtils.h:164
var ioService
sbIPDURI(const char *aValue)
Definition: sbIPDUtils.h:255
sbIPDVariant(PRInt64 aValue)
Definition: sbIPDUtils.h:204
const unsigned long STATE_IDLE
Definition: sbIDevice.idl:220
sbIPDVariant(double aValue)
Definition: sbIPDUtils.h:222
sbIPDVariant(PRUint32 aValue, PRUint16 aType=nsIDataType::VTYPE_UINT32)
Definition: sbIPDUtils.h:191
SB_AUTO_CLASS(sbAutoGMemPtr, void *, mValue, g_free(mValue), mValue=NULL)
sbIPDVariant(PRInt32 aValue)
Definition: sbIPDUtils.h:182
_updateTextAndScrollDataForFrame aData
sbIPDVariant(nsISupports *aValue)
Definition: sbIPDUtils.h:115
static nsresult GetValue(nsIVariant *aVariant, PRInt16 *aValue)
Definition: sbIPDUtils.h:233
sbIPDVariant(PRInt16 aValue)
Definition: sbIPDUtils.h:173