Changes

Jump to: navigation, search

IPDL/Five minute example

2,772 bytes added, 00:17, 14 July 2009
Get the subprocess to launch
== Get the subprocess to launch ==
 
Here we reach a fork in the road of implementation. You can either continue to follow this guide, which will walk through creating a new, dummy, non-Firefox main process, or you can roughly follow the steps here but adapt them so that they end up launching your subprocess class from the existing Firefox process.
 
'''REMEMBER''': these steps create a new, non-Firefox main process.
 
Create the directory <code>ipc/test-harness/app</code> and see that it gets added to the <code>TOOL_DIRS</code> var in your Makefile. Create the file <code>ipc/test-harness/app/TestApp.cpp</code> with the following content.
#include "nsXULAppAPI.h"
#if defined(XP_WIN)
#include <windows.h>
#include "nsWindowsWMain.cpp"
#endif
int
main(int argc, char* argv[])
{
return XRE_RunIPCTestHarness(argc, argv);
}
 
Now re-open <code>xpcom/build/nsXULAppAPI.h</code> and add the declaration
XRE_API(int,
XRE_RunTestHarness, (int aArgc,
char* aArgv[]))
 
Re-open <code>toolkit/xre/nsEmbedFunctions.cpp</code>. See that
#include "mozilla/test/TestProcessParent.h"
#include "mozilla/test/TestParent.h"
using mozilla::test::TestProcessParent;
using mozilla::test::TestParent;
get added somewhere in the file. Add the following code.
 
//-----------------------------------------------------------------------------
// TestHarness
static void
TestHarnessMain(TestProcessParent* subprocess)
{
TestParent parent;
parent.Open(subprocess->GetChannel());
parent.DoStuff();
}
static void
TestHarnessLaunchSubprocess(TestProcessParent* subprocess,
MessageLoop* mainLoop)
{
NS_ASSERTION(subprocess->Launch(), "can't launch subprocess");
mainLoop->PostTask(FROM_HERE,
NewRunnableFunction(TestHarnessMain, subprocess));
}
static void
TestHarnessPostLaunchSubprocessTask(void* data)
{
TestProcessParent* subprocess = new TestProcessParent();
MessageLoop* ioLoop =
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
ioLoop->PostTask(FROM_HERE,
NewRunnableFunction(TestHarnessLaunchSubprocess,
subprocess,
MessageLoop::current()));
}
int
XRE_RunTestHarness(int aArgc, char* aArgv[])
{
nsresult rv =
XRE_InitParentProcess(
aArgc, aArgv, TestHarnessPostLaunchSubprocessTask, NULL);
NS_ENSURE_SUCCESS(rv, 1);
return 0;
}
 
(Sorry, this CPS-like code is a little hard to follow.)
 
This code will not compile because <code>TestParent::DoStuff()</code> has not been implemented. Everything else is set up though!
 
== Make the TestParent/TestChild do stuff ==
Confirm
699
edits

Navigation menu