티스토리 뷰

시작하기 전에...
Tizen 공부를 시작하며 에도 썼듯이 혼자 공부하며 서술합니다.
실제 사실과 다를 수도 있고, 보이는 대로 사견을 서술할 예정입니다.
잘못되었다 싶은 부분은 댓글이나, 메일로 알려주세요.
Tizen 2.4 Native 기준으로 포스팅 합니다.


system information API는 System 정보 및 Device의 지원 feature 들에 대한 정보를 get할 수 있습니다.

주로 많이 쓰게 될 정보는 screen 해상도 정보나, Camera 기능 등 H/W에 대한 정보가 될 듯 합니다.


developer.tizen.org -> Development -> API Reference


API Set들을 보겠습니다.



API가 아주 단순합니다.
API만 봐서는 아예 사용할 수 조차 없는 수준입니다.

platform / device 정보들은 변하는 값이 아니고, device에 따라 지원하는 key-value가 달라질 수 있습니다.
key-value 쌍이 굉장히 많기도 하고요.
이런 경우 key 별로 일일이 get하는 API를 제공하기 보다는 저렇게 type 별 get 함수만 주고,
key-value는 별도로 가이드 하는 방법이 나을 수 있습니다.

특히나 객체지향 언어였다면 단순히 member 변수로 준다든가 할 수 있지만,
이거는 C 언어다보니 API의 형태가 제한적이고 어떻게 보면 구식일 수 밖에 없습니다.


어떤 key를 넣으면 어떤 값이 나오는 지는 API Guide 쪽에 나와 있습니다.
다만, key 값 들에 대한 define을 제공하지 않고 Guide로 대체하는 건
API를 사용하는 입장에서 굉장히 불친절하게 느껴지는 부분이 아닐 수 없습니다.
API에 대한 신뢰도 떨어집니다.
나중에 Guide 사이트에서만 그냥 쏙 빠지면 동작 안해도 할 말이 없을 듯 보입니다.


API Set이 두 종류로 나뉩니다.

1. system_info_get_platform_XXX

2. system_info_get_custom_XXX

Overview에 보면 간략한 설명이 나옵니다.

The keys for the custom functions are specified by OEM's and vendors. Developers should check with their OEM's Tizen OS support if they wish to use a custom functions.

OEM 어쩌구 하는데 뭔 말인지 잘 모르겠습니다.
유추하자면 Tizen이 오픈소스 OS이니,
이걸 가져다 쓰게 될 2차 밴더에서 추가로 정의한 key 값이 있다면 이 custom API로 get 하라는 것으로 보입니다.


API의 동작 원리부터 살펴보겠습니다.

https://review.tizen.org/gerrit/#/admin/projects/framework/api/system-info
의 소스코드를 다운 받습니다.

$git clone git clone ssh://<my_gerrit_id>@review.tizen.org:29418/framework/api/system-info
$cd system-info
$git checkout tizen_2.4


src/system_info.c 의 system_info_get_platform_bool API를 보겠습니다.

API int system_info_get_platform_bool(const char *key, bool *value)
{
     ////////////// 생략 ///////////////

    if (access(CONFIG_FILE_PATH, R_OK)) {
        _E("cannot find file %s!!!", CONFIG_FILE_PATH);
        if (errno == EPERM || errno == EACCES)
            return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
        return SYSTEM_INFO_ERROR_IO_ERROR;
    }   

    ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, BOOL_TYPE, &string);

     ////////////// 생략 ///////////////

    return SYSTEM_INFO_ERROR_NONE;
}

system_info_get_value_from_config_xml 함수

int system_info_get_value_from_config_xml(char *feature_tag, const char *name_field, char *type_field, char **value)
{
    xmlDocPtr doc = NULL;
    xmlNodePtr cur = NULL;
    xmlNodePtr model_node = NULL;
    xmlNode *cur_node = NULL;
    char *name = NULL, *p_name = NULL;
    char *type = NULL;
    char *string = NULL;

    doc = xmlParseFile(CONFIG_FILE_PATH);
     ////////////// 생략 ///////////////

중요하지 않은 부분은 생략했습니다.
골자는 CONFIG_FILE_PATH 에 대해 read 가 가능한지 검사한 후,
해당 file에서 xml 파싱을 시도한다는 데에 있습니다.

CONFIG_FILE_PATH는 어떤 값인지 찾아보겠습니다.

ctags로 바로 안들어가지는 걸 보니 다른 데에 선언되어 있는 듯 합니다.
grep 으로 찾아보니 CMake와 spec 파일에서 찾아집니다.

우선 CMakeLists.txt 파일을 보면,

ADD_DEFINITIONS("-DCONFIG_FILE_PATH=\"${CONFIG_FILE_PATH}\"")

이라는 구문이 존재합니다.
그리고 이 CMake에 "CONFIG_FILE_PATH"를 전달한 주체가 spec 파일입니다.

packaging/capi-system-info.spec 에 다음과 같은 내용이 존재합니다.

%define config_file_path /etc/config/model-config.xml

/// 생략 ///

%build
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
cmake . -DCMAKE_INSTALL_PREFIX=/usr \
        -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
        -DCONFIG_FILE_PATH=%{config_file_path} \
/// 생략 ///

결국 system information API는 /etc/config/model-config.xml 로부터 xml 파싱해주는 API가 되겠습니다.

Emulator에서 sdb를 통해 해당 File을 살펴보면

sh-4.1$ head /etc/config/model-config.xml

<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<model-config version="2.4.0" model="EMULATOR">
	<platform>
		<key name="tizen.org/system/model_name" type="string">Emulator</key>
		<key name="tizen.org/system/platform.name" type="string">Tizen</key>
		<key name="tizen.org/feature/platform.version" type="string">2.4.0</key>
		<key name="tizen.org/system/platform.processor" type="string">Emulator</key>
		<key name="tizen.org/system/platform.communication_processor" type="string">none</key>
		<key name="tizen.org/system/manufacturer" type="string">Tizen</key>
		<key name="tizen.org/feature/account" type="bool">true</key>
		<!-- 이 하 생 략 -->

즉 저 안에 있는 "key"를 system information API에 넣으면 xml의 값을 얻을 수 있습니다.

코드를 유심히 보면 <platform> 테그 안에 들어간 내용들이 platform information이고,
custom 정보들은 <custom> 테그를 사용함을 알 수 있습니다.


API 사용 법을 보겠습니다.

이 API를 사용하기 위해서는 API Guide가 매우 중요합니다.

다행히 페이지가 제법 보기 좋게 되어있습니다.



Input 쪽을 보게 되면 built-in keyboard를 지원하는지 여부와
built-in keyboard의 layout string을 받아올 수 있습니다.

Table: Input feature keys

KeyTypeDescription
http://tizen.org/feature/input.keyboardboolThe platform returns true for this key, if the device provides a built-in keyboard supporting any keyboard layout.
http://tizen.org/feature/input.keyboard.layoutStringThe platform returns the keyboard layout (such as qwerty) supported by the built-in keyboard for this key and returnstrue for thehttp://tizen.org/feature/input.keyboard key.

If the device does not provide a built-in keyboard, the platform returns an empty string for this key and returns false for the http://tizen.org/feature/input.keyboard key.

http://tizen.org/feature/input.rotating_bezelboolThe platform returns true for this key, if the device supports the rotating bezel feature.

그러나 어이없게도, keyboard layout의 string이 어떤 값이 올 수 있는지 설명이 없습니다.
(such as qwerty)가 전부입니다.
쓰라고 만든 API 라기 보다는 그냥 사용자에게 보여주는 용도인 듯 싶습니다.


유용하게 쓰이는 feature는 Screen 관련 입니다.

http://tizen.org/feature/screen.widthintThe platform returns the width of the screen in pixels supported by the device for this key.
http://tizen.org/feature/screen.heightintThe platform returns the height of the screen in pixels supported by the device for this key.
http://tizen.org/feature/screen.dpiintThe platform returns the number of dots per inch supported by the device for this key.


screen.width와 screen.height를 이용하면 screen 해상도를 가져올 수 있습니다.

이를 통해 해상도를 이용할 기능이나 UI 구현이 가능합니다.


screen.dpi를 가져오면 실제 사용자에게 보여지게 될 크기 등을 계산할 수 있게 될 뿐만 아니라,
Android의 dp (pixel 대신 주로 사용되는 단위) 개념도 사용할 수 있습니다.

DPI란, Dot per inch 의 약자로 스크린에서 1 inch를 그리기 위해 차지하는 pixel 길이 입니다.

DPI 값을 이용하면 Device-independent pixel,
즉 디바이스에 구애 받지 않고 일관성있는 view를 표현할 수 있는 pixel 단위를 구현할 수 있습니다.
그 구현 예가 Android의 dp입니다. (Android의 1 dp는 1/160 inch 입니다.)


API를 사용해서 값들을 가져와 보겠습니다.

int dpi, width, height;
bool keyboard_support = false;
char *keyboard_layout = NULL;

system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
system_info_get_platform_int("http://tizen.org/feature/screen.width", &width);
system_info_get_platform_int("http://tizen.org/feature/screen.height", &height);

system_info_get_platform_bool("http://tizen.org/feature/input.keyboard", &keyboard_support);
system_info_get_platform_string("http://tizen.org/feature/input.keyboard", &keyboard_layout);

LOGI("dpi : %d", dpi);
LOGI("width : %d, height : %d", width, height);
LOGI("key support : %s, layout : %s", (keyboard_support?"yes":"no"), keyboard_layout);

free(keyboard_layout);

출력 결과입니다.

screen 가로 해상도가, 480인데, dpi가 233이면 화면 가로가 2인치 정도밖에 안되는 디바이스 입니다.

(에뮬레이터가 제 컴퓨터에서는 엄청 크게 나오는데 실제론 작다는 이야기군요;;)

keyboard는 build-in 되어있지 않네요.


팁. Android와 동일한 view size 계산 방법

만약 Android와 Tizen에서 동시에 서비스하기 위한 App을 만든다면,

Android에서 디자인한 dp를 Tizen에서는 다음과 같이 계산해서 일관성 있는 Layout을 서비스 할 수 있습니다.

1dp = (dpi / 160) pixel

즉, 위에서 Test한 Emulator의 Android 1dp에 해당하는 pixel은 233 / 160을 한 약 1.456 pixel 입니다.


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함