From a6a99f87ce3c97b6795585bae8da2da0d0ff9e22 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 23 Dec 2020 13:19:02 +0900 Subject: [PATCH] Initialization Change-Id: I4fd619dc30d03d761f1fbc5a71ccb97316f1da77 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 103 +++++++++ LICENSE.Apache-2.0 | 204 ++++++++++++++++++ hal-api-device.pc.in | 14 ++ include/common.h | 88 ++++++++ include/device-error.h | 62 ++++++ include/hal-battery-internal.h | 91 ++++++++ include/hal-battery.h | 221 +++++++++++++++++++ include/hal-device.h | 252 ++++++++++++++++++++++ include/hal-display-enum.h | 33 +++ include/hal-display-internal.h | 126 +++++++++++ include/hal-display.h | 193 +++++++++++++++++ include/hal-haptic.h | 163 ++++++++++++++ include/hal-ir.h | 83 +++++++ include/hal-led-internal.h | 72 +++++++ include/hal-led.h | 151 +++++++++++++ include/hal-temperature.h | 74 +++++++ include/hal-touchscreen-internal.h | 10 + include/list.h | 83 +++++++ packaging/hal-api-device.manifest | 5 + packaging/hal-api-device.spec | 58 +++++ src/battery.c | 428 +++++++++++++++++++++++++++++++++++++ src/common.c | 292 +++++++++++++++++++++++++ src/device.c | 68 ++++++ src/display.c | 426 ++++++++++++++++++++++++++++++++++++ src/haptic.c | 343 +++++++++++++++++++++++++++++ src/ir.c | 111 ++++++++++ src/led.c | 215 +++++++++++++++++++ src/memory.c | 138 ++++++++++++ src/temperature.c | 81 +++++++ src/touchscreen-internal.c | 45 ++++ 30 files changed, 4233 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE.Apache-2.0 create mode 100644 hal-api-device.pc.in create mode 100644 include/common.h create mode 100644 include/device-error.h create mode 100644 include/hal-battery-internal.h create mode 100644 include/hal-battery.h create mode 100644 include/hal-device.h create mode 100644 include/hal-display-enum.h create mode 100644 include/hal-display-internal.h create mode 100644 include/hal-display.h create mode 100644 include/hal-haptic.h create mode 100644 include/hal-ir.h create mode 100644 include/hal-led-internal.h create mode 100644 include/hal-led.h create mode 100644 include/hal-temperature.h create mode 100644 include/hal-touchscreen-internal.h create mode 100644 include/list.h create mode 100644 packaging/hal-api-device.manifest create mode 100644 packaging/hal-api-device.spec create mode 100644 src/battery.c create mode 100644 src/common.c create mode 100644 src/device.c create mode 100644 src/display.c create mode 100644 src/haptic.c create mode 100644 src/ir.c create mode 100644 src/led.c create mode 100644 src/memory.c create mode 100644 src/temperature.c create mode 100644 src/touchscreen-internal.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..af3a967 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,103 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "hal-api-device") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(PKG_MODULES + dlog + vconf + capi-base-common + capi-system-device + capi-system-info + gio-2.0 + tracker + libsyscommon +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${PKG_MODULES}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFEATURE_DEVICE_DLOG") +ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}/hal\"") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}/hal") + +aux_source_directory(src 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_DIR}/hal) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/hal + FILES_MATCHING + PATTERN "${INC_DIR}/hal-*.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_INSTALL_DIR}/pkgconfig) + +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.Apache-2.0 b/LICENSE.Apache-2.0 new file mode 100644 index 0000000..a06208b --- /dev/null +++ b/LICENSE.Apache-2.0 @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/hal-api-device.pc.in b/hal-api-device.pc.in new file mode 100644 index 0000000..30f2af2 --- /dev/null +++ b/hal-api-device.pc.in @@ -0,0 +1,14 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=@LIB_INSTALL_DIR@ +includedir=/usr/include + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: capi-base-common +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} -I/usr/include/system diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..273ed79 --- /dev/null +++ b/include/common.h @@ -0,0 +1,88 @@ +/* + * 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 __COMMON_H__ +#define __COMMON_H__ + +#ifdef FEATURE_DEVICE_DLOG + #define LOG_TAG "SYSTEM_DEVICE" + #include + #define _D(fmt, args...) SLOGD(fmt, ##args) + #define _I(fmt, args...) SLOGI(fmt, ##args) + #define _W(fmt, args...) SLOGW(fmt, ##args) + #define _E(fmt, args...) SLOGE(fmt, ##args) +#else + #define _D(x, ...) + #define _I(x, ...) + #define _W(x, ...) + #define _E(x, ...) +#endif + +#ifndef __CONSTRUCTOR__ +#define __CONSTRUCTOR__ __attribute__ ((constructor)) +#endif + +#include "device-error.h" + +static inline int errno_to_device_error(int err) +{ + switch (err) { + case 0: + return DEVICE_ERROR_NONE; + case -EACCES: + case -EPERM: + return DEVICE_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE System Error + case -EBUSY: + return DEVICE_ERROR_RESOURCE_BUSY; + case -ENOTSUP: + case -ENODEV: + case -ENOENT: + return DEVICE_ERROR_NOT_SUPPORTED; + default: + return DEVICE_ERROR_OPERATION_FAILED; + } +} + +struct parse_result { + char *section; + char *name; + char *value; +}; + +int config_parse(const char *file_name, + int cb(struct parse_result *result, void *data), + void *user_data); + +typedef enum { + TIZEN_PROFILE_UNKNOWN = 0, + TIZEN_PROFILE_MOBILE = 0x1, + TIZEN_PROFILE_WEARABLE = 0x2, + TIZEN_PROFILE_TV = 0x4, + TIZEN_PROFILE_IVI = 0x8, + TIZEN_PROFILE_COMMON = 0x10, +} tizen_profile_t; +extern tizen_profile_t _get_tizen_profile(); + +#define CHECK_RATE_THRESHOLD 100 +#define CHECK_RATE_PERIOD_LEN 5 +int check_async_call_rate(long *num_calls); + +#define TIZEN_FEATURE_TRACKER (_get_tizen_profile() == TIZEN_PROFILE_TV) + +bool is_emulator(void); +int is_display_state_supported(void); +int is_display_supported(void); +#endif /* __COMMON_H__ */ diff --git a/include/device-error.h b/include/device-error.h new file mode 100644 index 0000000..9b70367 --- /dev/null +++ b/include/device-error.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014 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_ERROR_H__ +#define __TIZEN_SYSTEM_DEVICE_ERROR_H__ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_MODULE + * @{ + */ + + +/** + * @brief Enumeration for device's error code. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum { + DEVICE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + DEVICE_ERROR_OPERATION_FAILED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted */ + DEVICE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + DEVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + DEVICE_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */ + DEVICE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported in this device */ + DEVICE_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + DEVICE_ERROR_NOT_INITIALIZED = TIZEN_ERROR_DEVICE | 0x13, /**< Not initialized */ +} device_error_e; + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_DEVICE_ERROR_H__ diff --git a/include/hal-battery-internal.h b/include/hal-battery-internal.h new file mode 100644 index 0000000..19b8768 --- /dev/null +++ b/include/hal-battery-internal.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020 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_BATTERY_INTERNAL_H__ +#define __TIZEN_SYSTEM_BATTERY_INTERNAL_H__ + + +#include +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE + * @{ + */ +#define BATTERY_INFO_MAX 32 + +struct device_battery_info { + char status[BATTERY_INFO_MAX]; + char health[BATTERY_INFO_MAX]; + char power_source[BATTERY_INFO_MAX]; + int online; + int present; + int capacity; + int current_now; + int current_average; + int voltage_now; + int voltage_average; + int temperature; +}; + +/** + * @brief Gets the battery status.. + * @since_tizen 6.0 + * @param[out] info battery status information.\n + * The current_average is INT_MAX if battery hw does not provide current average.\n + * The voltage_average is INT_MAX if battery hw does not provide voltage average. + * @return @c 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 + */ +int device_battery_get_info(struct device_battery_info *info); + +/** + * @brief Gets the battery status.. + * @since_tizen 6.0 + * @param[out] info battery status information.\n + * The current_average is INT_MAX if battery hw does not provide current average.\n + * The voltage_average is INT_MAX if battery hw does not provide voltage average. + * @return @c 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 + */ +int device_battery_get_info_direct(struct device_battery_info *info); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_BATTERY_H__ diff --git a/include/hal-battery.h b/include/hal-battery.h new file mode 100644 index 0000000..f28f8ee --- /dev/null +++ b/include/hal-battery.h @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2014 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_BATTERY_H__ +#define __TIZEN_SYSTEM_BATTERY_H__ + + +#include +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE + * @{ + */ + + +/** + * @brief Enumeration for the battery level status. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +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 fully charged. It means no more charge. */ +} device_battery_level_e; + + +/** + * @brief Enumeration for battery health information. + * @since_tizen 3.0 + */ +typedef enum { + DEVICE_BATTERY_HEALTH_GOOD, /**< The battery health is good */ + DEVICE_BATTERY_HEALTH_COLD, /**< The temperature of the battery is cold */ + DEVICE_BATTERY_HEALTH_DEAD, /**< The battery is dead */ + DEVICE_BATTERY_HEALTH_OVER_HEAT, /**< The temperature of the battery is high */ + DEVICE_BATTERY_HEALTH_OVER_VOLTAGE, /**< The battery is in over voltage state */ +} device_battery_health_e; + + +/** + * @brief Enumeration for power source information. + * @since_tizen 3.0 + */ +typedef enum { + DEVICE_BATTERY_POWER_SOURCE_NONE, /**< There is no power source */ + DEVICE_BATTERY_POWER_SOURCE_AC, /**< AC power cable is connected */ + DEVICE_BATTERY_POWER_SOURCE_USB, /**< USB power cable is connected */ + DEVICE_BATTERY_POWER_SOURCE_WIRELESS, /**< Power is provided by a wireless source */ +} device_battery_power_source_e; + + +/** + * @brief Enumeration for battery property information. + * @since_tizen 3.0 + */ +typedef enum { + DEVICE_BATTERY_PROPERTY_CAPACITY, /**< The battery capacity (0 ~ 100 %) */ + DEVICE_BATTERY_PROPERTY_CURRENT_NOW, /**< The battery current (uA) */ + DEVICE_BATTERY_PROPERTY_CURRENT_AVERAGE, /**< The average battery current (uA) */ + DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW, /**< The battery voltage (uV) (Since 5.0) */ + DEVICE_BATTERY_PROPERTY_VOLTAGE_AVERAGE, /**< The average battery voltage (uV) (Since 5.0) */ + DEVICE_BATTERY_PROPERTY_TEMPERATURE, /**< The battery temperature (`C) (Since 5.0) */ +} device_battery_property_e; + + +/** + * @brief Enumeration for battery status information. + * @since_tizen 3.0 + */ +typedef enum { + DEVICE_BATTERY_STATUS_CHARGING, /**< Battery is charging */ + DEVICE_BATTERY_STATUS_DISCHARGING, /**< Battery is discharging */ + DEVICE_BATTERY_STATUS_FULL, /**< Battery is fully charged */ + DEVICE_BATTERY_STATUS_NOT_CHARGING, /**< Battery is not charging */ +} device_battery_status_e; + + +/** + * @brief Gets the battery charge percentage. + * @details It returns an integer value from @c 0 to @c 100 that indicates remaining battery charge + * as a percentage of the maximum level. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @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 (@c 0 ~ @c 100) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_battery_get_percent(int *percent); + + +/** + * @brief Gets the charging state. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[out] charging The battery charging state + * @return @c 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_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_BATTERY_CHARGING + */ +int device_battery_is_charging(bool *charging); + + +/** + * @brief Gets the battery level status. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[out] status The battery level status + * @return @c 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_level_e + * @see device_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_BATTERY_LEVEL + */ +int device_battery_get_level_status(device_battery_level_e *status); + + +/** + * @brief Gets the battery health information. + * @since_tizen 3.0 + * @param[out] health The battery health information + * @return @c 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 + */ +int device_battery_get_health(device_battery_health_e *health); + + +/** + * @brief Gets the battery power source information. + * @since_tizen 3.0 + * @param[out] source The battery power source information + * @return @c 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 + */ +int device_battery_get_power_source(device_battery_power_source_e *source); + + +/** + * @brief Gets the battery properties. + * @since_tizen 3.0 + * @param[in] property The property type + * @param[out] value The battery information for the property given + * @return @c 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 + */ +int device_battery_get_property(device_battery_property_e property, int *value); + + +/** + * @brief Gets the battery status information. + * @since_tizen 3.0 + * @param[out] status The battery status information + * @return @c 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 + */ +int device_battery_get_status(device_battery_status_e *status); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_BATTERY_H__ diff --git a/include/hal-device.h b/include/hal-device.h new file mode 100644 index 0000000..38d5326 --- /dev/null +++ b/include/hal-device.h @@ -0,0 +1,252 @@ +/* + * 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 +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_MODULE + * @{ + */ + +/** + * @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 registered 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. + * + * @remarks This API is related to the following feature: %http://tizen.org/feature/camera.back.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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_brightness(int *brightness); + +/** + * @brief Set brightness value of LED that placed to camera flash. + * + * @remarks This API is related to the following feature: %http://tizen.org/feature/camera.back.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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_set_brightness(int brightness); + +/** + * @brief Get max brightness value of LED that placed to camera flash. + * + * @remarks + * Brightness control does not support yet. so this function always return 1. \n + * Set function can only use to switch on/off the flash. \n + * Get function can only use to retrieve on/off state of flash. + * This API is related to the following feature: %http://tizen.org/feature/camera.back.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 + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_max_brightness(int *max_brightness); + +/** + * @brief Get total amount of physical RAM, in kilobytes + * + * @remarks + * + * @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 + * + * @remarks + * 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); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_DEVICE_H__ diff --git a/include/hal-display-enum.h b/include/hal-display-enum.h new file mode 100644 index 0000000..9434bde --- /dev/null +++ b/include/hal-display-enum.h @@ -0,0 +1,33 @@ +#ifndef __TIZEN_SYSTEM_DISPLAY_ENUM_H__ +#define __TIZEN_SYSTEM_DISPLAY_ENUM_H__ + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @addtogroup CAPI_SYSTEM_DEVICE_DISPLAY_MODULE + * @{ + */ +/** + * @brief Enumeration for the available display states. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @remarks #DISPLAY_STATE_SCREEN_DIM may be ignored if the DIM state is disabled on the platform. + */ + +typedef enum +{ + DISPLAY_STATE_NORMAL, /**< Normal state */ + DISPLAY_STATE_SCREEN_DIM, /**< Screen dim state */ + DISPLAY_STATE_SCREEN_OFF, /**< Screen off state */ +} display_state_e; + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_DISPLAY_ENUM_H__ diff --git a/include/hal-display-internal.h b/include/hal-display-internal.h new file mode 100644 index 0000000..e9bf055 --- /dev/null +++ b/include/hal-display-internal.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018 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_DISPLAY_INTERNAL_H__ +#define __TIZEN_SYSTEM_DISPLAY_INTERNAL_H__ + + +#include +#include + +#include "device-error.h" +#include "hal-display-enum.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Gets the display brightness value. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display + * @param[out] brightness The current brightness value of the display + * @param[in] state The enum value of the display state \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @see device_display_get_numbers() + * @see device_display_set_brightness_state() + * @see device_display_get_max_brightness_state() + */ +int device_display_get_brightness_state(int display_index, display_state_e state, int *brightness); + + +/** + * @brief Gets the maximum brightness value that can be set. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display + * @param[out] max_brightness The maximum brightness value of the display + * @param[in] state The enum value of the display state \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @see device_display_get_numbers() + * @see device_display_get_brightness_state() + * @see device_display_set_brightness_state() + */ +int device_display_get_max_brightness_state(int display_index, display_state_e state, int *brightness); + + +/** + * @brief Sets the display brightness value. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_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_display_get_max_brightness_state() + * @param[in] state The enum value of the display state \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @see device_display_get_numbers() + * @see device_display_get_max_brightness() + * @see device_display_set_brightness_state() + */ +int device_display_set_brightness_state(int display_index, display_state_e state, int brightness); + +/** + * @brief Change display state by a specific reason + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @param[in] type The type is display state to change\n + * DISPLAY_STATE_NORMAL : change to normal\n + * DISPLAY_STATE_SCREEN_OFF: change to off\n + * @param[in] reason Reason that causes display chage state\n + * @param[in] timeout Timeout to change state\n + * @param[in] cb Callback function for handling result of dbus method call\n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @see device_display_change_state_by_reason() + */ +int device_display_change_state_by_reason(display_state_e type, const char *reason, int timeout, dbus_pending_cb cb); +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_DISPLAY_INTERNAL_H__ diff --git a/include/hal-display.h b/include/hal-display.h new file mode 100644 index 0000000..8f05d42 --- /dev/null +++ b/include/hal-display.h @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2014 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_DISPLAY_H__ +#define __TIZEN_SYSTEM_DISPLAY_H__ + + +#include "device-error.h" +#include "hal-display-enum.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_DISPLAY_MODULE + * @{ + */ + + +/** + * @brief Gets the number of display devices. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display + * @param[out] device_number The total number of displays + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_display_get_brightness() + * @see device_display_set_brightness() + * @see device_display_get_max_brightness() + */ +int device_display_get_numbers(int *device_number); + + +/** + * @brief Gets the maximum brightness value that can be set. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display + * @param[out] max_brightness The maximum brightness value of the display + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_display_get_numbers() + * @see device_display_set_brightness() + * @see device_display_get_brightness() + */ +int device_display_get_max_brightness(int display_index, int *max_brightness); + + +/** + * @brief Gets the display brightness value. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display + * @param[out] brightness The current brightness value of the display + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_display_get_numbers() + * @see device_display_set_brightness() + * @see device_display_get_max_brightness() + */ +int device_display_get_brightness(int display_index, int *brightness); + + +/** + * @brief Sets the display brightness value. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_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_display_get_max_brightness() + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_display_get_numbers() + * @see device_display_get_max_brightness() + * @see device_display_get_brightness() + */ +int device_display_set_brightness(int display_index, int brightness); + + +/** + * @brief Gets the current display state. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display + * @param[out] state The display state + * @return @c 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_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_DISPLAY_STATE + */ +int device_display_get_state(display_state_e *state); + + +/** + * @brief Changes the display state by force. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks This API triggers display change process and then updates the status when it completes. While the operation is on-going, the device_display_get_state() function returns previous display state. + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display.state. + * @param[in] state The display state + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_power_request_lock() + * @see device_power_release_lock() + * @see device_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_DISPLAY_STATE + * + * @par Example + * @code + * ... + * result = device_display_change_state(DISPLAY_STATE_SCREEN_OFF); + * if (result < 0) + * dlog_print(DLOG_ERROR, LOG_TAG, "[ERROR] return value result =%d, \n",result); + * else + * dlog_print(DLOG_DEBUG, LOG_TAG, "[SUCCESS] return value result =%d \n",result); + * ... + * @endcode + */ +int device_display_change_state(display_state_e state); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_DISPLAY_H__ diff --git a/include/hal-haptic.h b/include/hal-haptic.h new file mode 100644 index 0000000..08800fb --- /dev/null +++ b/include/hal-haptic.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2014 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_HAPTIC_H__ +#define __TIZEN_SYSTEM_HAPTIC_H__ + + +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE + * @{ + */ + + +/** + * @brief The haptic device handle. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef void* haptic_device_h; + + +/** + * @brief The haptic effect handle. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef void* haptic_effect_h; + + +/** + * @brief Gets the number of vibrators. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * @param[in] device_number The number of vibrators + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_haptic_get_count(int *device_number); + + +/** + * @brief Opens a haptic-vibration device. + * @details Internally, it makes a connection to the vibrator. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * @remarks You must close the Haptic API using device_haptic_close(). + * @param[in] device_index The index of device what you want to vibrate \n + * The index starts from @c 0 + * @param[out] device_handle The handle of vibrator + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_haptic_close() + */ +int device_haptic_open(int device_index, haptic_device_h *device_handle); + + +/** + * @brief Closes a haptic-vibration device. + * @details Internally, it disconnects the connection to the vibrator. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * @param[in] device_handle The device handle from device_haptic_open() + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_haptic_open() + */ +int device_haptic_close(haptic_device_h device_handle); + + +/** + * @brief Vibrates during the specified time with a constant intensity. + * @details This function can be used to start monotonous vibration for the specified time. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * @remarks @a feedback level is reserved for auto changing to save variable in the settings. + * @remarks @a effect_handle effect_handle value can be @c 0(zero). + * @remarks To prevent unexpected sleep (suspend) during vibration, please use @ref CAPI_SYSTEM_DEVICE_POWER_MODULE. + * @param[in] device_handle The device handle from device_haptic_open() + * @param[in] duration The play duration in milliseconds + * @param[in] feedback The amount of the intensity variation (@c 0 ~ @c 100) + * @param[out] effect_handle The pointer to the variable that will receive a handle to the playing effect + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_haptic_stop() + */ +int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle); + + +/** + * @brief Stops all vibration effects which are being played. + * @details This function can be used to stop all effects started by device_haptic_vibrate(). + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * @param[in] device_handle The device handle from device_haptic_open() + * @param[in] effect_handle The effect handle from device_haptic_vibrate() + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @see device_haptic_vibrate() + */ +int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_HAPTIC_H__ diff --git a/include/hal-ir.h b/include/hal-ir.h new file mode 100644 index 0000000..957831a --- /dev/null +++ b/include/hal-ir.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016 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_IR_H__ +#define __TIZEN_SYSTEM_IR_H__ + + +#include +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_IR_MODULE + * @{ + */ + + +/** + * @brief Gets the information whether IR module is available. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/use_ir + * @param[out] available The information whether IR is available + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_ir_is_available(bool *available); + + +/** + * @brief Transmits IR command. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/use_ir + * @param[in] carrier_frequency Carrier frequency to transmit IR command (Hertz) + * @param[in] pattern Integer array of IR command + * @param[in] size Size of IR command pattern + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_ir_transmit(int carrier_frequency, int *pattern, int size); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif /* __TIZEN_SYSTEM_IR_H__ */ diff --git a/include/hal-led-internal.h b/include/hal-led-internal.h new file mode 100644 index 0000000..7a13455 --- /dev/null +++ b/include/hal-led-internal.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 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_LED_INTERNAL_H__ +#define __TIZEN_SYSTEM_LED_INTERNAL_H__ + + +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief Gets the total number of LEDs in the device. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @param[out] Number of LEDs + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_multi_led_get_number(int *num_of_leds); + +/** + * @brief Plays multiple LEDs at the same time. + * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @remarks The array size must be the same as the number of LEDs, which is obtained by device_multi_led_get_number(). + * @param[in] color[] The Color value for each LED\n + * The first byte means opaque, and the other 3 bytes mean RGB values + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_multi_led_control(unsigned int color[]); + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_LED_INTERNAL_H__ diff --git a/include/hal-led.h b/include/hal-led.h new file mode 100644 index 0000000..2463f2d --- /dev/null +++ b/include/hal-led.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014 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_LED_H__ +#define __TIZEN_SYSTEM_LED_H__ + + +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_LED_MODULE + * @{ + */ + + +/** + * @brief Gets the max brightness value of a LED that is located next to the camera. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/camera.back.flash + * @param[out] max_brightness The max brightness value of the LED + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_max_brightness(int *max_brightness); + + +/** + * @brief Gets the brightness value of a LED that is located next to the camera. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/camera.back.flash + * @param[out] brightness The brightness value of LED (@c 0 ~ MAX) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_brightness(int *brightness); + + +/** + * @brief Sets the brightness value of a LED that is located next to the camera. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks Since @if Mobile 2.4 @elseif WEARABLE 3.0 @endif, this API check camera flash status whether camera API preempted flash or not, so it could be failed if flash was preempted by camera API. In this case, API will return #DEVICE_ERROR_RESOURCE_BUSY error. + * This API is related to the following feature: %http://tizen.org/feature/camera.back.flash + * @param[in] brightness The brightness value of LED (@c 0 ~ MAX) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @retval #DEVICE_ERROR_RESOURCE_BUSY Device or resource busy + */ +int device_flash_set_brightness(int brightness); + + +/** + * @brief Enumeration for custom LED flags. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum { + LED_CUSTOM_DUTY_ON = 1 << 0, /**< blink LED */ + LED_CUSTOM_DEFAULT = (LED_CUSTOM_DUTY_ON), /**< Default flag */ +} led_custom_flags; + + +/** + * @brief Plays the custom effect of the service LED that is located to the front of a device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @param[in] on Turn on time in milliseconds + * @param[in] off Turn off time in milliseconds + * @param[in] color The Color value \n + * The first byte means opaque and the other 3 bytes are RGB values + * @param[in] flags The combination of enum #led_custom_flags + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags); + + +/** + * @brief Stops the custom effect of the service LED that is located to the front of a device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * @remarks This API is related to the following feature: %http://tizen.org/feature/led + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_led_stop_custom(void); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif // __TIZEN_SYSTEM_LED_H__ diff --git a/include/hal-temperature.h b/include/hal-temperature.h new file mode 100644 index 0000000..91fea6d --- /dev/null +++ b/include/hal-temperature.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 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_TEMPERATURE_H__ +#define __TIZEN_SYSTEM_TEMPERATURE_H__ + + +#include +#include "device-error.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_THERMAL_MODULE + * @{ + */ + + +/** + * @brief Enumeration for the device temperature. + * @since_tizen 5.5 + */ +typedef enum +{ + DEVICE_THERMAL_AP, /**< Temperature for Application Processor */ + DEVICE_THERMAL_CP, /**< Temperature for Communication Processor */ + DEVICE_THERMAL_BATTERY, /**< Temperature for Battery */ +} device_thermal_e; + + +/** + * @brief Gets the temperature value. + * @since_tizen 5.5 + * @param[in] type The index of the device + * @param[out] temp The temperature value in degrees Celsius + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_thermal_get_temperature(device_thermal_e type, int *temp); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif /* __TIZEN_SYSTEM_TEMPERATURE_H__ */ diff --git a/include/hal-touchscreen-internal.h b/include/hal-touchscreen-internal.h new file mode 100644 index 0000000..900b41d --- /dev/null +++ b/include/hal-touchscreen-internal.h @@ -0,0 +1,10 @@ +#ifndef __TIZEN_SYSTEM_TOUCHSCREEN_INTERNAL_H__ +#define __TIZEN_SYSTEM_TOUCHSCREEN_INTERNAL_H__ + +#include +#include + +int device_touchscreen_enable(dbus_pending_cb cb); +int device_touchscreen_disable(dbus_pending_cb cb); + +#endif diff --git a/include/list.h b/include/list.h new file mode 100644 index 0000000..712ca70 --- /dev/null +++ b/include/list.h @@ -0,0 +1,83 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 __LIST_H__ +#define __LIST_H__ + +#include + +#define EINA_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) + +#define EINA_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) + +#define EINA_LIST_REMOVE_LIST(a, b) \ + a = eina_list_remove_list(a, b) + +#define EINA_LIST_FREE_LIST(a) \ + a = eina_list_free(a) + +#define EINA_LIST_PROMOTE_LIST(a, b) \ + a = eina_list_promote_list(a, b) + +#ifdef EINA_LIST +#include +typedef Eina_List dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = eina_list_prepend(a, b) +#define DD_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) +#define DD_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) +#define DD_LIST_LENGTH(a) \ + eina_list_count(a) +#define DD_LIST_NTH(a, b) \ + eina_list_nth(a, b) +#define DD_LIST_FREE_LIST(a) \ + a = eina_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + EINA_LIST_FOREACH(head, elem, node) +#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ + EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) + +#else +#include +typedef GList dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = g_list_prepend(a, (gpointer)b) +#define DD_LIST_APPEND(a, b) \ + a = g_list_append(a, (gpointer)b) +#define DD_LIST_REMOVE(a, b) \ + a = g_list_remove(a, (gpointer)b) +#define DD_LIST_LENGTH(a) \ + g_list_length(a) +#define DD_LIST_NTH(a, b) \ + g_list_nth_data(a, b) +#define DD_LIST_FREE_LIST(a) \ + g_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) +#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ + for (elem = head, elem_next = g_list_next(elem), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem_next, elem_next = g_list_next(elem), node = NULL) + +#endif + +#endif diff --git a/packaging/hal-api-device.manifest b/packaging/hal-api-device.manifest new file mode 100644 index 0000000..b631abe --- /dev/null +++ b/packaging/hal-api-device.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/hal-api-device.spec b/packaging/hal-api-device.spec new file mode 100644 index 0000000..2d404aa --- /dev/null +++ b/packaging/hal-api-device.spec @@ -0,0 +1,58 @@ +Name: hal-api-device +Summary: API library for HAL device modules +Version: 1.0.0 +Release: 0 +Group: System/API +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +Source1: hal-api-device.manifest +BuildRequires: cmake +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(tracker) +BuildRequires: pkgconfig(libsyscommon) + +%description +API library for HAL device modules + +%package devel +Summary: API library for HAL device modules (Development) +Group: System/Development +Requires: %{name} = %{version}-%{release} + +%description devel +API library for HAL device modules (Development package) + +%prep +%setup -q + +%build +cp %{SOURCE1} . +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%cmake . -DFULLVER=%{version} \ + -DMAJORVER=${MAJORVER} + +%__make %{?jobs:-j%jobs} + +%install +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 +%{_libdir}/hal/libhal-api-device.so.* + +%files devel +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 +%{_includedir}/hal/hal-*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/hal/libhal-api-device.so diff --git a/src/battery.c b/src/battery.c new file mode 100644 index 0000000..9a2eb08 --- /dev/null +++ b/src/battery.c @@ -0,0 +1,428 @@ +/* + * 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 +#include +#include +#include +#include +#define _GNU_SOURCE +#include +#include + +#include "hal-battery.h" +#include "hal-battery-internal.h" +#include "common.h" +#include + +#define METHOD_GET_PERCENT "GetPercent" +#define METHOD_GET_INFO "GetBatteryInfo" + +#define BATTERY_FEATURE "http://tizen.org/feature/battery" + +#ifndef LIBPATH +#error LIBPATH is not defined. +#endif + +#define BATTERY_PLUGIN LIBPATH"/libbattery-plugin.so" +#define GET_INFO_FUNC "battery_get_info_direct" + +static void *handle; +static int (*plugin_battery_get_info)(void *); + +static int is_battery_supported(void) +{ + int ret; + bool battery_avail; + + ret = system_info_get_platform_bool(BATTERY_FEATURE, &battery_avail); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get value of battery feature"); + return false; +//LCOV_EXCL_STOP + } else if (ret == 0 && !battery_avail) { +//LCOV_EXCL_START System Error + _D("Battery is not supported"); + return false; +//LCOV_EXCL_STOP + } else + return true; +} + + +int device_battery_get_percent(int *percent) +{ + int ret; + + if (!percent) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, + METHOD_GET_PERCENT, NULL); + /* regard not suppoted as disconnected */ + if (ret == -ENOTSUP) + ret = 0; + else if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *percent = ret; + return DEVICE_ERROR_NONE; +} + +int device_battery_is_charging(bool *charging) +{ + int ret, val; + + if (!charging) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &val); + /* regard not supported as disconnected */ + if (val == -ENOTSUP) + val = 0; //LCOV_EXCL_LINE System Error + else if (ret < 0 || val < 0 || val > 1) + return DEVICE_ERROR_OPERATION_FAILED; + + *charging = val; + return DEVICE_ERROR_NONE; +} + +int device_battery_get_level_status(device_battery_level_e *status) +{ + int val, ret; + + if (!status) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &val); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (val == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) + *status = DEVICE_BATTERY_LEVEL_EMPTY; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) + *status = DEVICE_BATTERY_LEVEL_CRITICAL; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) + *status = DEVICE_BATTERY_LEVEL_LOW; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) + *status = DEVICE_BATTERY_LEVEL_HIGH; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) + *status = DEVICE_BATTERY_LEVEL_FULL; +//LCOV_EXCL_START System Error + /* regard not supported as disconnected */ + else if (val == -ENOTSUP) + *status = DEVICE_BATTERY_LEVEL_EMPTY; +//LCOV_EXCL_STOP + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_info(struct device_battery_info *info) +{ + int ret; + GVariant *output = NULL; + char *status = NULL; + char *health = NULL; + char *power_source = NULL; + int online; + int present; + int capacity; + int current_now; + int current_average; + int voltage_now; + int voltage_average; + int temperature; + + if (!info) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + output = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, + METHOD_GET_INFO, NULL); + + if (!output) + return DEVICE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE System Error + + g_variant_get(output, "(isssiiiiiiii)", &ret, + &status, &health, &power_source, + &online, &present, &capacity, + ¤t_now, ¤t_average, &voltage_now, + &voltage_average, &temperature); + + if (ret < 0) { +//LCOV_EXCL_START System Error + ret = errno_to_device_error(ret); + goto out; +//LCOV_EXCL_STOP + } + + snprintf(info->status, sizeof(info->status), "%s", status); + snprintf(info->health, sizeof(info->health), "%s", health); + snprintf(info->power_source, sizeof(info->power_source), "%s", power_source); + info->online = online; + info->present = present; + info->capacity = capacity; + info->current_now = current_now; + info->current_average = current_average; + info->voltage_now = voltage_now; + info->voltage_average = voltage_average; + info->temperature = temperature; + + ret = DEVICE_ERROR_NONE; + +out: + g_free(status); + g_free(health); + g_free(power_source); + g_variant_unref(output); + + return ret; +} + +static int load_battery_plugin() +{ + if (plugin_battery_get_info) + return 0; + + if (!handle) { + handle = dlopen(BATTERY_PLUGIN, RTLD_NOW); + if (!handle) { +//LCOV_EXCL_START System Error + _E("Failed to open '%s' : %s", BATTERY_PLUGIN, dlerror()); + return -1; +//LCOV_EXCL_STOP + } + } + + plugin_battery_get_info = (int (*)(void *))dlsym(handle, GET_INFO_FUNC); + if (!plugin_battery_get_info) { +//LCOV_EXCL_START System Error + _E("Failed to get symbol '%s' : %s", GET_INFO_FUNC, dlerror()); + return -1; +//LCOV_EXCL_STOP + } + + return 0; +} + +int device_battery_get_info_direct(struct device_battery_info *info) +{ + int ret; + + if (!info) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (load_battery_plugin() < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + ret = plugin_battery_get_info(info); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get battery info: %d", ret); + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + } + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_health(device_battery_health_e *health) +{ + struct device_battery_info info; + int ret; + size_t len; + + if (!health) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_battery_get_info(&info); + if (ret != DEVICE_ERROR_NONE) { +//LCOV_EXCL_START System Error + _E("Failed to get battery info (%d)", ret); + return ret; +//LCOV_EXCL_STOP + } + + len = strlen(info.health); + if (!strncmp(info.health, "Good", len)) + *health = DEVICE_BATTERY_HEALTH_GOOD; + else if (!strncmp(info.health, "Cold", len)) + *health = DEVICE_BATTERY_HEALTH_COLD; + else if (!strncmp(info.health, "Dead", len)) + *health = DEVICE_BATTERY_HEALTH_DEAD; + else if (!strncmp(info.health, "Overheat", len)) + *health = DEVICE_BATTERY_HEALTH_OVER_HEAT; + else if (!strncmp(info.health, "Over voltage", len)) + *health = DEVICE_BATTERY_HEALTH_OVER_VOLTAGE; + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_power_source(device_battery_power_source_e *source) +{ + struct device_battery_info info; + int ret; + size_t len; + + if (!source) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_battery_get_info(&info); + if (ret != DEVICE_ERROR_NONE) { +//LCOV_EXCL_START System Error + _E("Failed to get battery info (%d)", ret); + return ret; +//LCOV_EXCL_STOP + } + + len = strlen(info.power_source); + if (!strncmp(info.power_source, "ac", len)) + *source = DEVICE_BATTERY_POWER_SOURCE_AC; + else if (!strncmp(info.power_source, "usb", len)) + *source = DEVICE_BATTERY_POWER_SOURCE_USB; + else if (!strncmp(info.power_source, "wireless", len)) + *source = DEVICE_BATTERY_POWER_SOURCE_WIRELESS; + else + *source = DEVICE_BATTERY_POWER_SOURCE_NONE; + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_property(device_battery_property_e property, int *val) +{ + struct device_battery_info info = {0, }; + int ret; + + if (!val) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_battery_get_info(&info); + if (ret != DEVICE_ERROR_NONE) { +//LCOV_EXCL_START System Error + _E("Failed to get battery info (%d)", ret); + return ret; +//LCOV_EXCL_STOP + } + + switch (property) { + case DEVICE_BATTERY_PROPERTY_CAPACITY: + *val = info.capacity; + break; + case DEVICE_BATTERY_PROPERTY_CURRENT_NOW: + *val = info.current_now; + break; + case DEVICE_BATTERY_PROPERTY_CURRENT_AVERAGE: + *val = info.current_average; + break; + case DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW: + *val = info.voltage_now; + break; + case DEVICE_BATTERY_PROPERTY_VOLTAGE_AVERAGE: + *val = info.voltage_average; + break; + case DEVICE_BATTERY_PROPERTY_TEMPERATURE: + *val = info.temperature; + break; + + default: + return DEVICE_ERROR_INVALID_PARAMETER; + } + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_status(device_battery_status_e *status) +{ + struct device_battery_info info; + int ret; + size_t len; + + if (!status) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_battery_get_info(&info); + if (ret != DEVICE_ERROR_NONE) { +//LCOV_EXCL_START System Error + _E("Failed to get battery info (%d)", ret); + return ret; +//LCOV_EXCL_STOP + } + + len = strlen(info.status); + if (!strncmp(info.status, "Charging", len)) + *status = DEVICE_BATTERY_STATUS_CHARGING; + else if (!strncmp(info.status, "Discharging", len)) + *status = DEVICE_BATTERY_STATUS_DISCHARGING; + else if (!strncmp(info.status, "Full", len)) + *status = DEVICE_BATTERY_STATUS_FULL; + else if (!strncmp(info.status, "Not charging", len)) + *status = DEVICE_BATTERY_STATUS_NOT_CHARGING; + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +void __attribute__ ((destructor)) battery_finalize(void) +{ + if (handle) { + dlclose(handle); + handle = NULL; + } +} diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..893c7b9 --- /dev/null +++ b/src/common.c @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2016 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 +#include +#include +#include +#include +#include "common.h" +#include + +#define MAX_LINE 128 +#define MAX_SECTION 64 +#define WHITESPACE " \t" +#define NEWLINE "\n\r" +#define COMMENT '#' + +#define MODEL_NAME "http://tizen.org/system/model_name" +#define MODEL_EMULATOR "Emulator" +#define DISPLAY_FEATURE "http://tizen.org/feature/display" +#define DISPLAY_STATE_FEATURE "http://tizen.org/feature/display.state" + +static inline char *trim_str(char *s) +{ + char *t; + /* left trim */ + s += strspn(s, WHITESPACE); + + /* right trim */ + for (t = strchr(s, 0); t > s; t--) + if (!strchr(WHITESPACE, t[-1])) + break; + *t = 0; + return s; +} + +int config_parse(const char *file_name, int cb(struct parse_result *result, + void *user_data), void *user_data) +{ + FILE *f = NULL; + struct parse_result result; + /* use stack for parsing */ + char line[MAX_LINE]; + char section[MAX_SECTION]; + char *start, *end, *name, *value; + int lineno = 0, ret = 0; + + if (!file_name || !cb) { +//LCOV_EXCL_START System Error + ret = -EINVAL; + goto error; +//LCOV_EXCL_STOP + } + + /* open conf file */ + f = fopen(file_name, "r"); + if (!f) { +//LCOV_EXCL_START System Error + if (errno == ENOENT) { + _I("There is no power config file"); + return 0; +//LCOV_EXCL_STOP + } + +//LCOV_EXCL_START System Error + _E("Failed to open file %s", file_name); + ret = -EIO; + goto error; +//LCOV_EXCL_STOP + } + + /* parsing line by line */ + while (fgets(line, MAX_LINE, f) != NULL) { + lineno++; + + start = line; + start[strcspn(start, NEWLINE)] = '\0'; + start = trim_str(start); + + if (*start == COMMENT) { + continue; + } else if (*start == '[') { + /* parse section */ + end = strchr(start, ']'); + if (!end || *end != ']') { +//LCOV_EXCL_START System Error + ret = -EBADMSG; + goto error; +//LCOV_EXCL_STOP + } + + *end = '\0'; + strncpy(section, start + 1, sizeof(section)); + section[MAX_SECTION-1] = '\0'; + } else if (*start) { + /* parse name & value */ + end = strchr(start, '='); + if (!end || *end != '=') { +//LCOV_EXCL_START System Error + ret = -EBADMSG; + goto error; +//LCOV_EXCL_STOP + } + *end = '\0'; + name = trim_str(start); + value = trim_str(end + 1); + end = strchr(value, COMMENT); + if (end && *end == COMMENT) { + *end = '\0'; + value = trim_str(value); + } + + result.section = section; + result.name = name; + result.value = value; + /* callback with parse result */ + ret = cb(&result, user_data); + if (ret < 0) { +//LCOV_EXCL_START System Error + ret = -EBADMSG; + goto error; +//LCOV_EXCL_STOP + } + } + } + _D("Success to load %s", file_name); + fclose(f); + return 0; + +//LCOV_EXCL_START System Error +error: + if (f) + fclose(f); + _E("Failed to read %s:%d!", file_name, lineno); +//LCOV_EXCL_STOP + return ret; +} + +tizen_profile_t _get_tizen_profile() +{ + static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN; + if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1)) + return profile; + + char *profileName; + system_info_get_platform_string("http://tizen.org/feature/profile", &profileName); + switch (*profileName) { + case 'm': + case 'M': + profile = TIZEN_PROFILE_MOBILE; + break; + case 'w': + case 'W': + profile = TIZEN_PROFILE_WEARABLE; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE + case 't': + case 'T': + profile = TIZEN_PROFILE_TV; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE + case 'i': + case 'I': + profile = TIZEN_PROFILE_IVI; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE + default: // common or unknown ==> ALL ARE COMMON. + profile = TIZEN_PROFILE_COMMON; //LCOV_EXCL_LINE + } + free(profileName); + + return profile; +} + +int check_async_call_rate(long *num_calls) +{ + static int status; + static struct timeval prev; + struct timeval cur; + int ret; + + if (status < 0) + return status; + + ret = gettimeofday(&cur, NULL); + if (ret < 0) + return 0; + + if (*num_calls > 0) { + long rate; + struct timeval diff; + timersub(&cur, &prev, &diff); + + if (diff.tv_sec > 0) { + rate = *num_calls / diff.tv_sec; + + if (rate > CHECK_RATE_THRESHOLD) { + status = -1; + return status; + } + + if (diff.tv_sec > CHECK_RATE_PERIOD_LEN) { + /* Reset the check period */ + *num_calls = 0; + return 0; + } + } + } else { + /* Start a new check period */ + prev = cur; + } + + *num_calls += 1; + return 0; +} + +//LCOV_EXCL_START Not used function +bool is_emulator(void) +{ + int ret; + char *model_name = NULL; + static bool emul = false; + static int set = 0; + + if (set) + return emul; + + ret = system_info_get_platform_string(MODEL_NAME, &model_name); + if (ret < 0) { + _E("Cannot get model name(%d)", ret); + return emul; + } + + if (!strncmp(MODEL_EMULATOR, model_name, strlen(model_name) + 1)) + emul = true; + + set = 1; + free(model_name); + + return emul; +} +//LCOV_EXCL_STOP + +int is_display_supported(void) +{ + int ret; + bool display_avail; + + ret = system_info_get_platform_bool(DISPLAY_FEATURE, &display_avail); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get value of display feature"); + return false; +//LCOV_EXCL_STOP + } else if (ret == 0 && !display_avail) { +//LCOV_EXCL_START System Error + _D("Display feature is not supported"); + return false; +//LCOV_EXCL_STOP + } else + return true; +} + +int is_display_state_supported(void) +{ + int ret; + bool display_state_avail; + + ret = system_info_get_platform_bool(DISPLAY_STATE_FEATURE, &display_state_avail); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get value of display state feature"); + return false; +//LCOV_EXCL_STOP + } else if (ret == 0 && !display_state_avail) { +//LCOV_EXCL_START System Error + _D("Display state feature is not supported"); + return false; +//LCOV_EXCL_STOP + } else + return true; +} diff --git a/src/device.c b/src/device.c new file mode 100644 index 0000000..4d580e1 --- /dev/null +++ b/src/device.c @@ -0,0 +1,68 @@ +/* + * 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 +#include +#include +#include + +#include "hal-device.h" +#include "hal-display.h" +#include "common.h" + +#define CHECK_ERR(val) \ + do { \ + if (val < 0) { \ + if (errno == ENODEV) \ + return DEVICE_ERROR_NOT_SUPPORTED; \ + return DEVICE_ERROR_OPERATION_FAILED; \ + } \ + } while (0) + +//LCOV_EXCL_START +int device_get_display_numbers(int* device_number) +{ + return device_display_get_numbers(device_number); +} + +int device_get_brightness(int disp_idx, int* value) +{ + return device_display_get_brightness(disp_idx, value); +} + +int device_set_brightness(int disp_idx, int new_value) +{ + _E("Deprecated api."); + return DEVICE_ERROR_NOT_SUPPORTED; +} + +int device_get_max_brightness(int disp_idx, int* max_value) +{ + return device_display_get_max_brightness(disp_idx, max_value); +} + +int device_set_brightness_from_settings(int disp_idx) +{ + _E("Deprecated api."); + return DEVICE_ERROR_NOT_SUPPORTED; +} + +int device_set_brightness_to_settings(int disp_idx, int new_value) +{ + return device_display_set_brightness(disp_idx, new_value); +} +//LCOV_EXCL_STOP diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..05284b3 --- /dev/null +++ b/src/display.c @@ -0,0 +1,426 @@ +/* + * 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 +#include +#include +#include + +#include "hal-display.h" +#include "hal-display-internal.h" +#include "common.h" + +#define METHOD_GET_DISPLAY_COUNT "GetDisplayCount" +#define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness" +#define METHOD_GET_BRIGHTNESS "GetBrightness" +#define METHOD_SET_BRIGHTNESS "SetBrightness" +#define METHOD_CHANGE_STATE "changestate" +#define METHOD_CHANGE_STATE_BY_REASON "ChangeStateByReason" + +#define STR_LCD_OFF "lcdoff" +#define STR_LCD_DIM "lcddim" +#define STR_LCD_ON "lcdon" + +static int display_cnt = -1; +struct display { + int normal_max; + int dim_max; +} *display_arr; + +static int alloc_display(void) +{ + int i; + + if (display_cnt < 0) + return -ENODEV; + + display_arr = malloc(sizeof(struct display) * display_cnt); + if (!display_arr) + return -ENOMEM; + + for (i = 0; i < display_cnt; ++i) { + display_arr[i].normal_max = -1; + display_arr[i].dim_max = -1; + } + + return 0; +} + +int device_display_get_numbers(int *device_number) +{ + int ret; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!device_number) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* if it is a first request */ + if (display_cnt < 0) { + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_DISPLAY_COUNT, NULL); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + display_cnt = ret; + alloc_display(); + } + + *device_number = display_cnt; + _I("device_number : %d", *device_number); + return DEVICE_ERROR_NONE; +} + +int device_display_get_max_brightness(int display_index, int *max_brightness) +{ + int ret; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!max_brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!display_arr && alloc_display() < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (display_arr[display_index].normal_max < 0) { + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_MAX_BRIGHTNESS, g_variant_new("(i)", (int)DISPLAY_STATE_NORMAL)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + display_arr[display_index].normal_max = ret; + } + + *max_brightness = display_arr[display_index].normal_max; + return DEVICE_ERROR_NONE; +} + +int device_display_get_brightness(int display_index, int *brightness) +{ + int ret; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_BRIGHTNESS, g_variant_new("(i)", (int)DISPLAY_STATE_NORMAL)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_display_set_brightness(int display_index, int brightness) +{ + int ret, max; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_arr[display_index].normal_max < 0) + device_display_get_max_brightness(display_index, &max); + + if (brightness < 0 || brightness > display_arr[display_index].normal_max) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", (int)DISPLAY_STATE_NORMAL, brightness)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return DEVICE_ERROR_NONE; +} + +int device_display_get_state(display_state_e *state) +{ + int ret, val; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!state) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = vconf_get_int(VCONFKEY_PM_STATE, &val); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (val == VCONFKEY_PM_STATE_NORMAL) + *state = DISPLAY_STATE_NORMAL; + else if (val == VCONFKEY_PM_STATE_LCDDIM) + *state = DISPLAY_STATE_SCREEN_DIM; + else if (val == VCONFKEY_PM_STATE_LCDOFF || val == VCONFKEY_PM_STATE_SLEEP) + *state = DISPLAY_STATE_SCREEN_OFF; + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +static char *get_state_str(display_state_e state) +{ + switch (state) { + case DISPLAY_STATE_NORMAL: + return STR_LCD_ON; + case DISPLAY_STATE_SCREEN_DIM: + return STR_LCD_DIM; + case DISPLAY_STATE_SCREEN_OFF: + return STR_LCD_OFF; + default: + break; + } + return NULL; +} + +static void change_cb(GVariant *result, void *data, GError *err) +{ + int ret; + + if (!result) { +//LCOV_EXCL_START System Error + _E("no message : %s", err->message); + return; +//LCOV_EXCL_STOP + } + + g_variant_get(result, "(i)", &ret); + _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_CHANGE_STATE, ret); +} + +int device_display_change_state(display_state_e state) +{ + char *str; + int ret; + static int privilege = -1; + static long num_calls = 0; + + ret = is_display_state_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (check_async_call_rate(&num_calls) < 0) { +//LCOV_EXCL_START System Error + _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated." + , CHECK_RATE_THRESHOLD); + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + } + + if (state < DISPLAY_STATE_NORMAL || state > DISPLAY_STATE_SCREEN_OFF) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (privilege < 0) { + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_CHANGE_STATE, g_variant_new("(s)", "privilege check")); +//LCOV_EXCL_START System Error + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error +//LCOV_EXCL_STOP + else + privilege = 1; + } + + str = get_state_str(state); + if (!str) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_async_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_CHANGE_STATE, g_variant_new("(s)", str), change_cb, -1, NULL); + + if (ret < 0) + ret = errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return ret; +} + +int device_display_get_max_brightness_state(int display_index, display_state_e state, int *brightness) +{ + int ret; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (state > DISPLAY_STATE_SCREEN_DIM) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!display_arr && alloc_display() < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_MAX_BRIGHTNESS, g_variant_new("(i)", (int)state)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + if (state == DISPLAY_STATE_NORMAL) { + display_arr[display_index].normal_max = ret; + *brightness = display_arr[display_index].normal_max; + } else { + display_arr[display_index].dim_max = ret; + *brightness = display_arr[display_index].dim_max; + } + + return DEVICE_ERROR_NONE; +} +//LCOV_EXCL_STOP + +int device_display_get_brightness_state(int display_index, display_state_e state, int *brightness) +{ + int ret; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (state > DISPLAY_STATE_SCREEN_DIM) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_BRIGHTNESS, g_variant_new("(i)", (int)state)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *brightness = ret; + + return DEVICE_ERROR_NONE; +} + +int device_display_set_brightness_state(int display_index, display_state_e state, int brightness) +{ + int ret, max; + + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + if (state > DISPLAY_STATE_SCREEN_DIM) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + switch (state) { + case DISPLAY_STATE_NORMAL: + if (display_arr[display_index].normal_max < 0) + device_display_get_max_brightness_state(display_index, DISPLAY_STATE_NORMAL, &max); + if (brightness < 0 || brightness > display_arr[display_index].normal_max) + return DEVICE_ERROR_INVALID_PARAMETER; + break; + case DISPLAY_STATE_SCREEN_DIM: + if (display_arr[display_index].dim_max < 0) + device_display_get_max_brightness_state(display_index, DISPLAY_STATE_SCREEN_DIM, &max); + if (brightness < 0 || brightness > display_arr[display_index].dim_max) + return DEVICE_ERROR_INVALID_PARAMETER; + break; + default: + break; + } + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", (int)state, brightness)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return DEVICE_ERROR_NONE; +} + +int device_display_change_state_by_reason(display_state_e type, const char *reason, int timeout, dbus_pending_cb cb) +{ + int ret; + + ret = dbus_handle_method_async_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_CHANGE_STATE_BY_REASON, g_variant_new("(isi)", (int)type, reason, timeout), cb, -1, NULL); + + return errno_to_device_error(ret); +} diff --git a/src/haptic.c b/src/haptic.c new file mode 100644 index 0000000..09e38e1 --- /dev/null +++ b/src/haptic.c @@ -0,0 +1,343 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 +#include +#include +#include +#include + +#include "hal-haptic.h" +#include "common.h" +#include "list.h" + +#define SIGNAL_VIBRATOR_INITIATED "InitiateVibrator" + +#define METHOD_GET_COUNT "GetCount" +#define METHOD_OPEN_DEVICE "OpenDevice" +#define METHOD_CLOSE_DEVICE "CloseDevice" +#define METHOD_STOP_DEVICE "StopDevice" +#define METHOD_VIBRATE_MONOTONE "VibrateMonotone" + +#define VIBRATION_FEATURE "http://tizen.org/feature/feedback.vibration" + +enum feedback_e { + HAPTIC_FEEDBACK_MIN = 0, + HAPTIC_FEEDBACK_MAX = 100, +}; + +enum priority_e { + HAPTIC_PRIORITY_MIN = 0, + HAPTIC_PRIORITY_MIDDLE, + HAPTIC_PRIORITY_HIGH, +}; + +struct haptic_handle { + int index; + int handle; +}; + +static guint haptic_id = 0; +static dd_list *handle_list; + +static int is_haptic_supported(void) +{ + int ret; + bool haptic_avail; + + ret = system_info_get_platform_bool(VIBRATION_FEATURE, &haptic_avail); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get value of haptic feature"); + return false; +//LCOV_EXCL_STOP + } else if (ret == 0 && !haptic_avail) { +//LCOV_EXCL_START System Error + _D("Haptic is not supported"); + return false; +//LCOV_EXCL_STOP + } else + return true; +} + +int device_haptic_get_count(int *device_number) +{ + int ret; + + if (!device_number) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + /* request to deviced to get haptic count */ + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_GET_COUNT, NULL); + /** + * there is no haptic method in no vibration model. + * so -ENOTSUP means that haptic count is zero. + */ + if (ret == -ENOTSUP) + ret = 0; + else if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *device_number = ret; + return DEVICE_ERROR_NONE; +} + +//LCOV_EXCL_START Not called Callback +static void restart_callback(void) +{ + dd_list *elem, *elem_next; + struct haptic_handle *temp; + int ret; + + DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_OPEN_DEVICE, g_variant_new("(i)", temp->index)); + if (ret < 0) { + _E("Failed to open device"); + continue; + } + temp->handle = ret; + } + +} +//LCOV_EXCL_STOP + +//LCOV_EXCL_START Not called Callback +static void haptic_signal_callback(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *signal, + GVariant *param, + gpointer data) +{ + size_t iface_len, signal_len; + + if (!param || !sender || !path || !iface || !signal) + return; + + iface_len = strlen(iface) + 1; + signal_len = strlen(signal) + 1; + + if (strncmp(iface, VIBRATOR_INTERFACE_HAPTIC, iface_len)) + return; + + if (strncmp(signal, SIGNAL_VIBRATOR_INITIATED, signal_len)) + return; + + restart_callback(); +} +//LCOV_EXCL_STOP + +int device_haptic_open(int device_index, haptic_device_h *device_handle) +{ + dd_list *elem, *elem_next; + struct haptic_handle *handle; + struct haptic_handle *temp; + int ret, max; + bool found = false; + + ret = device_haptic_get_count(&max); + if (ret < 0) + return ret; + + if (device_index < 0 || device_index >= max) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + /* request to deviced to open haptic device */ + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_OPEN_DEVICE, g_variant_new("(i)", device_index)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + if (temp->handle == ret) { + found = true; + temp->index = device_index; + break; + } + } + + if (!found) { + handle = (struct haptic_handle *)malloc(sizeof(struct haptic_handle)); + if (!handle) { +//LCOV_EXCL_START System Error + _E("Failed to malloc"); + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + } + + handle->handle = ret; + handle->index = device_index; + DD_LIST_APPEND(handle_list, handle); + *device_handle = (haptic_device_h)handle; + } + if (DD_LIST_LENGTH(handle_list) == 1) { + haptic_id = subscribe_dbus_signal(NULL, + VIBRATOR_PATH_HAPTIC, + VIBRATOR_INTERFACE_HAPTIC, + NULL, + haptic_signal_callback, + NULL, + NULL); + if (haptic_id <= 0) + _E("Faild to register signal handler"); //LCOV_EXCL_LINE Logs + } + + return DEVICE_ERROR_NONE; +} + +int device_haptic_close(haptic_device_h device_handle) +{ + dd_list *elem, *elem_next; + struct haptic_handle *handle = (struct haptic_handle *)device_handle; + struct haptic_handle *temp; + int ret; + bool found = false; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + if (temp->handle != handle->handle) + continue; + found = true; + break; + } + + if (!found) + return DEVICE_ERROR_OPERATION_FAILED; + DD_LIST_REMOVE(handle_list, handle); + + /* request to deviced to open haptic device */ + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_CLOSE_DEVICE, g_variant_new("(u)", (unsigned int)handle->handle)); + + free(handle); + + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + if (DD_LIST_LENGTH(handle_list) == 0) + unsubscribe_dbus_signal(NULL, haptic_id); + + return DEVICE_ERROR_NONE; +} + +int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle) +{ + dd_list *elem, *elem_next; + struct haptic_handle *handle = (struct haptic_handle *)device_handle; + struct haptic_handle *temp; + int ret, priority; + bool found = false; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (duration < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (feedback < HAPTIC_FEEDBACK_MIN || feedback > HAPTIC_FEEDBACK_MAX) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + priority = HAPTIC_PRIORITY_MIN; + + DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + if (temp != handle) + continue; + found = true; + break; + } + if (!found) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* request to deviced to vibrate haptic device */ + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_VIBRATE_MONOTONE, + g_variant_new("(uiii)", (unsigned int)handle->handle, duration, feedback, priority)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + if (effect_handle) + *effect_handle = (haptic_effect_h)ret; + + return DEVICE_ERROR_NONE; +} + +int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle) +{ + dd_list *elem, *elem_next; + struct haptic_handle *handle = (struct haptic_handle *)device_handle; + struct haptic_handle *temp; + int ret; + bool found = false; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + if (temp != handle) + continue; + found = true; + break; + } + if (!found) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* TODO : support to stop haptic effect */ + + /* request to deviced to open haptic device */ + ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, + VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, + METHOD_STOP_DEVICE, g_variant_new("(u)", (unsigned int)handle->handle)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return DEVICE_ERROR_NONE; +} diff --git a/src/ir.c b/src/ir.c new file mode 100644 index 0000000..aa0ed20 --- /dev/null +++ b/src/ir.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 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 +#include +#include + +#include "hal-ir.h" +#include "common.h" + +#define METHOD_IS_AVAILABLE "IRIsAvailable" +#define METHOD_TRANSMIT "TransmitIR" +#define IR_FEATURE "http://tizen.org/feature/consumer_ir" + + +int device_ir_is_available(bool *available) +{ + int ret; + bool ir_avail; + + if (!available) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = system_info_get_platform_bool(IR_FEATURE, &ir_avail); + + if (ret < 0) { +//LCOV_EXCL_START System Error + *available = false; + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + } else if (ret == 0 && !ir_avail) { + *available = false; + return DEVICE_ERROR_NOT_SUPPORTED; + } + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_IR, + DEVICED_INTERFACE_IR, METHOD_IS_AVAILABLE, + NULL); + +//LCOV_EXCL_START System Error + if (ret == -EACCES || ret == -EPERM) + return DEVICE_ERROR_PERMISSION_DENIED; + if (!ret) { + *available = false; + return DEVICE_ERROR_OPERATION_FAILED; + } +//LCOV_EXCL_STOP + + *available = ir_avail; + return DEVICE_ERROR_NONE; +} + +int device_ir_transmit(int carrier_frequency, int *pattern, int size) +{ + int ret; + int i; + bool ir_avail; + GVariantBuilder *builder; + + ret = device_ir_is_available(&ir_avail); + if (!ir_avail) { + if (ret < 0) { + _E("IR is not supported or IR operation failed"); + return ret; + } +//LCOV_EXCL_START System Error + _E("IR is not supported"); + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + } +//LCOV_EXCL_START System Error + if (!pattern) + return DEVICE_ERROR_INVALID_PARAMETER; + if (size <= 0) { + _E("IR pattern size is invalid"); + return DEVICE_ERROR_INVALID_PARAMETER; + } +//LCOV_EXCL_STOP + builder = g_variant_builder_new(G_VARIANT_TYPE ("ai")); + + g_variant_builder_add(builder, "i", carrier_frequency); + for (i = 0; i < size; ++i) + g_variant_builder_add(builder, "i", pattern[i]); + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_IR, + DEVICED_INTERFACE_IR, METHOD_TRANSMIT, + g_variant_new("(ai)", builder)); + + g_variant_builder_unref(builder); +//LCOV_EXCL_START System Error + if (ret == -EACCES || ret == -EPERM) + return DEVICE_ERROR_PERMISSION_DENIED; + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; +//LCOV_EXCL_STOP + + return DEVICE_ERROR_NONE; +} diff --git a/src/led.c b/src/led.c new file mode 100644 index 0000000..ef417d6 --- /dev/null +++ b/src/led.c @@ -0,0 +1,215 @@ +/* + * 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 +#include +#include +#include +#include + +#include "hal-led.h" +#include "hal-led-internal.h" +#include "common.h" + +#define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness" +#define METHOD_GET_BRIGHTNESS "GetBrightness" +#define METHOD_SET_BRIGHTNESS "SetBrightness" +#define METHOD_PLAY_CUSTOM "playcustom" +#define METHOD_GET_LED_NUMBER "GetNumOfLeds" +#define METHOD_MULTI_LED_CONTROL "multi_led_control" +#define METHOD_STOP_CUSTOM "stopcustom" + +#define FRONT_LED_FEATURE "tizen.org/feature/led" +#define CAMERA_LED_FEATURE "tizen.org/feature/camera.back.flash" + +static bool support_front_led; +static bool support_camera_led; +static int number_of_devices = -1; + +static void __CONSTRUCTOR__ init(void) +{ + int ret; + bool val; + + ret = system_info_get_platform_bool(FRONT_LED_FEATURE, &val); + if (ret == SYSTEM_INFO_ERROR_NONE && val) + support_front_led = true; + + ret = system_info_get_platform_bool(CAMERA_LED_FEATURE, &val); + if (ret == SYSTEM_INFO_ERROR_NONE && val) + support_camera_led = true; +} + +int device_flash_get_max_brightness(int *max_brightness) +{ + int ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!max_brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_MAX_BRIGHTNESS, NULL); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *max_brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_flash_get_brightness(int *brightness) +{ + int ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_BRIGHTNESS, NULL); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_flash_set_brightness(int brightness) +{ + int max, ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_flash_get_max_brightness(&max); + if (ret < 0) + return ret; + + if (brightness < 0 || brightness > max) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* if camera API preempt a flash device, it will return -EBUSY error. */ + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", brightness, 0)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return DEVICE_ERROR_NONE; +} + +int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags) +{ + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (on < 0 || off < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_PLAY_CUSTOM, g_variant_new("(iiuu)", on, off, (unsigned int)color, (unsigned int)flags)); +//LCOV_EXCL_START System Error + if (ret < 0) + return errno_to_device_error(ret); +//LCOV_EXCL_STOP + + return DEVICE_ERROR_NONE; +} + +int device_led_stop_custom(void) +{ + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_STOP_CUSTOM, NULL); +//LCOV_EXCL_START System Error + if (ret < 0) + return errno_to_device_error(ret); +//LCOV_EXCL_STOP + + return DEVICE_ERROR_NONE; +} + +int device_multi_led_get_number(int *num_of_leds) +{ + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!num_of_leds) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (number_of_devices < 0) { + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_LED_NUMBER, NULL); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + number_of_devices = ret; + } + + *num_of_leds = number_of_devices; + + return DEVICE_ERROR_NONE; +} + +int device_multi_led_control(unsigned int color[]) +{ + GVariantBuilder *builder = NULL; + GVariant *var = NULL; + int i, ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (color == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (number_of_devices < 0) { + ret = device_multi_led_get_number(&number_of_devices); + if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error + return ret; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("au")); + for (i = 0; i < number_of_devices; i++) + g_variant_builder_add(builder, "u", color[i]); + + var = g_variant_new("(au)", builder); + g_variant_builder_unref(builder); + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, METHOD_MULTI_LED_CONTROL, var); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + return DEVICE_ERROR_NONE; +} diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..58f3adf --- /dev/null +++ b/src/memory.c @@ -0,0 +1,138 @@ +/* + * 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 +#include +#include +#include +#include "hal-device.h" +#include "common.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", +}; + +//LCOV_EXCL_START Not used function +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; +} +//EXCL_LCOV_STOP diff --git a/src/temperature.c b/src/temperature.c new file mode 100644 index 0000000..36545cc --- /dev/null +++ b/src/temperature.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 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 +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "hal-temperature.h" + +#define METHOD_GET_TEMPERATURE "GetTemperature" + +#define THERMAL_AP_FEATURE "http://tizen.org/feature/thermistor.ap" +#define THERMAL_CP_FEATURE "http://tizen.org/feature/thermistor.cp" +#define THERMAL_BATTERY_FEATURE "http://tizen.org/feature/thermistor.battery" + +static int is_temperature_supported(device_thermal_e type) +{ + int ret = 0; + bool thermal_avail; + + if (type == DEVICE_THERMAL_AP) + ret = system_info_get_platform_bool(THERMAL_AP_FEATURE, &thermal_avail); + else if (type == DEVICE_THERMAL_CP) + ret = system_info_get_platform_bool(THERMAL_CP_FEATURE, &thermal_avail); + else + ret = system_info_get_platform_bool(THERMAL_BATTERY_FEATURE, &thermal_avail); + if (ret < 0) { +//LCOV_EXCL_START System Error + _E("Failed to get value of temp feature : %d", ret); + return false; +//LCOV_EXCL_STOP + } else if (ret == 0 && !thermal_avail) { +//LCOV_EXCL_START System Error + _D("Temperature is not supported"); + return false; +//LCOV_EXCL_STOP + } else + return true; +} + +int device_thermal_get_temperature(device_thermal_e type, int *temp) +{ + int ret; + + if (type > DEVICE_THERMAL_BATTERY) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_temperature_supported(type); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, + DEVICED_PATH_TEMPERATURE, + DEVICED_INTERFACE_TEMPERATURE, + METHOD_GET_TEMPERATURE, g_variant_new("(i)", type)); + if (ret < 0) + return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error + + *temp = ret; + return DEVICE_ERROR_NONE; +} + diff --git a/src/touchscreen-internal.c b/src/touchscreen-internal.c new file mode 100644 index 0000000..c1c2469 --- /dev/null +++ b/src/touchscreen-internal.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 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 + +#include "common.h" +#include "hal-touchscreen-internal.h" + +#define METHOD_TOUCHSCREEN_ENABLE "Enable" +#define METHOD_TOUCHSCREEN_DISABLE "Disable" + +int device_touchscreen_enable(dbus_pending_cb cb) +{ + int ret; + + ret = dbus_handle_method_async_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_TOUCH, DEVICED_INTERFACE_TOUCH, + METHOD_TOUCHSCREEN_ENABLE, NULL, NULL, cb, -1, NULL); + + return errno_to_device_error(ret); +} + +int device_touchscreen_disable(dbus_pending_cb cb) +{ + int ret; + + ret = dbus_handle_method_async_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_TOUCH, DEVICED_INTERFACE_TOUCH, + METHOD_TOUCHSCREEN_DISABLE, NULL, NULL, cb, -1, NULL); + + return errno_to_device_error(ret); +} -- 2.7.4