IPDL/Five minute example: Difference between revisions
< IPDL
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
This page walks you through the steps of creating an IPDL protocol and writing the C++ code that implements the required interfaces. This guide walks you through the steps taken to implement the testing code in <code>ipc | This page walks you through the steps of creating an IPDL protocol and writing the C++ code that implements the required interfaces. This guide walks you through the steps taken to implement the testing code in <code>ipc/test-harness</code>. You are encouraged to follow this guide step-by-step and change the code in <code>ipc/test-harness</code> as you follow along. | ||
== Write the IPDL specification == | == Write the IPDL specification == | ||
Put this in the file <code>ipc | Put this in the file <code>ipc/test-harness/Test.ipdl</code>. | ||
namespace mozilla { | namespace mozilla { | ||
| Line 48: | Line 48: | ||
== Hook the IPDL file into our build system == | == Hook the IPDL file into our build system == | ||
* Add <code>ipc | * Add <code>ipc/test-harness</code> to the IPDLDIRS variable in <code>ipc/ipdl/Makefile.in</code> | ||
* Create the file <code>ipc | * Create the file <code>ipc/test-harness/ipdl.mk</code> and add the following text to it. | ||
IPDLSRCS = \ | IPDLSRCS = \ | ||
| Line 58: | Line 58: | ||
* Run | * Run | ||
ipc | ipc/test-harness$ python ../ipdl.py -d /tmp Test.ipdl | ||
* Open <code>/tmp/mozilla/test/TestProtocolParent.h</code>. Look for the text "Skeleton implementation of abstract actor class." | * Open <code>/tmp/mozilla/test/TestProtocolParent.h</code>. Look for the text "Skeleton implementation of abstract actor class." | ||
** copy the "Header file contents" into the file <code>ipc | ** copy the "Header file contents" into the file <code>ipc/test-harness/TestParent.h</code> | ||
** copy the "C++ file contents" into <code>ipc | ** copy the "C++ file contents" into <code>ipc/test-harness/TestParent.cpp</code> | ||
** globally replace the text <code>ActorImpl</code> with <code>TestParent</code> in both files. | ** globally replace the text <code>ActorImpl</code> with <code>TestParent</code> in both files. | ||
** set up namespaces as you wish. The checked-in example puts TestParent in the mozilla::test namespace. | ** set up namespaces as you wish. The checked-in example puts TestParent in the mozilla::test namespace. | ||
* Repeat the above step for <code>TestProtocolChild.h</code> and <code>TestChild.(h, cpp)</code> | * Repeat the above step for <code>TestProtocolChild.h</code> and <code>TestChild.(h, cpp)</code> | ||
== Hook the C++ stubs into your build configuration == | |||
This is beyond the scope of this guide. See <code>ipc/test-harness/Makefile.in</code> for an example. | |||
It's a good idea to check now that everything compiles. | |||
== Create the subprocess and "child main thread" classes == | |||
Revision as of 18:23, 13 July 2009
This page walks you through the steps of creating an IPDL protocol and writing the C++ code that implements the required interfaces. This guide walks you through the steps taken to implement the testing code in ipc/test-harness. You are encouraged to follow this guide step-by-step and change the code in ipc/test-harness as you follow along.
Write the IPDL specification
Put this in the file ipc/test-harness/Test.ipdl.
namespace mozilla {
namespace test {
sync protocol Test
{
both:
sync Ping() returns (int status);
parent:
GetValue(String key);
GetValues(StringArray keys);
sync SetValue(String key, String val) returns (bool ok);
child:
TellValue(String key, String val);
TellValues(StringArray keys, StringArray vals);
state START:
recv Ping goto START;
send Ping goto START;
recv SetValue goto HAVE_VALUES;
state HAVE_VALUES:
recv Ping goto HAVE_VALUES;
send Ping goto HAVE_VALUES;
recv SetValue goto HAVE_VALUES;
recv GetValue goto TELLING_VALUE;
recv GetValues goto TELLING_VALUES;
state TELLING_VALUE:
send TellValue goto HAVE_VALUES;
state TELLING_VALUES:
send TellValues goto HAVE_VALUES;
};
} // namespace test
} // namespace mozilla
Hook the IPDL file into our build system
- Add
ipc/test-harnessto the IPDLDIRS variable inipc/ipdl/Makefile.in - Create the file
ipc/test-harness/ipdl.mkand add the following text to it.
IPDLSRCS = \ Test.ipdl \ $(NULL)
Create the C++ implementation stubs
- Run
ipc/test-harness$ python ../ipdl.py -d /tmp Test.ipdl
- Open
/tmp/mozilla/test/TestProtocolParent.h. Look for the text "Skeleton implementation of abstract actor class."- copy the "Header file contents" into the file
ipc/test-harness/TestParent.h - copy the "C++ file contents" into
ipc/test-harness/TestParent.cpp - globally replace the text
ActorImplwithTestParentin both files. - set up namespaces as you wish. The checked-in example puts TestParent in the mozilla::test namespace.
- copy the "Header file contents" into the file
- Repeat the above step for
TestProtocolChild.handTestChild.(h, cpp)
Hook the C++ stubs into your build configuration
This is beyond the scope of this guide. See ipc/test-harness/Makefile.in for an example.
It's a good idea to check now that everything compiles.