2010年11月23日 星期二

android 的 user space HAL

網路上一個有關user space HAL的問題
Q:
Hi All,

  I would like to know if there is any documents or related web links
for device driver development on "User Space Abstraction Layer ".
  I would appreciate if anyone can give me how this really works in
real world scenario.

 Thanks...

A:
I would suggest you to have a look of the overlay code in
hardware/libhardware/moudule/overlay.
In the new HAL architecutre, it introduced a "stub" concept which replaced
the legacy architecture which load the c/c++ library from java
application/service directly. In "stub", you need to implement some
interfaces and provide them to hardware service. For example if you wanna
implement a LED, the architecture will be:
Kernel Driver (driver to control the LED hardware) <-> syscall (open, close,
ioctl for LED, etc.) <-> hardware/libhardware/module/led (the led HAL
interfaces or "stub" ) <-> framework/base/services/jni/
com_android_server_LedService.cpp (the java native interface for LED )<->
framework/base/service/java/com/android/server/LedService.java (the java
interface of LED service <-> framwork/base/core/java
/android/hardware/LedManager (the java code of LED manager) and
ILedService.aidl (the android interface description language file for LED)
<-> LED application

這裡有一個文章連結

jollen的blog也有相關介紹文章

2010年11月16日 星期二

android 的 local service 與 thread 的差別

android 官網中提到要執行 background 的 long running 動作時 最好要用 service
但是 service 既然也是在同一個 process 中 create 一個 thread 來做這些 long running 的動作
為什麼不直接在 activity 裡直接 create thread 來做就好了

官網最下面有解答
1.
    一個有 service 在跑的 process 權限會比只有 background activity 在跑的 process高
    也就是當系統要砍 process 的時候比較不容易砍到你

2.
    用 service 的話 不管 activity 發生什麼事 都不會影響到 service, process 最少可以是 "service process" priority

android的application component是run在哪個thread

依照 android 官網所說 android 的 application component 包括 activity service broadcast receiver 等等
都是 run 在同一個 linux process 之中(除非這些 component 有特別指名要 run 在其他 process, 可以在 androidmanifest.xml 中指定)

官網又有說到 所有這些 component object 的實例化都發生在 process 的 main thread 中
而且有關 life cycle 的 method (例如 onCreate) 也都是在 main thread 中執行
所以在這些 method 中不能執行太花費時間的動作 免得阻擋到其他 component 的執行
如果需要作這些動作 應該 create 其他 thread 來做

2010年11月7日 星期日

vim 的自動完成

vim 也可以有自動完成的功能
在ubuntu 10.04下面裝的 vim 7 有預設支援自動完成的語言的資訊在 /usr/share/vim/vim72/autoload/ 下面

以php 為例 要開啟 php 自動完成功能 只要在 .vimrc 裡加上一行
    autocmd FileType php set omnifunc=phpcomplete#CompletePHP
就可以了

接下來在編輯 php 檔案時 只要用 ctrl+x ctrl+o 就可以使用自動完成

但是我最需要的 C/C++ 語言似乎需要額外的套件支援才能使用自動完成

C 的話有關鍵字自動完成可以用 不用在 .vimrc 中設定任何選項
只要在編輯 c 檔案時有 include 任何標頭檔 例如 stdio.h
在打入 print 時按下 ctrl+p 就會從 stdio.h 中找出符合的函式供你挑選

C++的話就沒有了 完全需要額外套件的支援
不知道為什麼 vim 不預設支援標準函式庫的自動完成 明明這是最需要的
關於 C/C++ 的自動完成之後再研究

2010年10月2日 星期六

vbscript 物件的解構函式不會在頁面關閉時呼叫

在VBScript裡面 可以寫下你自己物件的建構函式與解構函式
但是必須了解的一件事是 如果VBScript是跑在一個網頁上 網頁關閉時不會呼叫VBScript的解構函式
我本來以為 頁面關閉 物件銷毀 解構函式應該會執行 但是事實並不是如此
不過還好 還有 window.onbeforeunload 事件可以用
還是有機會在頁面結束前 作一些你想要執行的動作的

2010年10月1日 星期五

css 的 width 和 height 用百分比表示

在 css 裡面 元素的 width 和 height 可以用百分比表示
代表這個元素的寬和高為父元素的百分比
但是因為是使用父元素的寬和高來當基準 一定要確定父元素的寬和高也正確的設定了
否則可能會出現排版亂掉的情況

VBScript 和 JavaScript 的 string 是 pass by reference

在寫 scripting language 時 都知道變數通常可分為 primitive type 跟 reference type
primitive type 是 pass by value 而 reference type 是 pass by reference
可能語言會宣稱自己只有 pass by value (例如 java, 雖然他不是 scripting 語言)
但是保持一個觀念就是 reference type 的變數被傳進一個函式後
函式對這個變數做的改變在函式退出後還可以看的到

不過對 javascript 和 vbscript 來說 string 是特別的 string 不是物件 所以他是 primitive type
但是 string 又可以是任意長度的 所以如果 string 如果是 pass by value 將會很沒有效率
所以在實作上通常把他作為 pass by reference

如果只用 primitive type 和 reference type 來 分別 pass by value 和 pass by reference
可能會對 string 的 pass rule 搞錯了