Open C is a set of C libraries designed to ease and encourage porting open-source applications from the desktop to the Nokia S60 mobile phone platform (it also accommodates writing cross-platform software). Open C helps developers of mobile apps in two ways:
- Because Open C libraries are built on POSIX and other open-source projects, portable code on top of Open C is easier to write. This helps developers design and implement large application bases that need to run on several operating systems.
- Open C opens the door for C/C++ programmers who don't have Symbian experience, but who need to develop applications for mobile devices.
In this article, we introduce Open C (forum.nokia.com/openc) and show how you efficiently port existing code to the 260 smartphone platform. To illustrate, we port SQLite (www.sqlite.org), a small open-source C library that implements a self-contained, embeddable, zero-configuration SQL database engine, from the desktop to the S60 (www.s60.com).
Open C Details
Again, Open C is a collection of libraries based on POSIX and other open-source projects. In its first release, Open C includes more than 70 percent of the functionality contained in the following libraries:
- Libc. Standard C libraries, including standard input/output routines, database routines, bit operators, string operators, character tests and character operators, DES encryption routines, storage allocation, time functions, sockets, and interprocess communication.
- Libm. Arithmetical and mathematical functions.
- Libpthread. Pthreads API provides an IEEE Std1003.1c (POSIX) standard interface implementing multiple threads of execution within traditional user processes. This implementation is currently user-space only. Pthreads provides functions for thread creation and destruction, an interface to the thread scheduler to establish thread-scheduling parameters, and mutex and condition variables to provide mechanisms for you to synchronize access to shared process resources.
- Libz. The Zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data.
- Libdl. Provides users with the functionality to dynamically load DLLs.
- Libcrypto. The OpenSSL crypto library implements a wide range of cryptographic algorithms. The services provided by this library are used by the OpenSSL implementations of SSL, TLS, and S/MIME, and they have also been used to implement SSH, OpenPGP, and other cryptographic standards.
- Libssl. The OpenSSL ssl library implements the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols.
- Libcrypt. Cryptography libraries containing functions for encrypting datablocks and messages and password hashing.
- Libglib. A general-purpose utility library, which provides data types, macros, type conversions, string utilities, file utilities, a main loop abstraction, and so on. Libssl works on many UNIX-like platforms, as well as Windows, OS/2, and BeOS.
Open C builds on Symbian's P.I.P.S. (short for "POSIX on Symbian"), released earlier this year. Like Open C, P.I.P.S. reduces the effort required to migrate existing desktop and server components/applications from other platforms onto Symbian OS. The P.I.P.S. librarieslibc, libm, libdl, and libpthreadwere jointly developed by Nokia and Symbian to ensure that code written on top of Open C delivers the performance expected of a native environment. Open C adds to P.I.P.S. with libraries coming from the OpenSSL, libz, and Glib (from the GNOME project).
Open C Limitations
The first release of Open C doesn't provide complete functionality. For instance:
- There is no support for signal, fork, and exec. If the software you want to port contains these system calls, you should carefully analyze how much modification you must do to the ported software.
- dlsym. Address lookup through symbol names is not supported and you have to use ordinal numbers instead of symbol names. Ordinal numbers of the exported functions can be obtained from the module definition file (.def) of the associated DLL, as in Listing One. This same limitation applies for the g_module_symbol function. The first release of the Open C SDK plug-in lets you build Open C modules and deploy them to existing mobile devices built on S60 3rd Edition and S60 3rd Edition Feature Pack 1. Symbol lookup by name will be supported with the S60 3rd Edition Feature Pack 2 when using the new target types.
// This code is part of the libsliteU.DEF file // EXPORTS sqlite3AbortOtherActiveVdbes @ 1 NONAME sqlite3AddCheckConstraint @ 2 NONAME ...
/* The below won't work in */ /* Open C SDK plug-in */ ret = g_module_symbol(module, "sqlite3AbortOtherActiveVdbes" ,&ptr); /* And it has to be like below. */ /* 1 is the ordinal of the */ /* exported function */ ret = g_module_symbol(module, "1", &ptr);
Open C SDKs
An Open C SDK plug-in is available at Forum Nokia (www.forum.nokia.com/tools), letting you use Open C for S60 3rd Edition and S60 3rd Edition Feature Pack 1 devices. With the Open C SDK plug-in, we recommend that you use the S60 3rd Edition C++ SDK because you can then target a wide set of available devices. The Open C SDK plug-in contains libraries for building, runtimes for emulator/target, documentation, and sample applications. Signed Open C runtime packages can be shipped together with your application, making it convenient for end users to install.
For its part, Symbian will release a corresponding P.I.P.S. plug-in containing the four libraries developed jointly with Nokia. To ensure source and binary compatibility, both plug-ins will contain exactly the same version of the specified libraries and the same binaries of the shared libraries.
Open C will be part of the S60 platform beginning with S60 3rd Edition Feature Pack 2. The Feature Pack 2 release will include the same APIs as in the current Open C SDK plug-in, but will introduce new target typesSTDEXE, STDDLL, and STDLIBthat make development easier by enabling:
- Support for address lookup by name when using new target types. dlsym and g_module_symbol functions will work as specified and you will no longer have to use ordinals with those functions.
- There will be no need to annotate sources with IMPORT_C and EXPORT_C when using new target types. This makes porting easier when porting libraries exposing a lot of APIs.