Javatrans Symbian OS notes
Chris Greenhalgh, 2006-03-29; last update 2007-05-30
Introduction
This file (may) hold information specific Javatrans targetted to
Symbian OS.
Restrictions
Symbian is a real pain and makes the whole of the translated code much
more unreadable than it might be in ANSI C++/Posix. In particular:
- no multiple inheritance, even of pure virtual classes
- non-standard exceptions
Doh.
Threading issues
If using generated code from a Symbian application be aware that a
symbian application normally has only a single thread, and this thread
is the only thread which can perform UI operations (because the UI
libraries use thread-local storage).
Based on the approach used in Java Swing, under symbian the following
additional java_lang_Thread class methods can be used to (a) determine
if user code is being called from the main application thread or from
another (internal) thread and to (b) hand off calls to user code from
an internal thread to the main application thread via a Symbian active
object scheduled by the main thread (cf. the Swing event dispatch
thread). These methods are:
- static JAVA_BOOLEAN
java_lang_Thread::isFirstThread() - comparable to javax.swing.SwingUtilities.isEventDespatchThread(),
returns true if the calling thread is the main application thread and
can therefor call UI methods directly.
- static void java_lang_Thread::invokeLater(JavaPtr<java_lang_Runnable>
runnable) - calls the provided Runnable interface's void run()
method at some later time from the main thread.
- static void java_lang_Thread::invokeAndWait(JavaPtr<java_lang_Runnable>
runnable) - calls the provided Runnable interface's void run()
method and blocks until it completes. Note that this can result in
process deadlock if the main thread is unable to finish it current
acitvity(s) and return to its active scheduler. I.e. never call this
method if there is a change that you are also blocking the main thread.
As an additional convenience the following non-standard
java_lang_Thread constructor can be used to avoid having to defined
framework-supported subclasses of java_lang_Runnable in order to define
the code to be called using this mechanism:
- typedef void
(*NATIVE_THREAD_FN)(void* arg);
- java_lang_Thread::java_lang_Thread(NATIVE_THREAD_FN
fn, void *arg);
Sample code/projects
I have been developing/testing for Symbian using Symbian 8.0a series
60 FP2 SDK, and Carbide.vs with Visual Studio .NET 2003.
There are two solutions in CVS:
- ../symbian/equip2dll/equip2dll.sln,
which includes two sub-projects:
- ../symbian/test/test.sln,
which includees a single sub-project:
- ../symbian/test/test.vcproj
- which is a simple symbian GUI application which I have been using to
run the translated tests under symbian, passing the 'console' output to
a list display. This is a model for using a DLL such as the one above
to build an application based on the translated code.
Although set up to build under VC++ these include the normal Symbian
project and package files, and so should importable/buildable in other
IDEs/environments.
Known Issues
See Javatrans_introduction.html
Change Log
2006-03-29