|
This chapter describes the first steps in porting MIDP. By the end of the chapter, you will have a quick port of the MIDP Reference Implementation that compiles and should run the Hello MIDlet, but may not be fully functional. You will need to do additional work to complete the port and to tailor it for your device. The chapters after this one discuss those possibilities.
This chapter contains the sections:
This chapter assumes familiarity with the MIDP overview described in the previous chapter and the MIDP 2.0 Specification. The MIDP specification is at http://jcp.org/jsr/detail/118.jsp.
Do the following tasks before beginning a MIDP port:
The directories to create are:
where newPlatform is the name for the directory that hold the files for your device. For example, if midpInstallDir was c:\midp2.0fcs and your device was deviceX, you would execute the commands:
c:\midp2.0fcs\build> mkdir deviceX c:\midp2.0fcs\build> cd ..\src c:\midp2.0fcs\src> mkdir deviceX c:\midp2.0fcs\src> cd deviceX c:\midp2.0fcs\src\deviceX> mkdir native
\build\newPlatform directory.
For example, you could copy the files from midpInstallDir\src\solaris:
\build\newPlatform directory.Copy:
For example, you could copy the files from midpInstallDir\build\solaris:
c:\midp2.0fcs\build> cp solaris/GNUmakefile deviceX c:\midp2.0fcs\build> cp solaris/platform.gmk deviceX c:\midp2.0fcs\build> cp -r solaris/makefiles deviceX
See Appendix B, “Configuration Options” configuration options that you might need to set for porting. Typical options that need updating are:
GCCPLATFORMMIDP_EXCLUDE_CLASSESMIDP_INCLUDE_SRC_BOOTDIRDEBUG
For example, to make the value of the PLATFORM option deviceX, you would update the PLATFORM definition in the c:\midp2.0fcs\build\deviceX\platform.gmk file to:
If you have already ported CLDC, use those makefiles as a guide.
The makefile targets have the MIDP executable run inside the device emulator with debugging symbols, without debugging symbols, with profiling code, and so on. See Appendix A, “Build Targets” for a list of existing targets. You might want to add targets that include or exclude device-specific features, such as optional communication protocols.
To start porting MIDP, do the following tasks:
There are five allocation macros for managing the memory of the native heap:
The macros are defined in midpInstallDir\src\share\native\midpMalloc.h. Change the definitions of these macros, if necessary, to work with your device.
The files with native calls are in the following directories:
For example, if your system does not support a native call, substitute in a call that has the same functionality, or create a stub for it. To create a stub, comment out or remove the function body that contains the call, and substitute a print statement. One way to find these calls is by trying to build MIDP to see which calls prompt errors. (For instructions on building MIDP, see Using MIDP.) The errors could look something like this:
The stub that you create for the call could look something like this:
This step enables you to quickly get your port compiling. As you go through the chapters that follow, you will fill in the stubs as you port each module.
Ensure that the printf function sends its output to a location from which it is easy for you to collect information. For example, one such destination might be the debug port of your emulator. (If you have already ported CLDC, this step should already be done.)
Try out your port at this point:
In the MIDP Reference Implementation, the midp target in the build environment builds a ROMized version of MIDP. If you have not changed this aspect of the makefiles, then you would be able to use a command such as this:
For instructions on building MIDP, see Chapter 12, “Building Your Port.”
The following version of the HelloMIDlet does not use any graphics. It prints simple messages to the serial port of the device:
import javax.microedition.midlet.*; public class HelloWorld extends MIDlet { public HelloWorld() { system.out.println(“In HelloWorld constructor”); } public void startApp() { System.out.println(“In HelloWorld startapp”); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
|
Porting MIDP MIDP Reference Implementation, Version 2.0 FCS |
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.