OpenAlchemy Application Tour
From OpenAlchemy.org
If you are the creator of engaging applications on handheld devices and you need to know how you can create applications using OpenAlchemy you are in the right place.
The OpenAlchemy SDK enables you to create applications using any of the following programming languages Perl, Tcl/tk, C, C++, X, Amida alchemy.
You can also develop applications in environments like gtk if you port the gtk libraries to Amida.
Contents |
Developing applications on Amida
C language is the primary language used for developing applications for Amida.
The GUI for the application is acheived using PicoWidgets, Xlib and other libraries.
An Amida implementation of Tcl/Tk called ppwish is also available for rapid prototyping.
Since Tcl/Tk programs are interpreted and not compiled into binary, the performance may not be as good as programs written in C.
Amida Simulator on Linux PC
Application development for the Simputer is usually done on a PC. The programming language used for the development can be C or Tcl/Tk or a combination of both depending on the nature of the application. Whether it is C or Tcl/Tk it is convenient to develop the application on the Linux PC (on Intel x86 platofrm) before the application itself is run on the Simputer which runs on StrongARM SA1110.
It is easy to simulate Amida on a Linux PC which runs X windows. X windows has a utility called Xnest which is also a part of the Mandrake distribution.A brief description of Xnest is given below. The following two paragraphs are taken verbatim from the man pages of Xnest. Please refer to the man pages of Xnest for more details.
Xnest Description
Xnest is a client and a server. Xnest is a client of the real server which manages windows and graphics requests on its behalf. Xnest is also a server to its own clients. Xnest manages windows and graphics requests on their behalf. To these clients Xnest appears to be a conventional server.
Xnest usage
Starting up Xnest is as simple as starting up xclock from a terminal emulator. If a user wishes to run Xnest on the same workstation as the real server, it is important that the nested server is given its own listening socket address. Therefore, if there is a server already running on the user¿s workstation, Xnest will have to be started up with a new display number. Since there is usually no more than one server running on a workstation, specifying Xnest :1 on the command line will be sufficient for most users. For each server running on the workstation the display number needs to be incremented by one. Thus, if you wish to start another Xnest, you will need to type Xnest :2 on the command line. To run clients in the nested server each client needs to be given the same display number as the nested server. For example, xterm -display:1 will start up an xterm in the first nested server and xterm -display:2 will start an xterm in the second nested server from the example above. Additional clients can be started from these xterms in each nested server.
Fortunately, the developer doesn¿t need to spend too much time reading the Xnest man pages to figure out how to go about getting the Amida simulator up and running. All the details can be put into a simple script so that invoking the script brings out the Amida simulator. The script is given below and the after the installing the SDK the script gets installed at /usr/local/bin/ directory.
AmidaSimulator Script
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
Xnest -geometry 240x320 -ac :2 &
export DISPLAY=:2.0
sleep 0.5
rxvt&
sleep 0.5
xset fp+ /usr/local/X11R6/lib/X11/fonts/picopeta_fonts/
xset fp rehash
xmodmap -e "keycode any=Mode_switch"
alchemy /usr/local/share/alchemy/themes/pp 2>/dev/null >/dev/null &
Cross Compilation Tool Chain
Cross Compilation
Application development for the Simputer is usually done on a PC. After the development is complete, the application is compiled for the Simputer using a cross-compiler to obtain the binaries. These binaries are then transfered to the Simputer where they can be executed. The ARM Linux cross compiler toolchain provides C/C++ compilers, link editors and the required ARM libraries.
Amida SDK customers are provided the toolchain bundled with the Amida SDK. While the SDK is installed, the cross compiler toolchain is also installed at /usr/local/ directory. The cross compiler for the StrongARM i.e., for the Amida Simputer is (also) available at: http://handhelds.org/download/projects/toolchain/arm-linux-gcc-3.3.2.tar.bz2
Setting up the work environment
For some reasons, if you want to download the toolchain and set up the work environment, follow the next few steps. After the cross compiler download is complete, the cross compiler has to be extracted and some settings are to made to use it. These are explained below.
1. Run the following commands to extract arm-linux cross compiler toolchain. It is assumed that arm-linux-gcc-3.3.2.tar.bz2 file is copied to /tmp directory.The cross compiler toolchain will be extracted to /usr/local/arm/3.3.2. 2. The C/C++ cross compilers reside in /usr/local/arm/3.3.2/bin directory. So the PATH environment variable should include this directory. Add the following line in ~/.bashrc and ~/.bash profile respectively:
- $cd /
- $tar jxvf /tmp/arm-linux-gcc-3.3.2.tar.bz2
A typical .bashrc file would include the above statements at the end of the .bashrc file as given below.
- export PATH=$PATH:/usr/local/arm/3.3.2/bin
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
These are the new definitions exportPATH=$PATH:$HOME/bin:/usr/local/bin:/usr/local/arm/3.3.2/bin:/usr/local/Acrobat5/bin:/
export LD_LIBRARY_PATH=/usr/local/lib:/usr/X11R6/lib: Source this .bashrc file to get the environment variables such as PATH take new value. Do this by typing source /.bashrc Now type the command $echo $PATH$ and it should display the /usr/local/arm/3.3.2/bin in the pathlist. If it is not found, run the command export PATH=$PATH:/usr/local/arm/3.3.2/bin directly from the command prompt. 3. After the arm-linux toolchain is extracted, the arm-alchemy-toolchain has to be extracted. Run the following commands to extract arm-alchemy-toolchain (It is assumed that arm-alchemy-toolchain.tar.bz2 file is copied to /tmp):
- $cd /
- $tar jxvf /tmp/arm-alchemy-toolchain.tar.bz2
Using the arm-linux toolchain
Do the following to compile the C/C++ application welcome.c with the cross compiler.
- $arm-linux-gcc -o some welcome.c
- $arm-linux-strip welcome
arm-linux-strip removes the symbol table from the executable and the resulting executable size will be smaller.
Example using Pwrap widget
Dialog Box Example
In this example a dialog box (i.e. window) containing a button is created. A callback bcallback() is associated with the button press event on the button which will stop the eventloop pw_stop_eventloop(), and thus quit the application.
#include <pwrap.h>
px_widget *dialog;
Bool bcallback(px_widget *widget, px_event *event)
{
pw_stop_eventloop();
return False;
}
int main(int ac, char **av)
{
px_widget *button=NULL;
pw_init(PW_SUPPORT_ALCHEMY);
dialog = pw_create_dialog(150, 80, PW_TITLE, "DialogBox",
PW_BGCOLOR, "linen",
PW_BORDER, PW_RECTANGLE_BORDER, PW_NA);
button = pw_create_button(dialog, 25, 25, 100, 30,
PW_TEXT, "Quit",
PW_CALLBACK, PW_BUTTON_RELEASE_EVENT, bcallback,
PW_FONT, PW_BOLD_FONT, PW_CONFIG_END);
pw_eventloop();
pw_exit();
}
Makefile.arm
The typical Makefile for compiling Pwrap programs for the Amida Simputer is isted below. The SRCS variable can be modified to include the list of your bject files (and thus, the source .c files). You can compile this by issuing the command make -f Makefile.arm on your command prompt.
CC= arm-linux-gcc
LIBS= -L/usr/local/arm/3.3.2/lib -lpwrap
SRCS= example.o
RPATH= -Wl,-rpath-link /usr/local/arm/3.3.2/lib -Wl,-rpath-link /usr/local/arm/3.3.2/arm-linux/lib/X11
example: $(SRCS)
$(CC) $^ -o $@ $(RPATH) $(LIBS)
arm-linux-strip $@
clean:
rm -f *.o example
Dialog Box Example

