JS-ctypes

From Kiwix
Revision as of 09:14, 29 November 2011 by Reg (talk | contribs) (Created page with "With the unavailability of XulRunner in Ubuntu Oneiric and the possible removal of it from other distro, we decided to switch to js-ctypes components. The main reason is that ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

With the unavailability of XulRunner in Ubuntu Oneiric and the possible removal of it from other distro, we decided to switch to js-ctypes components. The main reason is that our code won't be tied to a XR version (which are released every 6 weeks) as components are. It also has some side-advantages

JS-ctypes

ctypes is a Foreign Function Interface which is available in several languages. It allows one to call C functions (of a library) from Javascript or Python or other language supporting it. It doesn't require specific C code. It just calls arbitrary functions.

Porting

Porting Kiwix components to js-ctypes requires a lot of work so we decided to incorporate other changes. Porting a component consist of the following:

  1. Rewrite the C++ component into a C++ library with no mozilla dependency.
  2. Write a C++ program testing the C++ API.
  3. Write a C Wrapper around the C++ API.
  4. Write a C program testing the C Wrapper/API.
  5. Write a JS module interfacing with js-ctypes and the C wrapper.
  6. Fix existing JS code (gui.js, etc) to use the JS module.

Rewrite the C++ component into a C++ library

The main rule here is to remove Mozilla dependency. It is very important to remove it completely otherwise it's a waste of time. Advantages of removing MOZ dep:

  • We build a shared/static lib which is not a component.
  • We don't need the mozilla stack to build it (ease Windows, and other system setup like arm)
  • We don't need an every-release recompile of our code
  • We don't even need to release anything to have it work with newer XR.
  • We can use it to build a Kiwix UI with webkit (for example on Android). We'll code all component code and just need a new UI.
  • We can use the same code for kiwix-serve
  • We could use it to create a Kiwix server instead of a kiwix-http-server (allow one to administer the server library using a Web UI)
  • We can then split kiwix code with components code and have a kiwix-libs package.

Writing this library is quite easy. It's mostly a copy-paste of the component code then cleaning.

Note: The goal is to replace the component but until all components are ported, we'll have a duplication of the code in the tree. We need to port-back every addition to the comonent to the new library until it replaces the component completely.

Rules to embrace/respect:

  1. nsAString is replaced with unicode
  2. nsACString is replaced with char *
  3. nsURL is replaced with unicode and code adapted consequently.
  4. No more retVal nor NS_OK. Methods uses return type (bool mostly)


Remaining work

  • unicode