See the source code for this example.