Initialize Tizen 2.3 2.3a_release submit/tizen_2.3/20140531.063144
authorSehong Na <sehong.na@samsung.com>
Sat, 31 May 2014 03:34:03 +0000 (12:34 +0900)
committerSehong Na <sehong.na@samsung.com>
Sat, 31 May 2014 03:34:03 +0000 (12:34 +0900)
33 files changed:
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0755]
TC/_export_env.sh [new file with mode: 0755]
TC/_export_target_env.sh [new file with mode: 0755]
TC/build.sh [new file with mode: 0755]
TC/clean.sh [new file with mode: 0755]
TC/config [new file with mode: 0644]
TC/execute.sh [new file with mode: 0755]
TC/testcase/Makefile [new file with mode: 0755]
TC/testcase/tslist [new file with mode: 0644]
TC/testcase/utc_system_device_battery.c [new file with mode: 0644]
TC/testcase/utc_system_device_brightness.c [new file with mode: 0644]
TC/tet_scen [new file with mode: 0755]
TC/tetbuild.cfg [new file with mode: 0644]
TC/tetclean.cfg [new file with mode: 0644]
TC/tetexec.cfg [new file with mode: 0644]
capi-system-device.pc.in [new file with mode: 0644]
include/device.h [new file with mode: 0755]
include/device_doc.h [new file with mode: 0755]
include/device_log.h [new file with mode: 0644]
packaging/capi-system-device.manifest [new file with mode: 0644]
packaging/capi-system-device.spec [new file with mode: 0644]
src/mobile/battery.c [new file with mode: 0644]
src/mobile/cpu.c [new file with mode: 0644]
src/mobile/device.c [new file with mode: 0644]
src/mobile/memory.c [new file with mode: 0644]
src/wearable/battery.c [new file with mode: 0644]
src/wearable/cpu.c [new file with mode: 0644]
src/wearable/device.c [new file with mode: 0644]
src/wearable/memory.c [new file with mode: 0644]
test/CMakeLists.txt [new file with mode: 0755]
test/battery.c [new file with mode: 0644]
test/system-device.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..9a54217
--- /dev/null
@@ -0,0 +1,109 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-system-device")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+IF("${ARCH}" STREQUAL "mobile")
+       OPTION(USE_MOBILE "Use Mobile" ON)
+ELSEIF("${ARCH}" STREQUAL "wearable")
+       OPTION(USE_WEARABLE "Use Wearable" ON)
+ENDIF()
+
+IF(USE_MOBILE)
+       SET(SRCS src/mobile)
+       SET(dependents devman)
+ELSEIF(USE_WEARABLE)
+       SET(SRCS src/wearable)
+       SET(dependents deviced)
+ENDIF()
+
+SET(dependents ${dependents} "dlog vconf capi-base-common")
+SET(pc_dependents "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(${SRCS} SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+    PROPERTIES
+    VERSION ${FULLVER}
+    SOVERSION ${MAJORVER}
+    CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/system
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "*_log.h" EXCLUDE
+        PATTERN "*_doc.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+    ${fw_name}.pc.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+#ADD_SUBDIRECTORY(test)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+        DEPENDS clean 
+        COMMENT "distribution clean"
+        COMMAND find
+        ARGS    . 
+        -not -name config.cmake -and \(
+        -name tester.c -or
+        -name Testing -or
+        -name CMakeFiles -or
+        -name cmake.depends -or
+        -name cmake.check_depends -or
+        -name CMakeCache.txt -or
+        -name cmake.check_cache -or
+        -name *.cmake -or
+        -name Makefile -or
+        -name core -or
+        -name core.* -or
+        -name gmon.out -or
+        -name install_manifest.txt -or
+        -name *.pc -or
+        -name *~ \)
+        | grep -v TC | xargs rm -rf
+        TARGET  distclean
+        VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..bbe9d02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+\r
+\r
diff --git a/TC/_export_env.sh b/TC/_export_env.sh
new file mode 100755 (executable)
index 0000000..72a11ec
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. ./config
+export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+export TET_ROOT=$TET_TARGET_PATH
diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh
new file mode 100755 (executable)
index 0000000..5ddaa53
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./config
+export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+export TET_ROOT=$TET_TARGET_PATH
diff --git a/TC/build.sh b/TC/build.sh
new file mode 100755 (executable)
index 0000000..72aad6c
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. ./_export_env.sh                              # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+FILE_NAME_EXTENSION=`date +%s`
+
+RESULT_DIR=results
+HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir -p $RESULT_DIR
+
+tcc -c -p ./
+tcc -b -j $JOURNAL_RESULT -p ./
+grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT
diff --git a/TC/clean.sh b/TC/clean.sh
new file mode 100755 (executable)
index 0000000..29743e0
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+. ./_export_env.sh                              # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+RESULT_DIR=results
+
+tcc -c -p ./                                # executing tcc, with clean option (-c)
+rm -r $RESULT_DIR
+rm -r tet_tmp_dir
+rm testcase/tet_captured
diff --git a/TC/config b/TC/config
new file mode 100644 (file)
index 0000000..8b68019
--- /dev/null
+++ b/TC/config
@@ -0,0 +1,2 @@
+TET_INSTALL_HOST_PATH=/home/idkiller/work/tetware/TETware
+TET_INSTALL_TARGET_PATH=/mnt/nfs/tetware/TETware
diff --git a/TC/execute.sh b/TC/execute.sh
new file mode 100755 (executable)
index 0000000..a4f6095
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. ./_export_target_env.sh                    # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+FILE_NAME_EXTENSION=`date +%s`
+
+RESULT_DIR=results
+HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir -p $RESULT_DIR
+
+tcc -e -j $JOURNAL_RESULT -p ./
+grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT
diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile
new file mode 100755 (executable)
index 0000000..8cc3da8
--- /dev/null
@@ -0,0 +1,28 @@
+CC = gcc
+
+C_FILES = $(shell ls *.c)
+
+PKGS = dlog capi-system-device capi-system-power
+
+#TET_ROOT = /home/idkiller/work/tetware/TETware/tetware-target
+
+LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s
+LDFLAGS += `pkg-config --libs $(PKGS)`
+
+CFLAGS += `pkg-config --cflags $(PKGS)`
+CFLAGS += -I.
+CFLAGS += -I$(TET_ROOT)/inc/tet3
+CFLAGS += -Wall
+
+#TARGETS = $(C_FILES:%.c=tc-%)
+TCS := $(shell ls -1 *.c | cut -d. -f1)
+
+all: $(TCS)
+
+%: %.c
+       $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
+
+clean:
+       rm -f $(TCS)
diff --git a/TC/testcase/tslist b/TC/testcase/tslist
new file mode 100644 (file)
index 0000000..9517124
--- /dev/null
@@ -0,0 +1,3 @@
+/testcase/utc_system_device_battery
+/testcase/utc_system_device_brightness
+
diff --git a/TC/testcase/utc_system_device_battery.c b/TC/testcase/utc_system_device_battery.c
new file mode 100644 (file)
index 0000000..a93ba00
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+#include <tet_api.h>
+#include <device.h>
+
+#define API_NAME_DEVICE_BATTERY_GET_PERCENT "device_battery_get_percent"
+#define API_NAME_DEVICE_BATTERY_IS_FULL "device_battery_is_full"
+#define API_NAME_DEVICE_BATTERY_IS_CHARGING "device_battery_is_charging"
+#define API_NAME_DEVICE_BATTERY_SET_CB "device_battery_set_cb"
+#define API_NAME_DEVICE_BATTERY_UNSET_CB "device_battery_unset_cb"
+
+static void startup(void);
+static void cleanup(void);
+
+void (*tet_startup)(void) = startup;
+void (*tet_cleanup)(void) = cleanup;
+
+static void utc_system_device_battery_get_percent_p(void);
+static void utc_system_device_battery_get_percent_n(void);
+static void utc_system_device_battery_is_full_p(void);
+static void utc_system_device_battery_is_full_n(void);
+static void utc_system_device_battery_is_charging_p(void);
+static void utc_system_device_battery_is_charging_n(void);
+static void utc_system_device_battery_set_cb_p(void);
+static void utc_system_device_battery_set_cb_n(void);
+static void utc_system_device_battery_unset_cb_p(void);
+
+
+enum {
+       POSITIVE_TC_IDX = 0x01,
+       NEGATIVE_TC_IDX,
+};
+
+struct tet_testlist tet_testlist[] = {
+       { utc_system_device_battery_get_percent_p, POSITIVE_TC_IDX },
+       { utc_system_device_battery_get_percent_n, NEGATIVE_TC_IDX },
+       { utc_system_device_battery_is_full_p, POSITIVE_TC_IDX },
+       { utc_system_device_battery_is_full_n, NEGATIVE_TC_IDX },
+       { utc_system_device_battery_is_charging_p, POSITIVE_TC_IDX },
+       { utc_system_device_battery_is_charging_n, NEGATIVE_TC_IDX },
+       { utc_system_device_battery_set_cb_p, POSITIVE_TC_IDX },
+       { utc_system_device_battery_set_cb_n, NEGATIVE_TC_IDX },
+       { utc_system_device_battery_unset_cb_p, POSITIVE_TC_IDX },
+       { NULL, 0},
+};
+
+static void startup(void)
+{
+       /* start of TC */
+}
+
+static void cleanup(void)
+{
+       /* end of TC */
+}
+
+/**
+ * @brief Positive test case of device_battery_get_percent()
+ */
+static void utc_system_device_battery_get_percent_p(void)
+{
+    int percent = 0;
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_get_percent(&percent);
+
+    dts_check_eq(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE);
+}
+
+/**
+ * @brief Negative test case of device_battery_get_percent()
+ */
+static void utc_system_device_battery_get_percent_n(void)
+{
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_get_percent(NULL);
+
+    dts_check_ne(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE);
+}
+
+/**
+ * @brief Positive test case of device_battery_is_full()
+ */
+static void utc_system_device_battery_is_full_p(void)
+{
+    bool full;
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_is_full(&full);
+    dts_check_eq(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE);
+}
+
+/**
+ * @brief Negative test case of device_battery_is_full()
+ */
+static void utc_system_device_battery_is_full_n(void)
+{
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_is_full(NULL);
+    dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE);
+}
+
+
+static void utc_system_device_battery_is_charging_p(void)
+{
+    bool charging;
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_is_charging(&charging);
+    dts_check_eq(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE);
+}
+
+static void utc_system_device_battery_is_charging_n(void)
+{
+    bool charging;
+    int error = DEVICE_ERROR_NONE;
+    error = device_battery_is_charging(NULL);
+    dts_check_ne(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE);
+}
+
+static void battery_cb(int percent, void *user_data)
+{
+}
+
+static void utc_system_device_battery_set_cb_p(void)
+{
+    int error = device_battery_set_cb(battery_cb, NULL);
+    device_battery_unset_cb();
+    dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
+}
+
+static void utc_system_device_battery_set_cb_n(void)
+{
+    int error = device_battery_set_cb(NULL, NULL);
+    device_battery_unset_cb();
+    dts_check_ne(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
+}
+
+static void utc_system_device_battery_unset_cb_p(void)
+{
+    device_battery_set_cb(battery_cb, NULL);
+    int error = device_battery_unset_cb();
+    dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
+}
diff --git a/TC/testcase/utc_system_device_brightness.c b/TC/testcase/utc_system_device_brightness.c
new file mode 100644 (file)
index 0000000..3914e9f
--- /dev/null
@@ -0,0 +1,330 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+#include <tet_api.h>
+#include <device.h>
+#include <power.h>
+
+#define API_NAME_DEVICE_GET_DISPLAY_COUNT "device_get_display_numbers"
+#define API_NAME_DEVICE_GET_BRIGHTNESS "device_get_brightness"
+#define API_NAME_DEVICE_GET_MAX_BRIGHTNESS "device_get_max_brightness"
+#define API_NAME_DEVICE_SET_BRIGHTNESS "device_set_brightness"
+#define API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS "device_set_brightness_from_settings"
+
+static void startup(void);
+static void cleanup(void);
+
+void (*tet_startup)(void) = startup;
+void (*tet_cleanup)(void) = cleanup;
+
+
+static void utc_system_device_get_display_numbers_p(void);
+static void utc_system_device_get_brightness_p(void);
+static void utc_system_device_get_brightness_n_1(void);
+static void utc_system_device_get_brightness_n_2(void);
+static void utc_system_device_get_max_brightness_p(void);
+static void utc_system_device_get_max_brightness_n_1(void);
+static void utc_system_device_get_max_brightness_n_2(void);
+static void utc_system_device_set_brightness_p_1(void);
+static void utc_system_device_set_brightness_p_2(void);
+static void utc_system_device_set_brightness_n_1(void);
+static void utc_system_device_set_brightness_n_2(void);
+static void utc_system_device_set_brightness_from_settings_p(void);
+static void utc_system_device_set_brightness_from_settings_n(void);
+
+
+enum {
+       POSITIVE_TC_IDX = 0x01,
+       NEGATIVE_TC_IDX,
+};
+
+struct tet_testlist tet_testlist[] = {
+    { utc_system_device_get_display_numbers_p, POSITIVE_TC_IDX},
+       { utc_system_device_get_brightness_p, POSITIVE_TC_IDX },
+       { utc_system_device_get_brightness_n_1, NEGATIVE_TC_IDX },
+       { utc_system_device_get_brightness_n_2, NEGATIVE_TC_IDX },
+       { utc_system_device_get_max_brightness_p, POSITIVE_TC_IDX },
+       { utc_system_device_get_max_brightness_n_1, NEGATIVE_TC_IDX },
+       { utc_system_device_get_max_brightness_n_2, NEGATIVE_TC_IDX },
+       { utc_system_device_set_brightness_p_1, POSITIVE_TC_IDX },
+       { utc_system_device_set_brightness_p_2, POSITIVE_TC_IDX },
+       { utc_system_device_set_brightness_n_1, NEGATIVE_TC_IDX },
+       { utc_system_device_set_brightness_n_2, NEGATIVE_TC_IDX },
+       { utc_system_device_set_brightness_from_settings_p, POSITIVE_TC_IDX },
+       { utc_system_device_set_brightness_from_settings_n, NEGATIVE_TC_IDX },
+       { NULL, 0},
+};
+
+static int cnt;
+
+static void startup(void)
+{
+       /* start of TC */
+    power_wakeup(false);
+    power_lock_state(POWER_STATE_NORMAL, 0);
+
+    device_get_display_numbers(&cnt);
+}
+
+static void cleanup(void)
+{
+       /* end of TC */
+    power_unlock_state(POWER_STATE_NORMAL);
+}
+
+static void utc_system_device_get_display_numbers_p(void)
+{
+    int _cnt, err;
+    err = device_get_display_numbers(&_cnt);
+
+    if(err < 0){
+        dts_fail(API_NAME_DEVICE_GET_DISPLAY_COUNT);
+    }
+    else{
+        dts_pass(API_NAME_DEVICE_GET_DISPLAY_COUNT);
+    }
+}
+
+/**
+ * @brief Positive test case of device_get_brightness()
+ */
+static void utc_system_device_get_brightness_p(void)
+{
+    int i;
+    int value = 0;
+    int error = DEVICE_ERROR_NONE;
+
+    for(i=0; i<cnt; i++){
+        error = device_get_brightness(i, &value);
+
+        if (error != DEVICE_ERROR_NONE){
+            dts_fail(API_NAME_DEVICE_GET_BRIGHTNESS);
+        }
+
+        if (value < 0){
+            dts_fail(API_NAME_DEVICE_GET_BRIGHTNESS);
+        }
+    }
+
+    dts_pass(API_NAME_DEVICE_GET_BRIGHTNESS);
+}
+
+/**
+ * @brief Negative test case of device_get_brightness() with bad display parameter
+ */
+static void utc_system_device_get_brightness_n_1(void)
+{
+    int value = 0;
+    int error = DEVICE_ERROR_NONE;
+    
+    error = device_get_brightness(cnt+1, &value);
+    dts_check_ne(API_NAME_DEVICE_GET_BRIGHTNESS, error, DEVICE_ERROR_NONE);
+}
+
+/**
+ * @brief Negative test case of device_get_brightness() with null pointer
+ */
+static void utc_system_device_get_brightness_n_2(void)
+{
+    int value = 0, i=0;
+    int error = DEVICE_ERROR_NONE;
+
+    for(i=0; i<cnt; i++){
+        error = device_get_brightness(i, NULL);
+
+        if(error == DEVICE_ERROR_NONE){
+            dts_fail(API_NAME_DEVICE_GET_BRIGHTNESS);
+        }
+    }
+    dts_pass(API_NAME_DEVICE_GET_BRIGHTNESS);
+}
+
+/**
+ * @brief Positive test case of device_get_max_brightness()
+ */
+static void utc_system_device_get_max_brightness_p(void)
+{
+    int value = 0, i=0;
+    int error = DEVICE_ERROR_NONE;
+
+    for(i=0; i<cnt; i++){
+        error = device_get_max_brightness(i, &value);
+
+        if(error != DEVICE_ERROR_NONE){
+            dts_fail(API_NAME_DEVICE_GET_MAX_BRIGHTNESS);
+        }
+    }
+    dts_pass(API_NAME_DEVICE_GET_MAX_BRIGHTNESS);
+}
+
+/**
+ * @brief Negative test case of device_get_max_brightness() with bad display parameter
+ */
+static void utc_system_device_get_max_brightness_n_1(void)
+{
+    int value = 0;
+    int error = DEVICE_ERROR_NONE;
+    error = device_get_max_brightness(cnt+1, &value);
+
+    dts_check_ne(API_NAME_DEVICE_GET_MAX_BRIGHTNESS, error, DEVICE_ERROR_NONE);
+}
+
+/**
+ * @brief Negative test case of device_get_max_brightness() with null pointer
+ */
+static void utc_system_device_get_max_brightness_n_2(void)
+{
+    int error = DEVICE_ERROR_NONE, i=0;
+
+    for(i=0; i<cnt; i++){
+        error = device_get_max_brightness(i, NULL);
+
+        if(error == DEVICE_ERROR_NONE){
+            dts_fail(API_NAME_DEVICE_GET_MAX_BRIGHTNESS);
+        }
+    }
+    dts_pass(API_NAME_DEVICE_GET_MAX_BRIGHTNESS);
+}
+
+/**
+ * @brief Positive test case of device_set_brightness()
+ */
+static void utc_system_device_set_brightness_p_1(void)
+{
+    int i=0;
+    int err;
+
+    dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "!@#$ cnt=%d", cnt);
+
+    for(i=0; i<cnt; i++){
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "index=%d", i);
+        err = device_set_brightness(i, 0);
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "error=%d", err);
+        if(err != DEVICE_ERROR_NONE) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+    }
+    dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS);
+}
+
+/**
+ * @brief Positive test case of device_set_brightness()
+ */
+static void utc_system_device_set_brightness_p_2(void)
+{
+    int setting = 0;
+    int max_value = 0;
+    int value = 0, i=0;
+
+    for(i=0; i<cnt; i++){
+        if( device_get_max_brightness(i, &max_value) != DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+
+        if( max_value < 0 ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+
+        setting = max_value > 1 ? max_value / 2 : 1;
+
+        if( device_set_brightness(i, setting) != DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "brightness=%d", setting);
+
+
+        if ( device_get_brightness(i, &value) != DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "brightness=%d", value);
+
+        if ( value != setting ){
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+    }
+
+    dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS);
+}
+
+/**
+ * @brief Negative test case of device_set_brightness()
+ */
+static void utc_system_device_set_brightness_n_1(void)
+{
+    int i=0;
+    int max_value = 0;
+
+    for(i=0; i<cnt; i++){
+        if( device_get_max_brightness(i, &max_value) != DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS, "fail get_max_brightness");
+        }
+
+        if( device_set_brightness(i, max_value+1) == DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS, "fail set_brightness");
+        }
+    }
+
+    dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS);
+}
+
+/**
+ * @brief Negative test case of device_set_brightness()
+ */
+static void utc_system_device_set_brightness_n_2(void)
+{
+    int i=0;
+
+    for(i=0; i<cnt; i++){
+        if( device_set_brightness(i, -1) == DEVICE_ERROR_NONE ) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS);
+        }
+    }
+
+    dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS);
+}
+
+/**
+ * @brief Positive test case of device_set_brightness_from_settings()
+ */
+static void utc_system_device_set_brightness_from_settings_p(void)
+{
+    int i, error;
+
+    dts_message(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS, "display cnt=%d", cnt);
+
+    for(i=0; i<cnt; i++){
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS, "index=%d", i);
+        error = device_set_brightness_from_settings(i);
+        dts_message(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS, "error=%d", error);
+        if(error != DEVICE_ERROR_NONE) {
+            dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS);
+        }
+    }
+    dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS);
+}
+
+/**
+ * @brief Negative test case of device_set_brightness_from_settings() with bad display parameter
+ */
+static void utc_system_device_set_brightness_from_settings_n(void)
+{
+       int error = DEVICE_ERROR_NONE;
+
+       error = device_set_brightness_from_settings(cnt+1);
+
+       dts_check_ne(API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS, error, DEVICE_ERROR_NONE);
+}
diff --git a/TC/tet_scen b/TC/tet_scen
new file mode 100755 (executable)
index 0000000..03f029a
--- /dev/null
@@ -0,0 +1,7 @@
+all
+       ^TEST
+##### Scenarios for TEST #####
+
+# Test scenario
+TEST
+       :include:/testcase/tslist
diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg
new file mode 100644 (file)
index 0000000..f7eda55
--- /dev/null
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capture option for build operation checking
+TET_BUILD_TOOL=make # build with using make command
+TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build
+TET_API_COMPLIANT=True # use TET API in Test Case ?
+TET_PASS_TC_NAME=True # report passed TC name in Journal file?
diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg
new file mode 100644 (file)
index 0000000..02d7030
--- /dev/null
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capture option
+TET_CLEAN_TOOL= make clean # clean tool
+TET_CLEAN_FILE= Makefile # file for clean
+TET_API_COMPLIANT=True # TET API useage 
+TET_PASS_TC_NAME=True # showing name , passed TC
diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg
new file mode 100644 (file)
index 0000000..ef3e452
--- /dev/null
@@ -0,0 +1,5 @@
+TET_OUTPUT_CAPTURE=True # capturing execution or not
+TET_EXEC_TOOL=  # ex) exec : execution tool set up/ Optional
+TET_EXEC_FILE=   # ex) exectool : execution file/ Optional
+TET_API_COMPLIANT=True # Test case or Tool usesTET API?
+TET_PASS_TC_NAME=True # showing Passed TC name ?
diff --git a/capi-system-device.pc.in b/capi-system-device.pc.in
new file mode 100644 (file)
index 0000000..d0610b9
--- /dev/null
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/system
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@ 
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/include/device.h b/include/device.h
new file mode 100755 (executable)
index 0000000..93fabd3
--- /dev/null
@@ -0,0 +1,613 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. 
+ */
+
+
+
+
+#ifndef __TIZEN_SYSTEM_DEVICE_H__
+#define __TIZEN_SYSTEM_DEVICE_H__
+
+#include <stdbool.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumerations of error code for Device.
+ */
+typedef enum
+{
+    DEVICE_ERROR_NONE              = TIZEN_ERROR_NONE,                  /**< Successful */
+    DEVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
+    DEVICE_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */
+    DEVICE_ERROR_NOT_SUPPORTED     = TIZEN_ERROR_SYSTEM_CLASS | 0x13, /**< Not supported in this device */
+} device_error_e;
+
+/**
+ * @brief Enumerations of the battery warning status
+ */
+typedef enum
+{
+    DEVICE_BATTERY_WARN_EMPTY,      /**< The battery goes empty. Prepare for the safe termination of the application, because the device starts a shutdown process soon after entering this level. */
+    DEVICE_BATTERY_WARN_CRITICAL,  /**< The battery charge is at a critical state. You may have to stop using multimedia features, because they are not guaranteed to work correctly at this battery status. */
+    DEVICE_BATTERY_WARN_LOW,       /**< The battery has little charge left. */
+    DEVICE_BATTERY_WARN_NORMAL,    /**< The battery status is not to be careful. */
+    DEVICE_BATTERY_WARN_FULL,      /**< The battery status is full. */
+} device_battery_warn_e;
+
+/**
+ * @brief Enumerations of the battery remaining time type
+ */
+typedef enum
+{
+    DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED,
+    DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED
+} device_battery_remaining_time_type_e;
+
+/**
+ * @brief Enumerations of the battery level status
+ */
+typedef enum
+{
+    DEVICE_BATTERY_LEVEL_EMPTY = 0,      /**< The battery goes empty. Prepare for the safe termination of the application, because the device starts a shutdown process soon after entering this level. */
+    DEVICE_BATTERY_LEVEL_CRITICAL,  /**< The battery charge is at a critical state. You may have to stop using multimedia features, because they are not guaranteed to work correctly at this battery status. */
+    DEVICE_BATTERY_LEVEL_LOW,       /**< The battery has little charge left. */
+    DEVICE_BATTERY_LEVEL_HIGH,    /**< The battery status is not to be careful. */
+    DEVICE_BATTERY_LEVEL_FULL,      /**< The battery status is full. */
+} device_battery_level_e;
+
+
+/**
+ * @brief Structure of the time information system spent, measured in units of USER_HZ
+ */
+typedef struct {
+       unsigned long long total;
+       unsigned long long user;
+       unsigned long long nice;
+       unsigned long long system;
+       unsigned long long idle;
+       unsigned long long iowait;
+       unsigned long long irq;
+       unsigned long long softirq;
+} device_system_time_s;
+
+/**
+ * @}
+*/
+
+ /**
+ * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when an battery charge percentage changed
+ *
+ * @param[in] percent       The remaining battery charge percentage (0 ~ 100)
+ * @param[in] user_data     The user data passed from the callback registration function
+ *
+ */
+typedef void (*device_battery_cb)(int percent, void *user_data); 
+
+/**
+ * @brief Called when the device warn about the battery status.
+ *
+ * @param[in] status       The battery warning status
+ * @param[in] user_data    The user data passed from the callback registration function
+ *
+ */
+typedef void (*device_battery_warn_cb)(device_battery_warn_e status, void *user_data);
+
+/**
+ * @brief This callback take remained time for fully charged or discharged.
+ *
+ * @param[in] time         The battery remainig seconds to fully chagred or discharged
+ * @param[in] user_data    The user data passed from the callback registration function
+ *
+ */
+typedef void (*device_battery_remaining_time_changed_cb)(int time, void* user_data);
+
+/**
+ * @brief Called when an battery level changed
+ *
+ * @param[in] status       The remaining battery level (empty[0~1] critical[2~5] low[6~15] high[16~94] full[95~100])
+ * @param[in] user_data     The user data passed from the callback registration function
+ *
+ */
+typedef void (*device_battery_level_cb)(device_battery_level_e status, void *user_data);
+
+/**
+ * @brief Gets the battery warning status.
+ *
+ * @param[out] status The battery warning status.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_status_e
+ * @see device_battery_status_set_cb()
+ */
+int device_battery_get_warning_status(device_battery_warn_e *status);
+
+/**
+ * @brief Set callback to be observing battery warning.
+ *
+ * @param[in] callback      The callback function to set
+ * @param[in] user_data     The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_status_e
+ * @see device_battery_get_status()
+ */
+int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data);
+
+/**
+ * @brief Unset battery warning callback function.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE               Successful
+ * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
+ */
+int device_battery_warning_unset_cb(void);
+
+/**
+ * @brief Gets the battery charge percentage.
+ * @details It returns integer value from 0 to 100 that indicates remaining battery charge
+ * as a percentage of the maximum level.
+ * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
+ *
+ * @param[out] percent The remaining battery charge percentage (0 ~ 100) 
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_is_full()
+ * @see device_battery_get_detail()
+ * @see device_battery_set_cb()
+ */
+int device_battery_get_percent(int *percent);
+
+/**
+ * @brief Gets the battery detail charge as a per ten thousand.
+ * @details It return integer value from 0 to 10000 that indicates remaining battery charge as a per ten thousand of the maximum level.
+ * @remarks this function return #DEVICE_ERROR_NOT_SUPPORTED when device can not be supported detail battery information.
+ *
+ * @param[out] detail   The remaining battery charge as a per ten thousand. (0 ~ 10000)
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED      Not supported device
+ *
+ * @see device_battery_is_full()
+ * @see device_battery_get_percent()
+ * @see device_battery_set_cb()
+ */
+int device_battery_get_detail(int *detail);
+
+/**
+ * @brief Get charging state
+ *
+ * @param[out] charging The battery charging state.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ */
+int device_battery_is_charging(bool *charging);
+
+/**
+ * @brief Set callback to be observing battery charge percentage.
+ *
+ * @param[in] callback      The callback function to set
+ * @param[in] user_data     The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_battery_set_cb(device_battery_cb callback, void* user_data);
+
+/**
+ * @brief Unset battery charge percentage callback function.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_battery_unset_cb(void);
+
+/**
+ * @brief Checks whether the battery is fully charged.
+ * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
+ *
+ * @param[out] full @c true when the battery is fully charged, otherwise @c false.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_get_percent()
+ * @see        system_info_set_changed_cb()
+ * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_PERCENTAGE, ...)
+ * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_CHARGE, ...)
+ */
+int device_battery_is_full(bool *full);
+
+/**
+ * @brief Retrive the remaining time for fully charged or discharged.
+ *
+ * @remark @a time will be retrieved the time to fully charged or discharged depending on @a type
+ *
+ * @param[in]  type   The type of battery remaining time
+ * @param[out] time   battery remainig seconds to fully chagred or discharged
+
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_set_remaining_time_changed_cb()
+ * @see device_battery_unset_remaining_time_changed_cb()
+ */
+int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time);
+
+/**
+ * @brief Set callback to be return battery remaining time to fully charged or discharged.
+ *
+ * @remark @a callback will be retrieved the time to fully charged or discharged depending on @a type
+ *
+ * @param[in] callback      The callback function to set
+ * @param[in] user_data     The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ */
+int device_battery_set_remaining_time_changed_cb(
+        device_battery_remaining_time_type_e type,
+        device_battery_remaining_time_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unset battery remaining time callback function.
+ *
+ * @param[in] type The type of battery remainig time
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type);
+
+/**
+ * @brief Gets the battery level status.
+ *
+ * @param[out] status The battery level status.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_level_e
+ * @see device_battery_level_set_cb()
+ */
+int device_battery_get_level_status(device_battery_level_e *status);
+
+/**
+ * @brief Set/Unset callback to be observing battery level.
+ *
+ * @param[in] callback      The callback function to set, if you input NULL, observing is disabled
+ * @param[in] user_data     The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                  Successful
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_battery_level_e
+ * @see device_battery_get_level_status()
+ */
+int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data);
+
+/**
+ * @brief Gets the number of display devices.
+ *
+ * @return The number of display devices that the device provides.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ *
+ * @see        device_get_brightness()
+ * @see device_set_brightness()
+ * @see device_get_max_brightness()
+ * @see device_set_brightness_from_settings()
+ * @see device_set_brightness_to_settings()
+ */
+int device_get_display_numbers(int* device_number);
+
+/**
+ * @brief Gets the display brightness value.
+ *
+ * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
+ *                          the number of displays returned by device_get_display_numbers().\n
+ *                          The index zero is always assigned to the main display.
+ * @param[out] brightness      The current brightness value of the display
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_get_display_numbers()
+ * @see device_set_brightness()
+ * @see device_get_max_brightness()
+ * @see device_set_brightness_from_settings()
+ * @see device_set_brightness_to_settings()
+ */
+int device_get_brightness(int display_index, int *brightness);
+
+/**
+ * @brief Sets the display brightness value. 
+ *
+ * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
+ *                          the number of displays returned by device_get_display_numbers().\n
+ *                          The index zero is always assigned to the main display.
+ * @param[in] brightness       The new brightness value to set \n
+ *                                                     The maximum value can be represented by device_get_max_brightness()
+ * 
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
+ *
+ * @see device_get_display_numbers()
+ * @see device_get_max_brightness()
+ * @see device_get_brightness()
+ * @see device_set_brightness_from_settings()
+ * @see device_set_brightness_to_settings()
+ */
+int device_set_brightness(int display_index, int brightness);
+
+/**
+ * @brief Gets the maximum brightness value that can be set. 
+ *
+ * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
+ *                          the number of displays returned by device_get_display_numbers().\n
+ *                          The index zero is always assigned to the main display.
+ * @param[out] max_brightness  The maximum brightness value of the display
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_get_display_numbers()
+ * @see device_set_brightness()
+ * @see device_get_brightness()
+ * @see device_set_brightness_from_settings()
+ * @see device_set_brightness_to_settings()
+ */
+int device_get_max_brightness(int display_index, int *max_brightness);
+
+/**
+ * @brief Sets the display brightness value from registed in settings.
+ *
+ * @details
+ * This function set display brightness to condition in the settings.
+ * if auto brightness option is enabled in setting, display's brightness will be changed automatically.
+ *
+ * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
+ *                          the number of displays returned by device_get_display_numbers().\n
+ *                          The index zero is always assigned to the main display.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_get_display_numbers()
+ * @see device_get_max_brightness()
+ * @see device_set_brightness()
+ * @see device_get_brightness()
+ * @see device_set_brightness_to_settings()
+ */
+int device_set_brightness_from_settings(int display_index);
+
+/**
+ * @brief Sets the display brightness value to specific display and set to variable in settings.
+ *
+ * @details
+ * This function set given brightness value to given index of display.
+ * And also brightness variable in settings will be changed to given brightness value too.
+ *
+ * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
+ *                          the number of displays returned by device_get_display_numbers().\n
+ *                          The index zero is always assigned to the main display.
+ * @param[in] brightness       The new brightness value to set \n
+ *                                                     The maximum value can be represented by device_get_max_brightness()
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ *
+ * @see device_get_display_numbers()
+ * @see device_get_max_brightness()
+ * @see device_set_brightness()
+ * @see device_get_brightness()
+ * @see device_set_brightness_from_settings()
+ */
+int device_set_brightness_to_settings(int display_index, int brightness);
+
+/**
+ * @brief Get brightness value of LED that placed to camera flash.
+ *
+ * @param[out] brightness brightness value of LED (0 ~ MAX)
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_flash_get_brightness(int *brightness);
+
+/**
+ * @brief Set brightness value of LED that placed to camera flash.
+ *
+ * @param[in] brightness brightness value of LED (0 ~ MAX)
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_flash_set_brightness(int brightness);
+
+/**
+ * @brief Get max brightness value of LED that placed to camera flash.
+ *
+ * @remark
+ * Brightness control does not support yet. so this functioon always return 1. \n
+ * Set function can only use to switch on/off the flash. \n
+ * Get function can only use to retrive on/off state of flash.
+ *
+ * @param[out] max_brightness max brightness value of LED
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_flash_get_max_brightness(int *max_brightness);
+
+/**
+ * @brief Get total amount of physical RAM, in kilobytes
+ *
+ * @remark
+ *
+ * @param[out] total_mem total amount of physical RAM
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_memory_get_total(unsigned int *total_mem);
+
+/**
+ * @brief Get available amount of physical RAM, in kilobytes
+ *
+ * @remark
+ * Available amount is defined by following formula currently.
+ * available mem = MemFree+Buffers+Cached+SwapCached-Shmem
+ *
+ * @param[out] avail_mem available amount of physical RAM
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_memory_get_available(unsigned int *avail_mem);
+
+/**
+ * @brief Get time information the CPU has spent performing work.
+ *
+ * @remark
+ * Time units are in USER_HZ (typically hundredths of a second).
+ *
+ * @param[out] time structure of time information the CPU has spent
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_cpu_get_system_time(device_system_time_s *time);
+
+/**
+ * @brief Get all of CPU count
+ *
+ * @remark
+ *
+ * @param[out] cpu_cnt total count of CPU
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_cpu_get_count(int *cpu_cnt);
+
+/**
+ * @brief Get currently frequency of CPU
+ *
+ * @remark
+ *
+ * @param[in]  cpu the index of CPU which want to know
+ * @param[out] cur_freq currently frequency value of CPU
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq);
+
+/**
+ * @brief Get max frequency of CPU
+ *
+ * @remark
+ *
+ * @param[in]  cpu the index of CPU which want to know
+ * @param[out] max_freq max frequency value of CPU
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #DEVICE_ERROR_NONE                          Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED      Operation failed
+ */
+int device_cpu_get_max_freq(int cpu, unsigned int *max_freq);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // __TIZEN_SYSTEM_DEVICE_H__
diff --git a/include/device_doc.h b/include/device_doc.h
new file mode 100755 (executable)
index 0000000..00bad5b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_SYSTEM_DEVICE_DOC_H__
+#define __TIZEN_SYSTEM_DEVICE_DOC_H__
+
+/**
+ * @defgroup CAPI_SYSTEM_DEVICE_MODULE
+ * @brief  The DEVICE API provides functions to control devices or to get status of devices.
+ * @ingroup CAPI_SYSTEM_FRAMEWORK
+ *
+ * @section CAPI_SYSTEM_DEVICE_MODULE_HEADER Required Header
+ *   \#include <device.h>
+ *
+ * @section CAPI_SYSTEM_DEVICE_MODULE_OVERVIEW Overview
+ * The DEVICE API provides function to control devices or to get status of devices.
+ *
+ *  This API allows checking the following parameters:
+ * - Battery
+ * - Display
+ * - Flash (Camera torch light)
+ * - Memory
+ * - CPU
+ *
+ */
+
+#endif /* __TIZEN_SYSTEM_DEVICE_DOC_H__ */
diff --git a/include/device_log.h b/include/device_log.h
new file mode 100644 (file)
index 0000000..8752926
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DEVICE_LOG_H__
+#define __DEVICE_LOG_H__
+
+#ifdef FEATURE_DEVICE_DLOG
+    #define LOG_TAG "SYSTEM_DEVICE"
+    #include <dlog.h>
+    #define DEVICE_LOG(fmt, args...)       SLOGD(fmt, ##args)
+    #define DEVICE_ERROR(fmt, args...)     SLOGE(fmt, ##args)
+#else
+    #define DEVICE_LOG(x, ...)
+    #define DEVICE_ERROR(x, ...)
+#endif
+
+#endif /* __DEVICE_LOG_H__ */
diff --git a/packaging/capi-system-device.manifest b/packaging/capi-system-device.manifest
new file mode 100644 (file)
index 0000000..b631abe
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+<request>
+       <domain  name="_"/>
+</request>
+</manifest>
diff --git a/packaging/capi-system-device.spec b/packaging/capi-system-device.spec
new file mode 100644 (file)
index 0000000..103f2fc
--- /dev/null
@@ -0,0 +1,73 @@
+Name:       capi-system-device
+Summary:    A Device library in TIZEN C API
+Version:    0.1.0
+Release:    18
+Group:      System/Libraries
+License:    Apache License, Version 2.0
+Source0:    %{name}-%{version}.tar.gz
+Source1:    capi-system-device.manifest
+BuildRequires:  cmake
+%if "%{_repository}" == "wearable"
+BuildRequires:  pkgconfig(deviced)
+%else
+BuildRequires:  pkgconfig(devman)
+%endif
+BuildRequires:  pkgconfig(capi-base-common)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(vconf)
+
+Requires(post): /sbin/ldconfig  
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary:  A Device library in TIZEN C API (Development)
+Group:    TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS+=" -DTIZEN_ENGINEER_MODE"
+%endif
+cp %{SOURCE1} .
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%if "%{_repository}" == "wearable"
+%define ARCH wearable
+%else
+%define ARCH mobile
+%endif
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=%{ARCH}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%manifest capi-system-device.manifest
+%{_libdir}/libcapi-system-device.so.*
+%{_datadir}/license/%{name}
+
+%files devel
+%{_includedir}/system/device.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-system-device.so
diff --git a/src/mobile/battery.c b/src/mobile/battery.c
new file mode 100644 (file)
index 0000000..555cecc
--- /dev/null
@@ -0,0 +1,410 @@
+/*
+ * capi-system-device
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <devman.h>
+#include <vconf.h>
+#include "device.h"
+#include "device_log.h"
+
+#define CHECK_ERR(val) \
+       do {    \
+               if (val == DEVMAN_ERROR_NOT_SUPPORTED)  \
+                       return DEVICE_ERROR_NOT_SUPPORTED;      \
+               else if (val == DEVMAN_ERROR_OPERATION_FAILED)  \
+                       return DEVICE_ERROR_OPERATION_FAILED;   \
+       } while(0)
+
+int device_battery_get_percent(int* percent)
+{
+       if (percent == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int pct = device_get_battery_pct();
+       CHECK_ERR(pct);
+
+       *percent = pct;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_detail(int* percent)
+{
+       if (percent == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int pct = device_get_battery_pct_raw();
+       CHECK_ERR(pct);
+
+       *percent = pct;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_is_full(bool* full)
+{
+       if (full == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int f = device_is_battery_full();
+       CHECK_ERR(f);
+
+       *full = (f == 1) ? true : false;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_is_charging(bool *charging)
+{
+       // VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW
+       int value, err;
+
+       if (charging == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == 1) {
+               *charging = true;
+       } else if (value == 0) {
+               *charging = false;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_cb changed_callback = NULL;
+static void* changed_callback_user_data = NULL;
+
+static void battery_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) {
+               int percent = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) {
+                       changed_callback(percent, changed_callback_user_data);
+               }
+       }
+}
+
+int device_battery_set_cb(device_battery_cb callback, void* user_data)
+{
+       // VCONFKEY_SYSMAN_BATTERY_CAPACITY
+       int err;
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       changed_callback = callback;
+       changed_callback_user_data = user_data;
+
+       err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL);
+       if (err < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_unset_cb(void)
+{
+       int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       changed_callback = NULL;
+       changed_callback_user_data = NULL;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_warning_status(device_battery_warn_e *status)
+{
+       if (status == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int value, err;
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) {
+               *status = DEVICE_BATTERY_WARN_EMPTY;
+       } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
+               *status = DEVICE_BATTERY_WARN_CRITICAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
+               *status = DEVICE_BATTERY_WARN_LOW;
+       } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) {
+               *status = DEVICE_BATTERY_WARN_NORMAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_FULL) {
+               *status = DEVICE_BATTERY_WARN_FULL;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_warn_cb warn_changed_callback = NULL;
+static void* warn_changed_callback_user_data = NULL;
+static device_battery_level_cb level_changed_callback = NULL;
+static void* level_changed_callback_user_data = NULL;
+
+static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) {
+               int bat_state = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) {
+                       warn_changed_callback(bat_state-1, warn_changed_callback_user_data);
+               }
+       }
+}
+
+static void battery_level_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname;
+       keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && level_changed_callback != NULL &&
+           strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS) == 0) {
+               int bat_state = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &bat_state) == 0) {
+                       level_changed_callback(bat_state, level_changed_callback_user_data);
+               }
+       }
+}
+
+int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data)
+{
+       // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW
+       int err;
+
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       warn_changed_callback = callback;
+       warn_changed_callback_user_data = user_data;
+
+       err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL);
+       if (err < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_warning_unset_cb(void)
+{
+       int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       warn_changed_callback = NULL;
+       warn_changed_callback_user_data = NULL;
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_remaining_time_changed_cb timetofull_changed_cb = NULL;
+static device_battery_remaining_time_changed_cb timetoempty_changed_cb = NULL;
+static void* timetofull_cb_user_data = NULL;
+static void* timetoempty_cb_user_data = NULL;
+
+static void device_battery_time_timetofull_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+       int time = -1, err= -1;
+
+       if (keyname == NULL)
+               return;
+
+       if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOFULL) == 0) {
+               if (timetofull_changed_cb != NULL) {
+                       err = device_battery_get_remaining_time(
+                               DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &time);
+                       if ((err == DEVICE_ERROR_NONE) && (time >= 0))
+                               timetofull_changed_cb(time, timetofull_cb_user_data);
+               }
+       }
+}
+
+static void device_battery_time_timetoempty_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+       int time = -1, err= -1;
+
+       if (keyname == NULL)
+               return;
+
+       if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOEMPTY) == 0) {
+               if (timetoempty_changed_cb != NULL) {
+                       err = device_battery_get_remaining_time(
+                               DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED, &time);
+                       if ((err == DEVICE_ERROR_NONE) && (time >= 0))
+                               timetoempty_changed_cb(time, timetoempty_cb_user_data);
+               }
+       }
+}
+
+int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time)
+{
+       bool charging = false;
+       int err = -1;
+
+       err = device_battery_is_charging(&charging);
+       if (err != DEVICE_ERROR_NONE)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       if (charging == false) {
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       } else {
+                               err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, time);
+                               if (err < 0 || time < 0) {
+                                       return DEVICE_ERROR_OPERATION_FAILED;
+                               }
+                       }
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       if (charging == true) {
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       } else {
+                               err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, time);
+                               if (err < 0 || time < 0) {
+                                       return DEVICE_ERROR_OPERATION_FAILED;
+                               }
+                       }
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_set_remaining_time_changed_cb(device_battery_remaining_time_type_e type,
+       device_battery_remaining_time_changed_cb callback, void* user_data)
+{
+       int err;
+
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       timetofull_changed_cb = callback;
+                       timetofull_cb_user_data = user_data;
+                       err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
+                               device_battery_time_timetofull_inside_cb, NULL);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       timetoempty_changed_cb = callback;
+                       timetoempty_cb_user_data = user_data;
+                       err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
+                               device_battery_time_timetoempty_inside_cb, NULL);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type)
+{
+       int err;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
+                               device_battery_time_timetofull_inside_cb);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       timetofull_changed_cb = NULL;
+                       timetofull_cb_user_data = NULL;
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
+                               device_battery_time_timetoempty_inside_cb);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       timetoempty_changed_cb = NULL;
+                       timetoempty_cb_user_data = NULL;
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_level_status(device_battery_level_e *status)
+{
+       int value, err;
+
+       if (status == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) {
+               *status = DEVICE_BATTERY_LEVEL_EMPTY;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) {
+               *status = DEVICE_BATTERY_LEVEL_CRITICAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) {
+               *status = DEVICE_BATTERY_LEVEL_LOW;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) {
+               *status = DEVICE_BATTERY_LEVEL_HIGH;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) {
+               *status = DEVICE_BATTERY_LEVEL_FULL;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data)
+{
+       int err;
+
+
+       if (callback == NULL) {
+               err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+                       battery_level_changed_inside_cb);
+       } else {
+
+               err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+                       battery_level_changed_inside_cb, NULL);
+       }
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       level_changed_callback = callback;
+       level_changed_callback_user_data = user_data;
+
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/mobile/cpu.c b/src/mobile/cpu.c
new file mode 100644 (file)
index 0000000..5754026
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * capi-system-device
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "device.h"
+#include "device_log.h"
+
+#define PROC_STAT              "/proc/stat"
+
+#define PROC_CPU_PRESENT                               "/sys/devices/system/cpu/present"
+#define PROC_SCALING_CUR_FREQ                  "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq"
+#define PROC_SCALING_MAX_FREQ                  "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq"
+
+
+int device_cpu_get_count(int *cpu_cnt)
+{
+       FILE *fp;
+       int ret;
+       int st, ed;
+
+       if (cpu_cnt == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       fp = fopen(PROC_CPU_PRESENT, "r");
+       if (!fp)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       ret = fscanf(fp, "%u-%u", &st, &ed);
+       fclose(fp);
+       if (ret != 2)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *cpu_cnt = ed+1;
+       return DEVICE_ERROR_NONE;
+}
+
+static int _get_systime(device_system_time_s *st)
+{
+       FILE *fp;
+       char buf[4096];
+       char *s;
+
+       assert(st);
+
+       fp = fopen(PROC_STAT, "r");
+       if (!fp)
+               return -1;
+
+       s = fgets(buf, sizeof(buf), fp);
+       fclose(fp);
+       if (!s)
+               return -1;
+
+       s = strchr(buf, ' ');
+       if (!s)
+               return -1;
+
+       s++;
+       st->user = strtol(s, &s, 10);
+       st->nice = strtol(s, &s, 10);
+       st->system = strtol(s, &s, 10);
+       st->idle = strtol(s, &s, 10);
+       st->iowait = strtol(s, &s, 10);
+       st->irq = strtol(s, &s, 10);
+       st->softirq = strtol(s, &s, 10);
+
+       return 0;
+}
+
+int device_cpu_get_system_time(device_system_time_s *time)
+{
+       int ret;
+       device_system_time_s st;
+
+       if (time == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_systime(&st);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       st.total = st.user+st.nice+st.system+st.idle+st.iowait+st.irq+st.softirq;
+       *time = st;
+       return DEVICE_ERROR_NONE;
+}
+
+static int _get_uint(const char *path, unsigned int *val)
+{
+       FILE *fp;
+       unsigned int num;
+       int ret;
+
+       assert(path);
+       assert(val);
+
+       fp = fopen(path, "r");
+       if (!fp)
+               return -1;
+
+       ret = fscanf(fp, "%u", &num);
+       fclose(fp);
+       if (ret != 1)
+               return -1;
+
+       *val = num;
+       return 0;
+}
+
+int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq)
+{
+       char path[FILENAME_MAX];
+       int ret;
+       int count;
+       unsigned int cur;
+
+       if (cur_freq == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_cpu_get_count(&count);
+       if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       snprintf(path, sizeof(path), PROC_SCALING_CUR_FREQ, cpu);
+       ret = _get_uint(path, &cur);
+       if (ret < 0)
+               cur = 0;
+
+       *cur_freq = cur;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_cpu_get_max_freq(int cpu, unsigned int *max_freq)
+{
+       char path[FILENAME_MAX];
+       int ret;
+       int count;
+       unsigned int max;
+
+       if (max_freq == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_cpu_get_count(&count);
+       if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       snprintf(path, sizeof(path), PROC_SCALING_MAX_FREQ, cpu);
+       ret = _get_uint(path, &max);
+       if (ret < 0)
+               max = 0;
+
+       *max_freq = max;
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/mobile/device.c b/src/mobile/device.c
new file mode 100644 (file)
index 0000000..d4fb899
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * capi-system-device
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <devman.h>
+#include "device.h"
+#include "device_log.h"
+
+#define CHECK_ERR(val) \
+       do {    \
+               if (val == DEVMAN_ERROR_NOT_SUPPORTED)  \
+                       return DEVICE_ERROR_NOT_SUPPORTED;      \
+               else if (val == DEVMAN_ERROR_OPERATION_FAILED)  \
+                       return DEVICE_ERROR_OPERATION_FAILED;   \
+       } while(0)
+
+static int _display[] = {
+       DEV_DISPLAY_0,
+       DEV_DISPLAY_1,
+};
+
+int device_get_display_numbers(int* device_number)
+{
+       if(device_number == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       *device_number = device_get_display_count();
+       CHECK_ERR(*device_number);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_get_brightness(int disp_idx, int* value)
+{
+       int val, disp, max_id, ret;
+
+       if(value == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       disp = _display[disp_idx];
+       val = device_get_display_brt(disp);
+       CHECK_ERR(val);
+
+       *value = val;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness(int disp_idx, int new_value)
+{
+       int max_value, val;
+       int disp, max_id, ret;
+
+       if(new_value < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       disp = _display[disp_idx];
+       ret = device_get_max_brightness(disp, &max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(new_value > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = device_set_display_brt(disp, new_value);
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_get_max_brightness(int disp_idx, int* max_value)
+{
+       int val, disp, max_id, ret;
+
+       if(max_value == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+       
+       disp = _display[disp_idx];
+       val = device_get_max_brt(disp);
+       CHECK_ERR(val);
+
+       *max_value = val;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness_from_settings(int disp_idx)
+{
+       int max_id, disp, val, ret;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       disp = _display[disp_idx];
+       val = device_release_brt_ctrl(disp);
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness_to_settings(int disp_idx, int new_value)
+{
+       int max_value, val;
+       int disp, max_id, ret;
+
+       if(new_value < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       disp = _display[disp_idx];
+       ret = device_get_max_brightness(disp, &max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(new_value > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = device_set_display_brt_with_settings(disp, new_value);
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_get_brightness(int *brightness)
+{
+       int value;
+
+       if (brightness == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = device_get_led_brt();
+       CHECK_ERR(value);
+
+       *brightness = value;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_set_brightness(int brightness)
+{
+       int max_value, value, ret;
+
+       ret = device_flash_get_max_brightness(&max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if (brightness < 0 || brightness > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = device_set_led_brt(brightness);
+       CHECK_ERR(value);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_get_max_brightness(int *max_brightness)
+{
+       int value;
+
+       if (max_brightness == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = device_get_max_led();
+       CHECK_ERR(value);
+
+       *max_brightness = value;
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/mobile/memory.c b/src/mobile/memory.c
new file mode 100644 (file)
index 0000000..04c0a7d
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * capi-system-device
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "device.h"
+#include "device_log.h"
+
+#define PROC_MEMORY            "/proc/meminfo"
+
+enum {
+       _MI_TOTAL,
+       _MI_FREE,
+       _MI_BUF,
+       _MI_CACHED,
+       _MI_SWAP,
+       _MI_SHMEM,
+       _MI_MAX,
+};
+
+struct meminfo {
+       unsigned long l[_MI_MAX];
+};
+
+static const char *_mi_str[] = {
+       [_MI_TOTAL] = "MemTotal",
+       [_MI_FREE] = "MemFree",
+       [_MI_BUF] = "Buffers",
+       [_MI_CACHED] = "Cached",
+       [_MI_SWAP] = "SwapCached",
+       [_MI_SHMEM] = "Shmem",
+};
+
+static inline int _get_idx(const char *name)
+{
+       int i;
+
+       for (i = 0; i < sizeof(_mi_str)/sizeof(_mi_str[0]); ++i) {
+               if (name && _mi_str[i] && !strcmp(name, _mi_str[i]))
+                       return i;
+       }
+
+       return -1;
+}
+
+static int _get_meminfo(struct meminfo *mi)
+{
+       FILE *fp;
+       char buf[4096];
+       char *s, *name, *num;
+       int idx;
+
+       assert(mi);
+
+       fp = fopen(PROC_MEMORY, "r");
+       if (!fp)
+               return -1;
+
+       memset(mi, 0, sizeof(*mi));
+
+       while (!feof(fp)) {
+               s = fgets(buf, sizeof(buf), fp);
+               if (!s)
+                       break;
+
+               s = strchr(buf, ':');
+               if (!s)
+                       continue;
+
+               *s = '\0';
+               name = buf;
+
+               s++;
+               while (*s == ' ')
+                       s++;
+               num = s;
+
+               idx = _get_idx(name);
+               if (idx < 0)
+                       continue;
+
+               mi->l[idx] = strtol(num, NULL, 10);
+       }
+
+       fclose(fp);
+       return 0;
+}
+
+int device_memory_get_total(unsigned int *total_mem)
+{
+       struct meminfo mi;
+       int ret;
+
+       if (total_mem == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_meminfo(&mi);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *total_mem = mi.l[_MI_TOTAL];
+       return DEVICE_ERROR_NONE;
+}
+
+int device_memory_get_available(unsigned int *avail_mem)
+{
+       struct meminfo mi;
+       int ret;
+
+       if (avail_mem == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_meminfo(&mi);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *avail_mem = mi.l[_MI_FREE] + mi.l[_MI_BUF] + mi.l[_MI_CACHED] + mi.l[_MI_SWAP] - mi.l[_MI_SHMEM];
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/wearable/battery.c b/src/wearable/battery.c
new file mode 100644 (file)
index 0000000..dffc0a7
--- /dev/null
@@ -0,0 +1,411 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <dd-battery.h>
+#include <vconf.h>
+#include "device.h"
+#include "device_log.h"
+
+#define CHECK_ERR(val) \
+       do {    \
+               if (val < 0) {          \
+                       if (errno == ENODEV)    \
+                               return DEVICE_ERROR_NOT_SUPPORTED;      \
+                       return DEVICE_ERROR_OPERATION_FAILED;   \
+               }       \
+       } while(0)
+
+int device_battery_get_percent(int* percent)
+{
+       if (percent == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int pct = battery_get_percent();
+       CHECK_ERR(pct);
+
+       *percent = pct;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_detail(int* percent)
+{
+       if (percent == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int pct = battery_get_percent_raw();
+       CHECK_ERR(pct);
+
+       *percent = pct;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_is_full(bool* full)
+{
+       if (full == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int f = battery_is_full();
+       CHECK_ERR(f);
+
+       *full = (f == 1) ? true : false;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_is_charging(bool *charging)
+{
+       // VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW
+       int value, err;
+
+       if (charging == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == 1) {
+               *charging = true;
+       } else if (value == 0) {
+               *charging = false;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_cb changed_callback = NULL;
+static void* changed_callback_user_data = NULL;
+
+static void battery_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) {
+               int percent = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) {
+                       changed_callback(percent, changed_callback_user_data);
+               }
+       }
+}
+
+int device_battery_set_cb(device_battery_cb callback, void* user_data)
+{
+       // VCONFKEY_SYSMAN_BATTERY_CAPACITY
+       int err;
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       changed_callback = callback;
+       changed_callback_user_data = user_data;
+
+       err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL);
+       if (err < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_unset_cb(void)
+{
+       int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       changed_callback = NULL;
+       changed_callback_user_data = NULL;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_warning_status(device_battery_warn_e *status)
+{
+       if (status == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       int value, err;
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) {
+               *status = DEVICE_BATTERY_WARN_EMPTY;
+       } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
+               *status = DEVICE_BATTERY_WARN_CRITICAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
+               *status = DEVICE_BATTERY_WARN_LOW;
+       } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) {
+               *status = DEVICE_BATTERY_WARN_NORMAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_FULL) {
+               *status = DEVICE_BATTERY_WARN_FULL;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_warn_cb warn_changed_callback = NULL;
+static void* warn_changed_callback_user_data = NULL;
+static device_battery_level_cb level_changed_callback = NULL;
+static void* level_changed_callback_user_data = NULL;
+
+static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) {
+               int bat_state = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) {
+                       warn_changed_callback(bat_state-1, warn_changed_callback_user_data);
+               }
+       }
+}
+
+static void battery_level_changed_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname;
+       keyname = vconf_keynode_get_name(key);
+
+       if (keyname != NULL && level_changed_callback != NULL &&
+           strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS) == 0) {
+               int bat_state = 0;
+               if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &bat_state) == 0) {
+                       level_changed_callback(bat_state, level_changed_callback_user_data);
+               }
+       }
+}
+
+int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data)
+{
+       // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW
+       int err;
+
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       warn_changed_callback = callback;
+       warn_changed_callback_user_data = user_data;
+
+       err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL);
+       if (err < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_warning_unset_cb(void)
+{
+       int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       warn_changed_callback = NULL;
+       warn_changed_callback_user_data = NULL;
+
+       return DEVICE_ERROR_NONE;
+}
+
+static device_battery_remaining_time_changed_cb timetofull_changed_cb = NULL;
+static device_battery_remaining_time_changed_cb timetoempty_changed_cb = NULL;
+static void* timetofull_cb_user_data = NULL;
+static void* timetoempty_cb_user_data = NULL;
+
+static void device_battery_time_timetofull_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+       int time = -1, err= -1;
+
+       if (keyname == NULL)
+               return;
+
+       if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOFULL) == 0) {
+               if (timetofull_changed_cb != NULL) {
+                       err = device_battery_get_remaining_time(
+                               DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &time);
+                       if ((err == DEVICE_ERROR_NONE) && (time >= 0))
+                               timetofull_changed_cb(time, timetofull_cb_user_data);
+               }
+       }
+}
+
+static void device_battery_time_timetoempty_inside_cb(keynode_t* key, void* user_data)
+{
+       char* keyname = vconf_keynode_get_name(key);
+       int time = -1, err= -1;
+
+       if (keyname == NULL)
+               return;
+
+       if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOEMPTY) == 0) {
+               if (timetoempty_changed_cb != NULL) {
+                       err = device_battery_get_remaining_time(
+                               DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED, &time);
+                       if ((err == DEVICE_ERROR_NONE) && (time >= 0))
+                               timetoempty_changed_cb(time, timetoempty_cb_user_data);
+               }
+       }
+}
+
+int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time)
+{
+       bool charging = false;
+       int err = -1;
+
+       err = device_battery_is_charging(&charging);
+       if (err != DEVICE_ERROR_NONE)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       if (charging == false) {
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       } else {
+                               err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, time);
+                               if (err < 0 || *time < 0) {
+                                       return DEVICE_ERROR_OPERATION_FAILED;
+                               }
+                       }
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       if (charging == true) {
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       } else {
+                               err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, time);
+                               if (err < 0 || *time < 0) {
+                                       return DEVICE_ERROR_OPERATION_FAILED;
+                               }
+                       }
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_set_remaining_time_changed_cb(device_battery_remaining_time_type_e type,
+       device_battery_remaining_time_changed_cb callback, void* user_data)
+{
+       int err;
+
+       if (callback == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       timetofull_changed_cb = callback;
+                       timetofull_cb_user_data = user_data;
+                       err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
+                               device_battery_time_timetofull_inside_cb, NULL);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       timetoempty_changed_cb = callback;
+                       timetoempty_cb_user_data = user_data;
+                       err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
+                               device_battery_time_timetoempty_inside_cb, NULL);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type)
+{
+       int err;
+
+       switch(type) {
+               case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
+                       err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
+                               device_battery_time_timetofull_inside_cb);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       timetofull_changed_cb = NULL;
+                       timetofull_cb_user_data = NULL;
+                       break;
+               case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
+                       err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
+                               device_battery_time_timetoempty_inside_cb);
+                       if (err < 0)
+                               return DEVICE_ERROR_OPERATION_FAILED;
+                       timetoempty_changed_cb = NULL;
+                       timetoempty_cb_user_data = NULL;
+                       break;
+               default:
+                       return DEVICE_ERROR_INVALID_PARAMETER;
+       }
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_level_status(device_battery_level_e *status)
+{
+       int value, err;
+
+       if (status == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+
+       err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &value);
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       if (value == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) {
+               *status = DEVICE_BATTERY_LEVEL_EMPTY;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) {
+               *status = DEVICE_BATTERY_LEVEL_CRITICAL;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) {
+               *status = DEVICE_BATTERY_LEVEL_LOW;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) {
+               *status = DEVICE_BATTERY_LEVEL_HIGH;
+       } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) {
+               *status = DEVICE_BATTERY_LEVEL_FULL;
+       } else {
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data)
+{
+       int err;
+
+
+       if (callback == NULL) {
+               err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+                       battery_level_changed_inside_cb);
+       } else {
+
+               err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+                       battery_level_changed_inside_cb, NULL);
+       }
+       if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       level_changed_callback = callback;
+       level_changed_callback_user_data = user_data;
+
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/wearable/cpu.c b/src/wearable/cpu.c
new file mode 100644 (file)
index 0000000..d013992
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "device.h"
+#include "device_log.h"
+
+#define PROC_STAT              "/proc/stat"
+
+#define PROC_CPU_PRESENT                               "/sys/devices/system/cpu/present"
+#define PROC_SCALING_CUR_FREQ                  "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq"
+#define PROC_SCALING_MAX_FREQ                  "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq"
+
+
+int device_cpu_get_count(int *cpu_cnt)
+{
+       FILE *fp;
+       int ret;
+       int st, ed;
+
+       if (cpu_cnt == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       fp = fopen(PROC_CPU_PRESENT, "r");
+       if (!fp)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       ret = fscanf(fp, "%u-%u", &st, &ed);
+       fclose(fp);
+       if (ret != 2)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *cpu_cnt = ed+1;
+       return DEVICE_ERROR_NONE;
+}
+
+static int _get_systime(device_system_time_s *st)
+{
+       FILE *fp;
+       char buf[4096];
+       char *s;
+
+       assert(st);
+
+       fp = fopen(PROC_STAT, "r");
+       if (!fp)
+               return -1;
+
+       s = fgets(buf, sizeof(buf), fp);
+       fclose(fp);
+       if (!s)
+               return -1;
+
+       s = strchr(buf, ' ');
+       if (!s)
+               return -1;
+
+       s++;
+       st->user = strtol(s, &s, 10);
+       st->nice = strtol(s, &s, 10);
+       st->system = strtol(s, &s, 10);
+       st->idle = strtol(s, &s, 10);
+       st->iowait = strtol(s, &s, 10);
+       st->irq = strtol(s, &s, 10);
+       st->softirq = strtol(s, &s, 10);
+
+       return 0;
+}
+
+int device_cpu_get_system_time(device_system_time_s *time)
+{
+       int ret;
+       device_system_time_s st;
+
+       if (time == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_systime(&st);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       st.total = st.user+st.nice+st.system+st.idle+st.iowait+st.irq+st.softirq;
+       *time = st;
+       return DEVICE_ERROR_NONE;
+}
+
+static int _get_uint(const char *path, unsigned int *val)
+{
+       FILE *fp;
+       unsigned int num;
+       int ret;
+
+       assert(path);
+       assert(val);
+
+       fp = fopen(path, "r");
+       if (!fp)
+               return -1;
+
+       ret = fscanf(fp, "%u", &num);
+       fclose(fp);
+       if (ret != 1)
+               return -1;
+
+       *val = num;
+       return 0;
+}
+
+int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq)
+{
+       char path[FILENAME_MAX];
+       int ret;
+       int count;
+       unsigned int cur;
+
+       if (cur_freq == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_cpu_get_count(&count);
+       if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       snprintf(path, sizeof(path), PROC_SCALING_CUR_FREQ, cpu);
+       ret = _get_uint(path, &cur);
+       if (ret < 0)
+               cur = 0;
+
+       *cur_freq = cur;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_cpu_get_max_freq(int cpu, unsigned int *max_freq)
+{
+       char path[FILENAME_MAX];
+       int ret;
+       int count;
+       unsigned int max;
+
+       if (max_freq == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_cpu_get_count(&count);
+       if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       snprintf(path, sizeof(path), PROC_SCALING_MAX_FREQ, cpu);
+       ret = _get_uint(path, &max);
+       if (ret < 0)
+               max = 0;
+
+       *max_freq = max;
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/wearable/device.c b/src/wearable/device.c
new file mode 100644 (file)
index 0000000..a332d47
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. 
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <dd-display.h>
+#include <dd-led.h>
+#include "device.h"
+#include "device_log.h"
+
+#define CHECK_ERR(val) \
+       do {    \
+               if (val < 0) {          \
+                       if (errno == ENODEV)    \
+                               return DEVICE_ERROR_NOT_SUPPORTED;      \
+                       return DEVICE_ERROR_OPERATION_FAILED;   \
+               }       \
+       } while(0)
+
+int device_get_display_numbers(int* device_number)
+{
+       if(device_number == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       *device_number = display_get_count();
+       CHECK_ERR(*device_number);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_get_brightness(int disp_idx, int* value)
+{
+       int val, max_id, ret;
+
+       if(value == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = display_get_brightness();
+       CHECK_ERR(val);
+
+       *value = val;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness(int disp_idx, int new_value)
+{
+       int max_value, val, max_id, ret;
+
+       if(new_value < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_max_brightness(disp_idx, &max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(new_value > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = display_set_brightness(new_value);
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_get_max_brightness(int disp_idx, int* max_value)
+{
+       int val, max_id, ret;
+
+       if(max_value == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = display_get_max_brightness();
+       CHECK_ERR(val);
+
+       *max_value = val;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness_from_settings(int disp_idx)
+{
+       int max_id, val, ret;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = display_release_brightness();
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_set_brightness_to_settings(int disp_idx, int new_value)
+{
+       int max_value, val, max_id, ret;
+
+       if(new_value < 0)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_display_numbers(&max_id);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(disp_idx < 0 || disp_idx >= max_id)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = device_get_max_brightness(disp_idx, &max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if(new_value > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       val = display_set_brightness_with_setting(new_value);
+       CHECK_ERR(val);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_get_brightness(int *brightness)
+{
+       int value;
+
+       if (brightness == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = led_get_brightness();
+       CHECK_ERR(value);
+
+       *brightness = value;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_set_brightness(int brightness)
+{
+       int max_value, value, ret;
+
+       ret = device_flash_get_max_brightness(&max_value);
+       if (ret != DEVICE_ERROR_NONE)
+               return ret;
+
+       if (brightness < 0 || brightness > max_value)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = led_set_brightness(brightness);
+       CHECK_ERR(value);
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_flash_get_max_brightness(int *max_brightness)
+{
+       int value;
+
+       if (max_brightness == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       value = led_get_max_brightness();
+       CHECK_ERR(value);
+
+       *max_brightness = value;
+       return DEVICE_ERROR_NONE;
+}
diff --git a/src/wearable/memory.c b/src/wearable/memory.c
new file mode 100644 (file)
index 0000000..8e71a23
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "device.h"
+#include "device_log.h"
+
+#define PROC_MEMORY            "/proc/meminfo"
+
+enum {
+       _MI_TOTAL,
+       _MI_FREE,
+       _MI_BUF,
+       _MI_CACHED,
+       _MI_SWAP,
+       _MI_SHMEM,
+       _MI_MAX,
+};
+
+struct meminfo {
+       unsigned long l[_MI_MAX];
+};
+
+static const char *_mi_str[] = {
+       [_MI_TOTAL] = "MemTotal",
+       [_MI_FREE] = "MemFree",
+       [_MI_BUF] = "Buffers",
+       [_MI_CACHED] = "Cached",
+       [_MI_SWAP] = "SwapCached",
+       [_MI_SHMEM] = "Shmem",
+};
+
+static inline int _get_idx(const char *name)
+{
+       int i;
+
+       for (i = 0; i < sizeof(_mi_str)/sizeof(_mi_str[0]); ++i) {
+               if (name && _mi_str[i] && !strcmp(name, _mi_str[i]))
+                       return i;
+       }
+
+       return -1;
+}
+
+static int _get_meminfo(struct meminfo *mi)
+{
+       FILE *fp;
+       char buf[4096];
+       char *s, *name, *num;
+       int idx;
+
+       assert(mi);
+
+       fp = fopen(PROC_MEMORY, "r");
+       if (!fp)
+               return -1;
+
+       memset(mi, 0, sizeof(*mi));
+
+       while (!feof(fp)) {
+               s = fgets(buf, sizeof(buf), fp);
+               if (!s)
+                       break;
+
+               s = strchr(buf, ':');
+               if (!s)
+                       continue;
+
+               *s = '\0';
+               name = buf;
+
+               s++;
+               while (*s == ' ')
+                       s++;
+               num = s;
+
+               idx = _get_idx(name);
+               if (idx < 0)
+                       continue;
+
+               mi->l[idx] = strtol(num, NULL, 10);
+       }
+
+       fclose(fp);
+       return 0;
+}
+
+int device_memory_get_total(unsigned int *total_mem)
+{
+       struct meminfo mi;
+       int ret;
+
+       if (total_mem == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_meminfo(&mi);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *total_mem = mi.l[_MI_TOTAL];
+       return DEVICE_ERROR_NONE;
+}
+
+int device_memory_get_available(unsigned int *avail_mem)
+{
+       struct meminfo mi;
+       int ret;
+
+       if (avail_mem == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = _get_meminfo(&mi);
+       if (ret < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       *avail_mem = mi.l[_MI_FREE] + mi.l[_MI_BUF] + mi.l[_MI_CACHED] + mi.l[_MI_SWAP] - mi.l[_MI_SHMEM];
+       return DEVICE_ERROR_NONE;
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..30ac1c2
--- /dev/null
@@ -0,0 +1,53 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-system-device")
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 ${fw_name})
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+#ADD_EXECUTABLE("system-sensor" system-sensor.c)
+#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS})
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${src_name} ${src})
+    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+        DEPENDS clean 
+        COMMENT "distribution clean"
+        COMMAND find
+        ARGS    . 
+        -not -name config.cmake -and \(
+        -name tester.c -or
+        -name Testing -or
+        -name CMakeFiles -or
+        -name cmake.depends -or
+        -name cmake.check_depends -or
+        -name CMakeCache.txt -or
+        -name cmake.check_cache -or
+        -name *.cmake -or
+        -name Makefile -or
+        -name core -or
+        -name core.* -or
+        -name gmon.out -or
+        -name install_manifest.txt -or
+        -name *.pc -or
+        -name *~ \)
+        | grep -v TC | xargs rm -rf
+        TARGET  distclean
+        VERBATIM
+)
+
+ENDIF(UNIX)
diff --git a/test/battery.c b/test/battery.c
new file mode 100644 (file)
index 0000000..16408d2
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <stdbool.h>
+#include <device.h>
+
+static GMainLoop *mainloop;
+
+void battery_cb(int percent, void* ud)
+{
+    char* txt = (char*)ud;
+    printf("battery capacity [%d] -- %s\n", percent, txt); 
+}
+
+static void sig_quit(int signo)
+{
+       if(mainloop)
+       {
+               g_main_loop_quit(mainloop);
+       }
+}
+
+static void errp(device_error_e e){
+    switch(e){
+        case DEVICE_ERROR_INVALID_PARAMETER:
+            printf("invalid parameter!\n");
+            break;
+        case DEVICE_ERROR_OPERATION_FAILED:
+            printf("operation failed!\n");
+            break;
+        case DEVICE_ERROR_NONE:
+            printf("success!\n");
+            break;
+        default:
+            printf("unknown!\n");
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    int err;
+
+       signal(SIGINT, sig_quit);
+       signal(SIGTERM, sig_quit);
+       signal(SIGQUIT, sig_quit);
+
+       mainloop = g_main_loop_new(NULL, FALSE);
+
+    bool charging;
+    if( (err = device_battery_is_charging(&charging)) < 0){
+        printf("is charging return ");
+        errp(err);
+    }
+    printf("charging state -> %s\n", charging?"charging...":"not charging");
+
+    if( (err=device_battery_set_cb(battery_cb, "PIUS!!")) < 0){
+        printf("set cb return ");
+        errp(err);
+    }
+
+       g_main_loop_run(mainloop);
+       g_main_loop_unref(mainloop);
+
+    if( (err=device_battery_unset_cb()) < 0){
+        printf("unset cb return ");
+        errp(err);
+    }
+
+       return 0;
+}
diff --git a/test/system-device.c b/test/system-device.c
new file mode 100644 (file)
index 0000000..466150b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <device.h>
+
+int main(int argc, char *argv[])
+{
+       int pct;
+       bool is_full;
+       int brt, max, cnt;
+
+       if(device_battery_get_percent(&pct) == DEVICE_ERROR_NONE){
+               printf("battery percent is %d %%\n", pct);
+       }else{
+               printf("device_battery_get_percent error\n");
+       }
+
+       if(device_battery_is_full(&is_full) == DEVICE_ERROR_NONE){
+               printf("battery is %s\n", is_full ? "full" : "not full");
+       }else{
+               printf("device_battery_is_full error\n");
+       }
+
+       if(device_get_max_brightness(0, &max) == DEVICE_ERROR_NONE){
+               printf("display brightness max is %d\n", max);
+       }else{
+               printf("device_get_max_brightness error\n");
+       }
+
+    cnt = device_get_display_count();
+    printf("display count is %d\n", cnt);
+
+       if(argc > 1){
+               brt = atoi(argv[1]);
+       }else{
+               brt = max / 2;
+       }
+       if(device_set_brightness(0, brt) == DEVICE_ERROR_NONE){
+               printf("set brightness %d\n", brt);
+       }else{
+               printf("device_set_brightness error\n");
+       }
+
+       if(device_get_brightness(0, &brt) == DEVICE_ERROR_NONE){
+               printf("display brightness is %d\n", brt);
+       }else{
+               printf("device_get_brightness error\n");
+       }
+
+       return 0;
+}