58 #include <nsAutoPtr.h>
60 #include <nsServiceManagerUtils.h>
61 #include <nsIGenericFactory.h>
63 #include <sbIDevice.h>
64 #include <sbIDeviceEvent.h>
65 #include <sbIDeviceEventTarget.h>
66 #include <sbIDeviceManager.h>
78 sbDeviceEventTesterRemoval::~sbDeviceEventTesterRemoval()
84 NS_IMETHODIMP sbDeviceEventTesterRemoval::Run()
87 nsCOMPtr<sbIDeviceManager2> manager =
88 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
89 NS_ENSURE_SUCCESS(rv, rv);
91 nsCOMPtr<sbIDeviceEventTarget>
target = do_QueryInterface(manager, &rv);
92 NS_ENSURE_SUCCESS(rv, rv);
95 nsRefPtr<sbDeviceEventTesterRemovalHelper> listenerA =
97 NS_ENSURE_TRUE(listenerA, NS_ERROR_OUT_OF_MEMORY);
99 rv = target->AddEventListener(listenerA);
100 NS_ENSURE_SUCCESS(rv, rv);
102 nsRefPtr<sbDeviceEventTesterRemovalHelper> listenerB =
104 NS_ENSURE_TRUE(listenerB, NS_ERROR_OUT_OF_MEMORY);
106 rv = target->AddEventListener(listenerB);
107 NS_ENSURE_SUCCESS(rv, rv);
109 nsRefPtr<sbDeviceEventTesterRemovalHelper> listenerC =
111 NS_ENSURE_TRUE(listenerC, NS_ERROR_OUT_OF_MEMORY);
113 rv = target->AddEventListener(listenerC);
114 NS_ENSURE_SUCCESS(rv, rv);
116 nsRefPtr<sbDeviceEventTesterRemovalHelper> listenerD =
118 NS_ENSURE_TRUE(listenerD, NS_ERROR_OUT_OF_MEMORY);
122 rv = listenerA->SetFlag(0, PR_TRUE);
123 NS_ENSURE_SUCCESS(rv, rv);
127 NS_ENSURE_SUCCESS(rv, rv);
131 NS_ENSURE_SUCCESS(rv, rv);
135 NS_ENSURE_SUCCESS(rv, rv);
139 NS_ENSURE_SUCCESS(rv, rv);
144 NS_ENSURE_SUCCESS(rv, rv);
149 NS_ENSURE_SUCCESS(rv, rv);
153 NS_ENSURE_SUCCESS(rv, rv);
157 NS_ENSURE_SUCCESS(rv, rv);
161 NS_ENSURE_SUCCESS(rv, rv);
166 NS_ENSURE_SUCCESS(rv, rv);
170 NS_ENSURE_SUCCESS(rv, rv);
174 NS_ENSURE_SUCCESS(rv, rv);
178 NS_ENSURE_SUCCESS(rv, rv);
180 nsCOMPtr<sbIDeviceEvent>
event;
186 getter_AddRefs(event));
187 NS_ENSURE_SUCCESS(rv, rv);
189 rv = target->DispatchEvent(event, PR_FALSE, nsnull);
190 NS_ENSURE_SUCCESS(rv, rv);
192 rv = target->DispatchEvent(event, PR_FALSE, nsnull);
193 NS_ENSURE_SUCCESS(rv, rv);
210 return mActions.AppendElement(aAction) ?
NS_OK : NS_ERROR_FAILURE;
215 return mFlags.Put(aFlag, aSet) ?
NS_OK : NS_ERROR_OUT_OF_MEMORY;
219 NS_IMETHODIMP sbDeviceEventTesterRemovalHelper::OnDeviceEvent(
sbIDeviceEvent *aEvent)
231 nsCOMPtr<sbIDeviceEventTarget>
target;
232 rv = aEvent->GetTarget(getter_AddRefs(target));
233 NS_ENSURE_SUCCESS(rv, rv);
235 for (
int index = 0; index < length; ++index) {
236 printf(
"Removal event: %c#%i\n",
mName, index);
245 NS_ENSURE_SUCCESS(rv, rv);
250 NS_ENSURE_TRUE(succeeded, NS_ERROR_FAILURE);
256 PRBool
value = PR_FALSE;
262 PRBool value = PR_FALSE;
269 length = index + 1 +
mActions[index].count;
275 nsCOMPtr<sbIDeviceManager2> manager =
276 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
278 rv = aEvent->GetType(&eventType);
279 NS_ENSURE_SUCCESS(rv, rv);
281 nsCOMPtr<sbIDeviceEvent>
event;
282 rv = manager->CreateEvent(eventType,
287 getter_AddRefs(event));
288 NS_ENSURE_SUCCESS(rv, rv);
290 nsCOMPtr<sbIDeviceEventTarget>
target;
291 rv = aEvent->GetTarget(getter_AddRefs(target));
292 NS_ENSURE_SUCCESS(rv, rv);
293 rv = target->DispatchEvent(event, PR_FALSE, nsnull);
294 NS_ENSURE_SUCCESS(rv, rv);
nsresult AddAction(ACTION_TYPE aType, PRBool aSet, sbIDeviceEventListener *aListener)
const unsigned long EVENT_CLIENT_DEFINED
function succeeded(ch, cx, status, data)
nsTArray< ACTION > mActions
nsresult SetFlag(PRUint32 aFlag, PRBool aSet)
const unsigned long STATE_IDLE
nsTArray< nsRefPtr< sbDeviceEventTesterRemovalHelper > > mListeners
nsDataHashtableMT< nsUint32HashKey, PRBool > mFlags
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceEventTesterRemoval, nsIRunnable) sbDeviceEventTesterRemoval