Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

Open C: Paving the Way for Porting


Eero is a software technology manager and Antti is a software specialist at Nokia. They can be reached at eero.penttinen@ nokia.com and [email protected], respectively.


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. libraries—libc, libm, libdl, and libpthread—were 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
            ...
    Listing One

  • Open C does not provide APIs for UI development. UIs can be written using existing S60 APIs, and developed within the Carbide.c++ Developer or Professional editions. UIs can also be built using S60 Python (www.forum.nokia.com/python) with Python bindings for the exported functionality.
  • Open C does not offer native C-bindings to Symbian/S60 platform services like telephony, messaging, Bluetooth, location services, and the like. In those cases, you have to use the provided C++ interfaces. From a portability perspective, however, we recommend that you isolate platform-specific source code in different source files:

/* 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 types—STDEXE, STDDLL, and STDLIB—that 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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.