A safe upgrade to Diablo

At the end, Maemo Diablo release for N810 is out. But if you have valuable information, programs or configuration on it maybe you’re worried about what you’ll loose in a reflashing. In fact, if you’ve done the upgrade yet you’ll notice that the main part of the apps from Extras repository are missing in Diablo for the moment. Fortunately, there’s a way to install the apps from the old Chinook repository.

Here are six simple steps to perform the upgrade process and restore all your current applications:

  1. Backup your /home/user to a safe place by hand. Standard backup tool won’t
    backup every file you’ve at home and maybe you could need them later…
  2. Do a backup using the backup tool.
  3. Reflash the device with the new image using the flasher tool according to the reflashing instructions
  4. Restore the backup. Some old apps will remain grayshaded because the backup
    tool can’t find them in the now current Diablo repository.
  5. Open Application Manager. Menu, tools, application catalog. Maemo Extras,
    edit. Distribution: chinook, uncheck the “disabled” checkbox, Accept. Close.
  6. Menu, tools, restore applications. Accept.

That’s all. Enjoy your updated device!

How to send SMS in Linux using Skype

Skype for Linux doesn’t support SMS sending from the user interface. But that functionality is in fact implemented in the library and external apps can use it via the public API. I’ve found a working example of that nice feature. Just do these simple steps:

  1. Download Skype4Py from here, uncompress it and install it typing sudo python setup.py install
  2. Download Skype tools 0.11 from here and uncompress it
  3. Open your Skype client and prepare for the authorization dialog that will appear when you execute the next step
  4. Enter into the previous directory and send the SMS: ./send_sms.py +34123123456 My test sms

If the message takes too much to be sent, stop the app (CTRL+C), delete the authorization using the Skype options dialog, and try again. Third and next times worked fine for me.

Shishen Sho Mahjongg 0.3 released

Version 0.3 of Shishen Sho Mahjongg has just been released. The main improvements since 0.2 are: Gravity, hints, undo history, time counter and speed improvements.

You can download the game and know more about it visiting the project page at Maemo Garage.

Enjoy it!

Click here to install this application

28/05/2008 UPDATE: Now the application is also available in Maemo Extras repository and listed in Maemo Downloads with its own green “click to install” icon 🙂

Shishen Sho Mahjongg 0.2 released

Last month I published Shishen Sho Mahjongg for Gtk and Maemo, a board game similar to Mahjongg where the goal is to remove all the tile pairs and two tiles can be removed if a line with a maximum of three segments can be drawn between them.

Today I’m announcing version 0.2. The main improvements since 0.1.1 are Hildon integration (fullscreen, embedded menu, notifications) through conditional compilation and drawing of matching path when two pieces are matched.

You can download the game and know more about the project following these links:

Feel free to send me your comments, suggestions or patches over the original Vala sources.

Thank you! 🙂

Setting up Vala on Maemo and CPP integration

Until now, when I wanted to build some Vala source code for the Maemo platform I generated C code using the i386 Vala compiler and then builded the executable inside the scratchbox using gcc. That was fine until I wanted to use Hildon features (not available for i386). I definitely needed the Vala compiler running on the scratchbox.

This weekend I’ve put myself on the way and managed to compile Vala 0.3.2 on the scratchbox for the CHINOOK_ARMEL target. The process was much simpler than I expected and consisted of these few steps:

  1. Log into the scratchbox and choose CHINOOK_ARMEL
  2. Download the compiler from http://live.gnome.org/Vala/Release (I tried version 0.3.2)
  3. Untar it: tar jxvf vala-0.3.2.tar.bz2
  4. Enter the vala-0.3.2 directory and configure the package for ARMEL cross compiling: ./configure --host=armel
  5. Compile and install: make; make install

Alternately, to build for target CHINOOK_X86, repeat the previous steps but logged into the CHINOOK_X86 target. In step 3, issue ./configure without arguments instead.

That’s it. You have now the Vala compiler ready to be used. But if you want to develop a multiplatform project, you’ll need to avoid compilation of the Hildon related code when not building for Maemo target. The best way I found to do that was to use CPP as a preprocessor to allow me to use #ifdef’s in the code.

This is a simple way to use CPP to preprocess a single file:

cpp -P -Dsymbol1 -Dsymbol2 ... source.vala destination.vala

But I’ve managed to tweak my compilation script to preprocess all the files, write the result to a directory called CPP and finally compiling the result. Here’s the source:

# File compile.sh
export DEFINE=""
export APPNAME="myapp"
export PACKAGES="--thread --pkg gtk+-2.0 --pkg gdk-2.0 --pkg libglade-2.0 --pkg gmodule-2.0"

# Perform preprocessing and output to CPP directory
# Arguments to this script are "defined" and passed to CPP
for i in $@
do
 DEFINE="$DEFINE -D$i"
 case $i in
  MAEMO)
   PACKAGES="$PACKAGES --pkg hildon-1"
   ;;
 esac
done
if [ ! -d CPP ]; then mkdir CPP; fi
for f in *.vala; do cpp -P $DEFINE $f CPP/$f; done
valac $PACKAGES CPP/*.vala -o $APPNAME -X -g -X "-Wl,--export-dynamic -rdynamic"`
rm -rf CPP

The compile.sh script can be used by passing it the symbol set that should be defined. For instance, ./compile.sh MAEMO DEV would define both MAEMO and DEV symbols. Note that with this approach you should check the source files in the CPP directory when errors happen, because the line numbers referenced by the Vala compiler will be related to them and not to the original files.

I think this approach will be useful for other programmers too, so I’ve contributed it to the Vala FAQ (Does Vala have a preprocessor?).

Shishen Sho Mahjongg for Gtk and Maemo

Shishen Sho Mahjongg is a board game similar to Mahjongg. The goal is to remove all the tile pairs. Two tiles can be removed if a line with a maximum of three segments can be drawn between them.

Both the idea and the tile images were taken from kshishen (Shishen Sho 1.5.1), from the package kdegames, which is (C) 1997, Mario Weilguni and distributed under GPL license.

My girlfriend and me are fans of kshishen, so I needed to make a Maemo version to let her play on the N810 internet tablet, free my laptop and let me work on it. O:-)

The game is written in Vala and licensed under the GPL. Vala is a programming language that produces C/GObject source code which can also be compiled independently without the need of the original Vala compiler. Currently, two platforms are supported for the game: i386 (a desktop distribution, eg: Ubuntu Feisty), and also Maemo platform (armel).

21/04/2008 UPDATE: New version 0.1.1 available. Features improved compilation scripts, improved debian package structure and proper installation support from Maemo application manager.

Feel free to send me your comments, suggestions or patches over the original Vala sources. I hope you enjoy the game as much as I enjoyed writing it. 😀

Trying out Android

Android emulator
These weeks I’ve proposed myself to have a look at Google’s Android and try to learn how to write applications on it.

I went to the Android main page and, from there, I followed the “getting started” stuff to download the SDK, Eclipse and started to understand the framework.

The framework is a bit different from what I’m used to. The applications have 4 building blocks:

  • Activity: Tasks that the application performs (from the user point of view). For example, manage a collection of text notes. Activities can also request “intents”, that is, use the system to locate a component that can manage the action that the app wants to be done. For example, edit a single note. Intents are a clever way to reuse functionality.
  • Intent receiver: These are methods to attend external events asynchronously.
  • Service: Functionality provided to another applications by running code in the background.
  • Contend provider: A standard way to provide data to other applications.

Android features nice pieces of code, like SQLite database. The intended way of working relies heavily on XML config files, which make easier to build user interfaces and makes me remember the way UIs are done on other frameworks (I’ve heard that Glade uses XML files too).

My wish about Android would be to develop “Caterpillar”, a robotized (this is, for Android) version of Berto’s Vagalume. But for that there’s still a long way to go through.

At this moment, I’ve already created the “Hello Android” app and I’m following the tutorial. I’ve just completed exercise 2 this night. As I advance more, I’ll update this post to let you know about my progress.

UPDATE: 26/01/2008

The three exercises of the tutorial plus the extra credit one are now completed. The next step will be to have a look to common Android tasks and to continue learning from there. I’d also like to try DroidDraw for GUI designing.

UPDATE: 30/01/2008

I’ve started to write Caterpillar. An early version of the GUI was designed using DroidDraw (see the previous update) and fine tuned by hand. Fortunately, DroidDraw lets you not only export, but also import a layout text description.

The very first task I tried was to try to play an arbitrary MP3 file. I looked into the media APIs and tried some methods to load the test sound (as a raw resource, as an external URL and as a local file), but didn’t succeed. At first I thought that the emulator hadn’t the audio enabled, but after adding the “-useaudio” option, that shown not to be the problem.

Then I found this post (spanish) and this other that gave me some hints. At this moment I know that the sound system works, because I can hear the system sound when raising up the volume, but my media player instance is still null, despite I’m using an MP3 lesser than 1 MB in size. Yeah, the emulator has a 1 MB limitation on that. :-/

UPDATE: 03/02/2008

On this Google groups thread there are people saying that Android has problems playing MP3 from online streams, because it pretends to copy the whole stream to disk (SD card or whatever) and then play it. The problem has been reported to the Android bug tracking system.

UPDATE: 02/03/2008

After a month of silence I have to say that I’ve continued my work on Caterpillar in my spare time. Having a look to the Vagalume source code and doing some tests with Firefox and wget, I’ve developed the session management and playlist fetching and parsing code, so I can end up with a bunch of tracks and all the required information about them: title, author, album, picture, audio file URL…

I’ve decided to overcome the limitations of the Android media player by downloading the tracks one by one and feeding them to the media player as local files, erasing them when the media player has finished playing each one. It’s a bit weird solution but is the only one I’ve found.

The TrackDownloader, as I’ve named it, is created by the controller, which registers itself as an observer. When the downloader has got enough data, it notifies the controller, which starts up the media player. In the meanwhile, the downloader keeps downloading in the background and, when the transfer is about to finish, notifies the controller about that, just to spawn another TrackDownloader for the next track. When the track has definitely ended, the controller dismisses it and it’s erased from disk to save space. I haven’t tested the TrackDownloader for the moment, only coded it.

I’ll keep hacking. Stay tuned!

Teaching at Master on Free Software

Last weekend I taught my first class for the Caixanova Master on Free Software, organized by Universidad Rey Juan Carlos and Igalia. The class is part of the Systems Integration on Free Software subject and covered basic concepts of system administration and scripting. The goal is to provide the students a basic knowledge to be able to face more complex tasks in the Development subject.

All of them showed very interested and I felt quite happy with the results. Some of the students had basic knowledge of scripting, but a comprehensive walk through the concepts unleashed some concepts that they lacked of.

The subjects covered were:

  • Administrative tasks: System startup, Users & groups, Task automating, Auditing, Backups
  • Basic commands: Files & directories, Process control, Documentation, Redirections & pipes
  • Script programming: Environment variables, Input/output, Command grouping, Wildcards, Quoting, Control structures
  • Advanced commands: Regular expressions, Grep, Sed, Awk

All the materials of the Master are published on a Creative Commons by atribution share alike license. You can find them at the web of the Master:

http://gsyc.escet.urjc.es/moodle/course/category.php?id=17

(By the way, this blog aniversary was two days ago. Two years! I wish a long life for it and lots of interesting posts.)

Idea to build an application server in PHP

Theese days I’ve been following a thread in the php-es mailing list at lists.php.es. A subscriber noticed that static class attributes weren’t shared between different page requests. Someone explained him that the way PHP deals with the requests is the cause for it not to have an “application” variable scope.

In Java servlets, for example, static class attributes are shared by all the instances of that class in the virtual machine. Scalability (and speed) at a medium scale is achieved using object in-memory caches. In PHP that approach can’t be done without using shared memory management libraries, and never in an easy way. Developers have to resort to disk and database caches, much slower that the memory ones.

Moreover, the fact of having to parse in each request not only the target PHP file, but also all those ones recursively included, represent another of the disadvantages of the platform.

It’s strange because, as far as I know, an “execution environment” common to all the requests does exist on other languages, like Perl (Apache mod_perl) or Python. That way, data can be shared among the requests, memory caches can be done, and so on.

Something that would be nice, even being a daydream, would be to develop an “application server” consisting of:

  • A library that made shared memory usage simpler for storing session variables and object instances on it (even singletons), making them available from different threads.
  • A multithreaded web server implemented entirely in PHP using the socket API. The server would spawn threads with each request using the threads and processes API. It’d be a replacement for Apache.

This way, we would have the advanteges of the application servers and the syntax simplicity of PHP. The disadvantage would be that, as PHP has been developed with the “parse, create environment, process the request and dispose everything” model in mind, with the proposed approach, a great number of memory leaks would be found. That memory leaks are currently hidden thanks to the short life cycle of the requests.

That’s all. This was an idea I had some time ago and it seemed interesting to me. Now I’ve decided to share it with you. It’s surprising that nobody has already thought about it, isn’t it?

UPDATE:

I’ve just found Quercus, a PHP5 implementation written in Java that allows PHP programs to interact directly with Java libraries, taking advantage of all the benefits that Java caches, connection pools, etc. can provide. It’s not the same approach I propose, but maybe a good one anyway.