Skip to content

Instantly share code, notes, and snippets.

@suvirbhargav
Created December 30, 2016 15:34
Show Gist options
  • Save suvirbhargav/17b47af580f3f90b0ff29f87c60e3fd2 to your computer and use it in GitHub Desktop.
Save suvirbhargav/17b47af580f3f90b0ff29f87c60e3fd2 to your computer and use it in GitHub Desktop.
Sample of writing runnable for firefox xulrunner based code.
Header
=======
#ifndef PROFILER_RUNNABLES_H_
#define PROFILER_RUNNABLES_H_
#include <vector>
//#include "base/scoped_ptr.h"
#include "nsCOMPtr.h"
#include "nsIRunnable.h"
class IActivityProfilerEvent;
class IActivityProfilerTimelineEventCallback;
class nsIThread;
namespace activity {
class CallGraphProfileSnapshot;
class GetTimelineEventsRunnable : public nsIRunnable {
private:
//typedef std::vector<nsCOMPtr<IActivityProfilerEvent> > EventVector;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRUNNABLE
GetTimelineEventsRunnable();
private:
~GetTimelineEventsRunnable();
};
} // namespace activity
#endif // PROFILER_RUNNABLES_H_
cpp source
==========
namespace activity {
GetTimelineEventsRunnable::GetTimelineEventsRunnable() {}
GetTimelineEventsRunnable::~GetTimelineEventsRunnable() {}
NS_IMETHODIMP GetTimelineEventsRunnable::Run() {
std::cout << " GetTimelineEventsRunnable:Run!!!!!!!!!!!!!!!!!" << "\n" ;
return NS_OK;
}
}
// important to do below.
NS_IMPL_THREADSAFE_ISUPPORTS1(activity::GetTimelineEventsRunnable, nsIRunnable)
To call
=======
activity::GetTimelineEventsRunnable *get_timeline_events_runnable =
new activity::GetTimelineEventsRunnable();
nsresult rv = NS_DispatchToMainThread(get_timeline_events_runnable);
NS_ENSURE_SUCCESS(rv, rv);
# You should see runnable print in output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment