| C H A P T E R 4 |
|
Location API |
This chapter describes the JSR 179 Location API implementation in the Java Wireless Client software. It covers the structure of the source code, available implementations of its components, and a description of the porting steps both for the native layer and the JavaCall layer.
This chapter provides high level information about porting the Location API. For detailed information about each function in the porting layers, check out the API reference documentation that is included with the Java Wireless Client software.
The JSR 179 Location API enables mobile applications to determine their current location. This API covers obtaining information about the present geographic location and orientation of the terminal and accessing a database of known landmarks stored in the device.
This API is in a single package, javax.microedition.location.
In this chapter, jsr179-root is the root directory of the Location API source code and javacall-root is the root directory of the JavaCall API source code.
The Location API has two major parts corresponding to the public classes in javax.microedition.location:
These classes use some internal classes from com.sun.j2me.location.
LandmarkStore currently has two implementations:
The LandmarkStore implementation is chosen at compilation by assigning an appropriate value to JSR_179_STORE_IMPL option in jsr179-root/src/config/subsystem.gmk. See the makefile for the allowed values.
LocationProvider has only a platform_global implementation. A special dedicated layer of native interfaces is the porting layer.
The atan2 math function has two implementations:
The implementation of atan2 is chosen at compilation by assigning an appropriate value to JSR_179_ATAN2_IMPL in jsr179-root/src/config/subsystem.gmk.
Several internal properties in jsr179-root/src/config/common/properties_jsr179.xml define limitations of LandmarkStore:
The java_global implementation provides all functionality necessary for the Location API via some Java platform classes. This implementation does not have any interfaces to a platform. RMS record stores are used for the LandmarkStore implementation.
The platform_global implementation has a native porting layer for an efficient platform-dependent implementation of LandmarkStore. The platform_global implementation is appropriate if the LandmarkStore needs to be accessible from both Java platform applications and native applications.
The LocationProvider implementation has a dedicated native layer that hides all interactions with the device and is a porting layer for an efficient platform-dependent implementation.
Several internal properties in jsr179-root/src/config/common/properties_jsr179.xml define limitations of LocationProvider functionality:
The java_global implementation is platform independent.
The platform_global implementation is appropriate if your platform has its own optimized implementation.
The Location API source code is as follows:
jsr179-root/src
common - common classes
classes
com - implementation independent internal classes
javax - JSR 179 API package
native - native code for common part of JSR 179
share - platform independent parts of LocationProvider
linux - linux implemetation of LocationProvider
javacall - JavaCall API implemetation of LocationProvider
stubs - empty implementation of LocationProvider
config - files for build configuration
include - Native porting API header
java_global
classes
com - LandmarkStore implementation
native
math - atan2 implementation
platform_global
classes
com - LandmarkStore internal classes
native
javacall - JavaCall API implemetation of LandmarkStore and atan2
share - platform independent native source code
tests
i3test - the JSR 179 i3 tests
javacall-root
interface
jsr179_location - JavaCall API porting API headers
implementation
stubs
jsr179_location empty implementations
win32
jsr179_location win32 implementations
The major purpose of the porting API is an interaction with your device's location hardware to access location information a platform database of landmarks.
The platform_global implementation could be presented as the following set of layers:
FIGURE 4-1 Location API code structure
This document naturally focuses on the native porting API and the JavaCall porting API. All the platform-dependent functionality is placed in this code layer. To make the Location API work on a new platform, you must implement all the functions below the native or JavaCall porting API for the given target.
This API covers accessing a database of known landmarks stored in the terminal and the present geographic location and orientation of the terminal.
Here are optional features whose availability depends on the landmark store implementation of the device and its possible relation to landmark stores shared with native applications:
The porting layer includes the following:
To calculate distance or azimuth, a platform-independent atan2 function implementation is provided. However, if your device can calculate atan2 by means of a native math library, it is efficient to use it.
The acquired location includes the following information:
For the specified location provider, the following infomation is provided:
Following are the optional features whose availability depends on the used location methods:
The porting layer includes the following functionality:
The following features are optionally supported:
If the implementation chooses to support orientation, it must provide the azimuth information. Providing pitch and roll is optional.
The porting layer includes the following functionality:
This section describes general principles of the Location API.
Some functions operate asynchronously. In this case, the function returns quickly with JSR179_STATUSCODE_WOULD_BLOCK. When the operation completes, an event is required to be sent from the platform. See section on events for related information.
The following are the asynchronous functions:
The following rules apply to buffer allocation:
The exceptional cases are enumeration functions like *list_next(), which have the following rules:
If com.sun.j2me.location.CreateLandmarkStoreSupported is set to true, implement jsr179_landmarkstore_create().
If com.sun.j2me.location.DeleteLandmarkStoreSupported is set to true, implement jsr179_landmarkstore_delete().
If com.sun.j2me.location.DeleteCategorySupported is set to true, implement jsr179_category_delete().
The following functions can be implemented to obtain additional location information:
The following functions shall be implemented if com.sun.j2me.location.OrientationSupported is set to true:
The following functions shall be implemented if com.sun.j2me.location.ProximitySupported is set to true:
jsr179_atan2() should be implemented if the platform_global implementation of atan2 is chosen in jsr179-root/src/config/subsystem.gmk.
You must implement jsr179_notify_location_event().
If com.sun.j2me.location.ProximitySupported is set to true, implement jsr179_notify_location_proximity().
This section explains how the JSR 179 code can be ported to a new platform. The new platform is represented here as new-platform.
1. Create new-platform directory in jsr179-root/src/common/native.
2. Create jsr179_locationProvider_impl.c file in jsr179-root/src/common/native/new-platform and implement LocationProvider functions according to your platform.
3. Set values for com.sun.j2me.location.OrientationSupported and com.sun.j2me.location.ProximitySupported in jsr179-root/src/config/common/properties_jsr179.xml.
1. Create new-platform directory in jsr179-root/src/platform_global/native.
2. Create jsr179_landmarkStore_impl.c in jsr179-root/src/platform_global/native/new-platform and implement LandmarkStore functions according to your platform.
3. Set values for com.sun.j2me.location.CreateLandmarkStoreSupported, com.sun.j2me.location.DeleteLandmarkStoreSupported and com.sun.j2me.location.DeleteCategorySupported in jsr179-root/src/config/common/properties_jsr179.xml file.
4. Set JSR_179_STORE_IMPL to platform in jsr179-root/src/config/subsystem.gmk.
1. Create new-platform directory in jsr179-root/src/platform_global/native.
2. Create jsr179_math_kni.c in jsr179-root/src/common/native/new-platform and implement jsr179_atan2() for your platform.
3. Set JSR_179_ATAN2_IMPL to platform in jsr179-root/src/config/subsystem.gmk.
The location functions in the JavaCall API are much like the native porting functions, but porting occurs in a different layer.
The following optional features' availability depends on the landmark store implementation of the device and its possible relation to landmark stores shared with native applications:
The porting layer includes the following functionality:
To calculate distance or azimuth, the platform independent atan2 function implementation is provided. However, if your platform provides atan2 functionality by means of a native math library, it is more efficient to use it.
The acquired location should include following information:
For the specified location provider, the following infomation should be provided:
The following optional features' availability depends on the used location methods.
The porting layer includes the following functionality:
The following features are optionally supported:
If the implementation chooses to support orientation, it must provide the azimuth information. Providing pitch and roll is optional.
The porting layer includes the following functionality:
This section describes general principles of the Location API.
Some functions operate asynchronously. In this case, the function returns quickly with JAVACALL_WOULD_BLOCK. When the operation completes, an event is required to be sent from the platform. See the section on events for related information.
The asynchronous functions are as follows:
All unicode strings used in this API are NULL terminated.
The following rules apply to buffer allocation:
The exceptional cases are enumeration functions like *list_next(), which have the following rules:
If com.sun.j2me.location.CreateLandmarkStoreSupported is set to true, implement javacall_landmarkstore_create().
If com.sun.j2me.location.DeleteLandmarkStoreSupported is set to true, implement javacall_landmarkstore_delete().
If com.sun.j2me.location.DeleteCategorySupported is set to true, implement javacall_landmarkstore_category_delete().
Implement the following functions to obtain additional location information:
If com.sun.j2me.location.OrientationSupported is set to true, implement javacall_location_orientation_start() and javacall_location_orientation_finish().
If com.sun.j2me.location.ProximitySupported is set to true, implement javacall_location_proximity_monitoring_add() and javacall_location_proximity_monitoring_cancel().
Implement jsr179_atan2 if platform_global implementation of atan2 is chosen in jsr179-root/src/config/subsystem.gmk.
You must implement javanotify_location_event().
If com.sun.j2me.location.ProximitySupported is set to true, implement javanotify_location_proximity().
This section explains how the JSR 179 code can be ported to a new platform using the JavaCall API. The new platform is represented here as new-platform.
1. Create new-platform/jsr179_location directory in javacall-com/implementation directory.
Copy location.c from javacall-com/implementation/win32/jsr179_location to the new-platform/jsr179_location directory.
2. Rewrite functions in your new location.c according to the platform specifics.
3. Set the appropriate values for com.sun.j2me.location.OrientationSupported and com.sun.j2me.location.ProximitySupported properties in jsr179-root/src/config/common/properties_jsr179.xml.
1. Create new-platform/jsr179_location directory in javacall-com/implementation directory.
2. Copy landmarkstore.c from javacall-com/implementation/win32/jsr179_location to the new-platform/jsr179_location directory.
3. Rewrite functions in your new landmarkstore.c according to the platform specifics.
4. Set the appropriate values for com.sun.j2me.location.CreateLandmarkStoreSupported, com.sun.j2me.location.DeleteLandmarkStoreSupported and com.sun.j2me.location.DeleteCategorySupported in jsr179-root/src/config/common/properties_jsr179.xml.
5. Set value for JSR_179_STORE_IMPL to platform in jsr179-root/src/config/subsystem.gmk file.
1. Create new-platform/jsr179_location directory in javacall-com/implementation directory.
2. Copy location.c from javacall-com/implementation/win32/jsr179_location to the new-platform/jsr179_location directory.
3. Rewrite javacall_location_atan2() in your new location.c according to the platform specifics.
4. Set value for JSR_179_ATAN2_IMPL variable to platform in jsr179-root/src/config/subsystem.gmk file.
Copyright © 2007, Sun Microsystems, Inc. All rights reserved. SUN PROPRIETARY/CONFIDENTIAL.