30 #include <nsAutoLock.h>
32 #include <nsServiceManagerUtils.h>
33 #include <nsThreadUtils.h>
34 #include <nsIGenericFactory.h>
36 #include <sbIDevice.h>
37 #include <sbIDeviceEvent.h>
38 #include <sbIDeviceEventTarget.h>
39 #include <sbIDeviceManager.h>
41 #define STRESS_TEST_THREAD_COUNT 200
54 sbDeviceEventTesterStressThreads::~sbDeviceEventTesterStressThreads()
60 NS_IMETHODIMP sbDeviceEventTesterStressThreads::Run()
62 NS_ENSURE_FALSE(
mMonitor, NS_ERROR_ALREADY_INITIALIZED);
64 mMonitor = nsAutoMonitor::NewMonitor(__FILE__);
65 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_OUT_OF_MEMORY);
69 nsCOMPtr<sbIDeviceEventTarget>
target =
70 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
71 NS_ENSURE_SUCCESS(rv, rv);
73 rv = target->AddEventListener(static_cast<sbIDeviceEventListener*>(
this));
74 NS_ENSURE_SUCCESS(rv, rv);
80 nsCOMPtr<nsIRunnable>
event =
82 NS_ENSURE_TRUE(
event, NS_ERROR_OUT_OF_MEMORY);
84 nsCOMPtr<nsIThread> thread;
86 rv = NS_NewThread(getter_AddRefs(thread),
event);
87 NS_ENSURE_SUCCESS(rv, rv);
94 nsCOMPtr<nsIThread> thread =
mThreads[0];
96 NS_ENSURE_TRUE(succeeded, NS_ERROR_FAILURE);
97 rv = thread->Shutdown();
98 NS_ENSURE_SUCCESS(rv, rv);
101 rv = target->RemoveEventListener(static_cast<sbIDeviceEventListener*>(
this));
102 NS_ENSURE_SUCCESS(rv, rv);
104 NS_ENSURE_TRUE(
mCounter == 0, NS_ERROR_FAILURE);
110 NS_IMETHODIMP sbDeviceEventTesterStressThreads::OnDeviceEvent(
sbIDeviceEvent *aEvent)
114 if (!NS_IsMainThread()) {
115 NS_WARNING(
"Not on main thread!");
117 return NS_ERROR_UNEXPECTED;
123 void sbDeviceEventTesterStressThreads::OnEvent()
126 nsCOMPtr<sbIDeviceManager2> manager =
127 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
128 NS_ENSURE_SUCCESS(rv, );
130 nsCOMPtr<sbIDeviceEventTarget> target = do_QueryInterface(manager);
131 NS_ENSURE_SUCCESS(rv, );
133 nsCOMPtr<sbIDeviceEvent>
event;
139 getter_AddRefs(event));
140 NS_ENSURE_SUCCESS(rv, );
142 rv = target->DispatchEvent(event, PR_FALSE, nsnull);
143 NS_ENSURE_SUCCESS(rv, );
function succeeded(ch, cx, status, data)
#define STRESS_TEST_THREAD_COUNT
NS_IMPL_THREADSAFE_ISUPPORTS2(sbDeviceEventTesterStressThreads, nsIRunnable, sbIDeviceEventListener) sbDeviceEventTesterStressThreads
const unsigned long STATE_IDLE
const unsigned long EVENT_DEVICE_BASE
nsCOMArray< nsIThread > mThreads
_getSelectedPageStyle s i