2010年7月23日 星期五

Maemo 5 Hello World

衝著NOKIA N900 Linux base and open platform已經用了五六年的手機終於能退休了.事前其實沒作太多功課,光是看到x-terminal畫面還有busybox banner就已經受不了.期待已久真正功能強大又開放平台的Linux mobile phone終於出現了.對於像我這種天天在Linux programming的人來說真的是美夢成真,外人大概很難理解.網路上也有很多人對NOKIA update & bug fix很不滿.但以這一個月來使用的過程我個人覺得software穩定度已經很好,NOKIA一定也花了很多功夫在收尾.整體流暢度是還比不上IPhone但從Embedded Linux的產品來看真的是一大里程碑.

回到正題,NOKIA N900 Application Software的核心就是Maemo 5,架構可參考http://maemo.org/intro/platform/ 我想做的事就是寫一支可以在N900上跑的程式,用的是最熟悉不過的C Language.在開始之前有幾件事要做
1.在PC Ubuntu安裝Maemo 5 SDK,請參考http://maemo.org/development/
2.N900安裝openssh server & rootfs
開發的流程基本上是在Maemo 5 SDK 上coding and compile 再將binary複製到N900.

雖然說是Hello World但我並不想只是在x-terminal印個Hello World就好,而是能產生Window的程式.
其實到maemo.org就找得到這樣的程式碼.以下就是

/**
 * This file is part of maemo-examples package
 *
 * This maemo code example is licensed under a MIT-style license,
 * that can be found in the file called "COPYING" in the same
 * directory as this file.
 * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.
 */

/* Includes */
#include

#include
#include

int main(int argc, char *argv[])
{
    /* Create needed variables */
    HildonProgram *program;
    HildonWindow *window;

    /* Initialize the GTK. */
    gtk_init(&argc, &argv);

    /* Create the Hildon program and setup the title */
    program = HILDON_PROGRAM(hildon_program_get_instance());
    g_set_application_name("App Title");

    /* Create HildonWindow and set it to HildonProgram */
    window = HILDON_WINDOW(hildon_window_new());
    hildon_program_add_window(program, window);

    /* Add example label to window */
    gtk_container_add(GTK_CONTAINER(window),
                      GTK_WIDGET(gtk_label_new("HildonProgram Example")));

    /* Begin the main application */
    gtk_widget_show_all(GTK_WIDGET(window));

    /* Connect signal to X in the upper corner */
    g_signal_connect(G_OBJECT(window), "delete_event",
    G_CALLBACK(gtk_main_quit), NULL);

    gtk_main();

    /* Exit */
    return 0;
}

Maemo 5大量的使用glib & gtk,並在gtk上再建立一套UI library叫做Hildon以方便建立Window及各種control element. 程式碼本身我不再贅述,重點在source code compile & link

gcc -Wall `pkg-config --cflags gtk+-2.0 hildon-1` example_hildonprogram.c -o example_hildonprogram `pkg-config --libs gtk+-2.0 hildon-1`

example_hildonprogram就可以執行了

值得一提的是切換SDK platform再compile就可以產生相對應的binary code

[sbox-FREMANTLE_X86: ~] > sb-conf select FREMANTLE_ARMEL

[sbox-FREMANTLE_ARMEL: ~] > sb-conf select FREMANTLE_X86



沒有留言:

張貼留言