31 #include <nsAutoLock.h>
32 #include <nsComponentManagerUtils.h>
33 #include <nsISimpleEnumerator.h>
34 #include <nsIProperty.h>
46 static PRLogModuleInfo* gDevicePropertiesLog = nsnull;
47 #define TRACE(args) PR_LOG(gDevicePropertiesLog, PR_LOG_DEBUG, args)
48 #define LOG(args) PR_LOG(gDevicePropertiesLog, PR_LOG_WARN, args)
55 isInitialized(PR_FALSE)
58 if (!gDevicePropertiesLog) {
59 gDevicePropertiesLog = PR_NewLogModule(
"sbDeviceProperties");
62 mLock = nsAutoLock::NewLock(
"sbDevicePropertiesLock");
65 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/sbpropertybag;1");
68 TRACE((
"sbDeviceProperties[0x%.8x] - Constructed",
this));
72 sbDeviceProperties::~sbDeviceProperties()
74 TRACE((
"sbDeviceProperties[0x%.8x] - Destructed",
this));
76 nsAutoLock::DestroyLock(
mLock);
82 sbDeviceProperties::InitFriendlyName(
const nsAString & aFriendlyName)
88 NS_ENSURE_SUCCESS(rv, rv);
94 sbDeviceProperties::InitDefaultName(
const nsAString & aDefaultName)
101 NS_ENSURE_SUCCESS(rv, rv);
107 sbDeviceProperties::InitVendorName(
const nsAString & aVendorName)
109 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
114 NS_ENSURE_SUCCESS(rv, rv);
120 sbDeviceProperties::InitModelNumber(nsIVariant *aModelNumber)
122 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
127 NS_ENSURE_SUCCESS(rv, rv);
133 sbDeviceProperties::InitSerialNumber(nsIVariant *aSerialNumber)
135 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
141 NS_ENSURE_SUCCESS(rv, rv);
147 sbDeviceProperties::InitFirmwareVersion(
const nsAString &aFirmwareVersion)
149 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
155 NS_ENSURE_SUCCESS(rv, rv);
161 sbDeviceProperties::InitDeviceLocation(nsIURI *aDeviceLocationUri)
163 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
169 sbDeviceProperties::InitDeviceIcon(nsIURI *aDeviceIconUri)
171 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
177 sbDeviceProperties::InitDeviceProperties(nsIPropertyBag2 *aProperties)
179 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
180 NS_ENSURE_ARG_POINTER(aProperties);
186 nsCOMPtr<nsISimpleEnumerator> enumerator;
187 rv = aProperties->GetEnumerator(getter_AddRefs(enumerator));
188 NS_ENSURE_SUCCESS(rv, rv);
190 nsCOMPtr<nsIProperty> property;
192 nsCOMPtr<nsIVariant>
value;
195 while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
196 rv = enumerator->GetNext(getter_AddRefs(property));
197 NS_ENSURE_SUCCESS(rv, rv);
199 rv =
property->GetName(name);
200 NS_ENSURE_SUCCESS(rv, rv);
202 rv =
property->GetValue(getter_AddRefs(value));
203 NS_ENSURE_SUCCESS(rv, rv);
206 NS_ENSURE_SUCCESS(rv, rv);
212 sbDeviceProperties::InitDone()
214 NS_ENSURE_TRUE(!
isInitialized, NS_ERROR_ALREADY_INITIALIZED);
223 nsAString
const & aProp,
227 value.SetIsVoid(PR_TRUE);
229 nsresult rv = aProperties->GetPropertyAsAString(aProp,
231 if (rv != NS_ERROR_NOT_AVAILABLE) {
232 NS_ENSURE_SUCCESS(rv, rv);
240 nsAString
const & aProp,
243 nsresult rv = aProperties->GetProperty(aProp, aValue);
244 if (rv == NS_ERROR_NOT_AVAILABLE) {
248 NS_ENSURE_SUCCESS(rv, rv);
254 sbDeviceProperties::GetFriendlyName(nsAString & aFriendlyName)
258 nsAutoLock lock(
mLock);
265 sbDeviceProperties::SetFriendlyName(
const nsAString & aFriendlyName)
269 nsAutoLock lock(
mLock);
273 NS_ENSURE_SUCCESS(rv, rv);
279 sbDeviceProperties::GetDefaultName(nsAString & aDefaultName)
283 nsAutoLock lock(
mLock);
290 sbDeviceProperties::GetVendorName(nsAString & aVendorName)
294 nsAutoLock lock(
mLock);
302 sbDeviceProperties::GetModelNumber(nsIVariant * *aModelNumber)
305 NS_ENSURE_ARG_POINTER(aModelNumber);
307 nsAutoLock lock(
mLock);
315 sbDeviceProperties::GetSerialNumber(nsIVariant * *aSerialNumber)
318 NS_ENSURE_ARG_POINTER(aSerialNumber);
320 nsAutoLock lock(
mLock);
328 sbDeviceProperties::GetFirmwareVersion(nsAString &aFirmwareVersion)
332 nsAutoLock lock(
mLock);
340 sbDeviceProperties::GetUri(nsIURI * *aUri)
343 NS_ENSURE_ARG_POINTER(aUri);
345 nsAutoLock lock(
mLock);
352 sbDeviceProperties::GetIconUri(nsIURI * *aIconUri)
355 NS_ENSURE_ARG_POINTER(aIconUri);
357 nsAutoLock lock(
mLock);
364 sbDeviceProperties::GetProperties(nsIPropertyBag2 * *aProperties)
367 NS_ENSURE_ARG_POINTER(aProperties);
369 nsAutoLock lock(
mLock);
376 sbDeviceProperties::SetHidden(PRBool aHidden)
380 nsAutoLock lock(
mLock);
384 NS_ENSURE_SUCCESS(rv, rv);
390 sbDeviceProperties::GetHidden(PRBool *aHidden)
393 NS_ENSURE_ARG_POINTER(aHidden);
395 nsAutoLock lock(
mLock);
399 NS_ENSURE_SUCCESS(rv, rv);
#define SB_DEVICE_PROPERTY_HIDDEN
#define SB_DEVICE_PROPERTY_MANUFACTURER
#define SB_DEVICE_PROPERTY_DEFAULT_NAME
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
static nsresult GetProperty(nsIPropertyBag2 *aProperties, nsAString const &aProp, nsAString &aValue)
nsCOMPtr< nsIURI > mDeviceLocation
#define SB_DEVICE_PROPERTY_FIRMWARE_VERSION
nsCOMPtr< nsIWritablePropertyBag > mProperties
#define SB_DEVICE_PROPERTY_NAME
nsCOMPtr< nsIURI > mDeviceIcon
nsCOMPtr< nsIWritablePropertyBag2 > mProperties2
#define SB_DEVICE_PROPERTY_SERIAL_NUMBER
#define SB_DEVICE_PROPERTY_MODEL
PRPackedBool isInitialized
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEPROPERTIES sbDeviceProperties()