sbDeviceFirmwareSupport.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-2010 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 
26 
27 #include <nsIClassInfoImpl.h>
28 #include <nsIProgrammingLanguage.h>
29 #include <nsIMutableArray.h>
30 #include <nsISimpleEnumerator.h>
31 #include <nsISupportsPrimitives.h>
32 
33 #include <nsAutoLock.h>
34 #include <nsComponentManagerUtils.h>
35 #include <nsMemory.h>
36 #include <nsXPCOMCID.h>
37 
40 
44 
45 NS_IMPL_CI_INTERFACE_GETTER1(sbDeviceFirmwareSupport,
46  sbIDeviceFirmwareSupport)
47 
48 NS_DECL_CLASSINFO(sbDeviceFirmwareSupport)
49 NS_IMPL_THREADSAFE_CI(sbDeviceFirmwareSupport)
50 
51 sbDeviceFirmwareSupport::sbDeviceFirmwareSupport()
52 : mMonitor(nsnull)
53 {
54 }
55 
56 sbDeviceFirmwareSupport::~sbDeviceFirmwareSupport()
57 {
58  if(mMonitor) {
59  nsAutoMonitor::DestroyMonitor(mMonitor);
60  }
61 }
62 
63 /* readonly attribute AString deviceFriendlyName; */
64 NS_IMETHODIMP
65 sbDeviceFirmwareSupport::GetDeviceFriendlyName(nsAString & aDeviceFriendlyName)
66 {
67  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
68 
69  nsAutoMonitor mon(mMonitor);
70  aDeviceFriendlyName = mDeviceFriendlyName;
71 
72  return NS_OK;
73 }
74 
75 /* readonly attribute unsigned long deviceVendorID; */
76 NS_IMETHODIMP
77 sbDeviceFirmwareSupport::GetDeviceVendorID(PRUint32 *aDeviceVendorID)
78 {
79  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
80  NS_ENSURE_ARG_POINTER(aDeviceVendorID);
81 
82  nsAutoMonitor mon(mMonitor);
83  *aDeviceVendorID = mDeviceVendorID;
84 
85  return NS_OK;
86 }
87 
88 /* readonly attribute nsISimpleEnumerator deviceProductIDs; */
89 NS_IMETHODIMP
90 sbDeviceFirmwareSupport::GetDeviceProductIDs(nsISimpleEnumerator * *aDeviceProductIDs)
91 {
92  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
93  NS_ENSURE_ARG_POINTER(aDeviceProductIDs);
94 
95  nsAutoMonitor mon(mMonitor);
96 
97  nsresult rv = mDeviceProductIDs->Enumerate(aDeviceProductIDs);
98  NS_ENSURE_SUCCESS(rv, rv);
99 
100  return NS_OK;
101 }
102 
103 /* void init (in AString aDeviceName, in unsigned long aVendorID, in nsISimpleEnumerator aDeviceProductIDs); */
104 NS_IMETHODIMP
105 sbDeviceFirmwareSupport::Init(const nsAString & aDeviceName,
106  PRUint32 aVendorID,
107  nsISimpleEnumerator *aDeviceProductIDs)
108 {
109  NS_ENSURE_ARG_POINTER(aDeviceProductIDs);
110  NS_ENSURE_FALSE(mMonitor, NS_ERROR_ALREADY_INITIALIZED);
111  NS_ENSURE_FALSE(mDeviceProductIDs, NS_ERROR_ALREADY_INITIALIZED);
112 
113  mMonitor = nsAutoMonitor::NewMonitor("sbDeviceFirmwareSupport::mMonitor");
114  NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
115 
116  mDeviceFriendlyName = aDeviceName;
117  mDeviceVendorID = aVendorID;
118 
119  nsresult rv = NS_ERROR_UNEXPECTED;
120  PRBool hasMore = PR_FALSE;
121 
122  nsCOMPtr<nsIMutableArray> productIDs =
123  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
124  NS_ENSURE_SUCCESS(rv, rv);
125 
126  while(NS_SUCCEEDED(rv = aDeviceProductIDs->HasMoreElements(&hasMore)) &&
127  hasMore) {
128  nsCOMPtr<nsISupports> element;
129  rv = aDeviceProductIDs->GetNext(getter_AddRefs(element));
130  NS_ENSURE_SUCCESS(rv, rv);
131 
132  nsCOMPtr<nsISupportsPRUint32> productID = do_QueryInterface(element, &rv);
133  NS_ENSURE_SUCCESS(rv, rv);
134 
135  rv = productIDs->AppendElement(productID, PR_FALSE);
136  NS_ENSURE_SUCCESS(rv, rv);
137  }
138 
139  mDeviceProductIDs = productIDs;
140 
141  return NS_OK;
142 }
143 
144 NS_IMETHODIMP
145 sbDeviceFirmwareSupport::SimpleInit(const nsAString & aDeviceName,
146  PRUint32 aVendorID,
147  PRUint32 aProductID)
148 {
149  NS_ENSURE_FALSE(mMonitor, NS_ERROR_ALREADY_INITIALIZED);
150  NS_ENSURE_FALSE(mDeviceProductIDs, NS_ERROR_ALREADY_INITIALIZED);
151 
152  mMonitor = nsAutoMonitor::NewMonitor("sbDeviceFirmwareSupport::mMonitor");
153  NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
154 
155  nsresult rv = NS_ERROR_UNEXPECTED;
156 
158  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
159  NS_ENSURE_SUCCESS(rv, rv);
160 
161  mDeviceFriendlyName = aDeviceName;
162  mDeviceVendorID = aVendorID;
163 
164  nsCOMPtr<nsISupportsPRUint32> productID =
165  do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
166  NS_ENSURE_SUCCESS(rv, rv);
167 
168  rv = productID->SetData(aProductID);
169  NS_ENSURE_SUCCESS(rv, rv);
170 
171  rv = mDeviceProductIDs->AppendElement(productID, PR_FALSE);
172  NS_ENSURE_SUCCESS(rv, rv);
173 
174  return NS_OK;
175 }
176 
177 NS_IMETHODIMP
178 sbDeviceFirmwareSupport::AppendProductID(PRUint32 aProductID)
179 {
180  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
181 
182  nsresult rv = NS_ERROR_UNEXPECTED;
183 
184  nsAutoMonitor mon(mMonitor);
185 
186  nsCOMPtr<nsISupportsPRUint32> productID =
187  do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
188  NS_ENSURE_SUCCESS(rv, rv);
189 
190  rv = productID->SetData(aProductID);
191  NS_ENSURE_SUCCESS(rv, rv);
192 
193  rv = mDeviceProductIDs->AppendElement(productID, PR_FALSE);
194  NS_ENSURE_SUCCESS(rv, rv);
195 
196  return NS_OK;
197 }
NS_IMPL_QUERY_INTERFACE2_CI(sbDeviceFirmwareSupport, sbIDeviceFirmwareSupport, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER1(sbDeviceFirmwareSupport
return NS_OK
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
function Init()
nsCOMPtr< nsIMutableArray > mDeviceProductIDs
StringArrayEnumerator prototype hasMore
sbIJobCancelable NS_DECL_CLASSINFO(sbGstreamerMediaInspector)
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery