SET(INC_DIR include)
INCLUDE_DIRECTORIES(${INC_DIR})
-SET(dependents "devman dlog vconf capi-base-common")
+SET(dependents "deviced dlog vconf dbus-1 dbus-glib-1 capi-base-common capi-system-info")
SET(pc_dependents "capi-base-common")
INCLUDE(FindPkgConfig)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
IF("${ARCH}" STREQUAL "arm")
)
INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(FILES ${INC_DIR}/device.h ${INC_DIR}/device-error.h
+ DESTINATION include/system)
INSTALL(
- DIRECTORY ${INC_DIR}/ DESTINATION include/system
+ DIRECTORY ${INC_DIR}/ DESTINATION include/device
FILES_MATCHING
- PATTERN "*_private.h" EXCLUDE
- PATTERN "*_log.h" EXCLUDE
+ PATTERN "device.h" EXCLUDE
PATTERN "${INC_DIR}/*.h"
)
prefix=@PREFIX@
exec_prefix=/usr
libdir=@LIB_INSTALL_DIR@
-includedir=/usr/include/system
+includedir=/usr/include
Name: @PC_NAME@
Description: @PACKAGE_DESCRIPTION@
Version: @VERSION@
-Requires: @PC_REQUIRED@
+Requires: @PC_REQUIRED@
Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir}
-
+Cflags: -I${includedir} -I/usr/include/system
--- /dev/null
+/*
+ * 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 <stdbool.h>
+#include "device-error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for the battery level status.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+ DEVICE_BATTERY_LEVEL_EMPTY = 0, /**< The battery goes empty. Prepare for the safe termination of the application, because the device starts a shutdown process soon after entering this level. */
+ DEVICE_BATTERY_LEVEL_CRITICAL, /**< The battery charge is at a critical state. You may have to stop using multimedia features, because they are not guaranteed to work correctly at this battery status. */
+ DEVICE_BATTERY_LEVEL_LOW, /**< The battery has little charge left. */
+ DEVICE_BATTERY_LEVEL_HIGH, /**< The battery status is not to be careful. */
+ DEVICE_BATTERY_LEVEL_FULL, /**< The battery status is full. */
+} device_battery_level_e;
+
+/**
+ * @brief 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 2.3
+ *
+ * @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
+ */
+int device_battery_get_percent(int *percent);
+
+/**
+ * @brief Gets the charging state.
+ *
+ * @since_tizen 2.3
+ *
+ * @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
+ *
+ * @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 2.3
+ *
+ * @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
+ *
+ * @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);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __TIZEN_SYSTEM_BATTERY_H__
--- /dev/null
+/*
+ * 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_CALLBACK_H__
+#define __TIZEN_SYSTEM_CALLBACK_H__
+
+#include <stdbool.h>
+#include "device-error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_CALLBACK_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for the device state callback.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+ DEVICE_CALLBACK_BATTERY_CAPACITY, /**< Called when a battery charge percentage is changed */
+ DEVICE_CALLBACK_BATTERY_LEVEL, /**< Called when a battery level is changed */
+ DEVICE_CALLBACK_BATTERY_CHARGING, /**< Called when battery charging state is changed */
+ DEVICE_CALLBACK_DISPLAY_STATE, /**< Called when a display state is changed */
+ DEVICE_CALLBACK_MAX
+} device_callback_e;
+
+/**
+ * @brief Called when a device status is changed.
+ * @details Each device callback has a different output param type. \n
+ * So you need to check below output param before using this function. \n
+ * callback enum output type \n
+ * DEVICE_CALLBACK_BATTERY_CAPACITY int \n
+ * DEVICE_CALLBACK_BATTERY_LEVEL int \n
+ * DEVICE_CALLBACK_BATTERY_CHARGING bool \n
+ * DEVICE_CALLBACK_DISPLAY_STATE int
+ *
+ * @since_tizen 2.3
+ *
+ * @param[out] type The device type to monitor
+ * @param[out] value The changed value \n
+ * @param[out] user_data The user data passed from the callback registration function
+ */
+typedef void (*device_changed_cb)(device_callback_e type, void *value, void *user_data);
+
+/**
+ * @brief Adds a callback to the observing device state.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in] type The device type to monitor
+ * @param[in] callback The callback function to add
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @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_ALREADY_IN_PROGRESS Operation already
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ */
+int device_add_callback(device_callback_e type, device_changed_cb callback, void *user_data);
+
+/**
+ * @brief Removes a device callback function.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in] type The device type to monitor
+ * @param[in] callback The callback function to remove
+ *
+ * @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
+ */
+int device_remove_callback(device_callback_e type, device_changed_cb callback);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __TIZEN_SYSTEM_CALLBACK_H__
--- /dev/null
+/*
+ * 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 <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumerations of error code for Device.
+ */
+typedef enum
+{
+ DEVICE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ DEVICE_ERROR_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_NOT_INITIALIZED = TIZEN_ERROR_DEVICE | 0x13, /**< Not initialized */
+} device_error_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __TIZEN_SYSTEM_DEVICE_ERROR_H__
#define __TIZEN_SYSTEM_DEVICE_H__
#include <stdbool.h>
-#include <tizen_error.h>
+#include "device-error.h"
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief Enumerations of error code for Device.
- */
-typedef enum
-{
- DEVICE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- DEVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- DEVICE_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */
- DEVICE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_SYSTEM_CLASS | 0x13, /**< Not supported in this device */
-} device_error_e;
-
-/**
* @brief Enumerations of the battery warning status
*/
typedef enum
--- /dev/null
+/*
+ * 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"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_DISPLAY_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets the number of display devices.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/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
+ *
+ * @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 2.3
+ * @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
+ *
+ * @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()
+ * @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 2.3
+ * @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
+ *
+ * @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()
+ * @see device_display_get_max_brightness()
+ */
+int device_display_get_brightness(int display_index, int *brightness);
+
+/**
+ * @brief Sets the display brightness value.
+ *
+ * @since_tizen 2.3
+ * @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().
+ *
+ * @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_get_brightness()
+ */
+int device_display_set_brightness(int display_index, int brightness);
+
+/**
+ * @brief Enumeration for the available display states.
+ * @details An application cannot put the device into the power off state or the suspend state.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+ DISPLAY_STATE_NORMAL, /**< Normal state */
+ DISPLAY_STATE_SCREEN_DIM, /**< Screen dim state */
+ DISPLAY_STATE_SCREEN_OFF, /**< Screen off state */
+} display_state_e;
+
+/**
+ * @brief Gets the current display state.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/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
+ *
+ * @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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ *
+ * @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
+ *
+ * @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 )
+ * printf("[ERROR] return value result =%d, \n",result);
+ * else
+ * printf("[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__
--- /dev/null
+/*
+ * 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.
+ */
+typedef void* haptic_device_h;
+
+/**
+ * @brief The haptic effect handle.
+ */
+typedef void* haptic_effect_h;
+
+/**
+ * @brief Gets the number of vibrators.
+ *
+ * @since_tizen 2.3
+ * @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 2.3
+ * @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
+ * @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 2.3
+ * @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 2.3
+ * @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).
+ *
+ * @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 2.3
+ * @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__
--- /dev/null
+/*
+ * 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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ *
+ * @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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ *
+ * @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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ *
+ * @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
+ */
+int device_flash_set_brightness(int brightness);
+
+/**
+ * @brief Enumeration for custom LED flags.
+ * @since_tizen 2.3
+ */
+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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/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 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/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__
--- /dev/null
+/*
+ * 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_POWER_H__
+#define __TIZEN_SYSTEM_POWER_H__
+
+#include <stdbool.h>
+#include "device-error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_SYSTEM_DEVICE_POWER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for lock type.
+ * @details Each enum ensures that the suitable device is on
+ * until all the lock requests have been released or after a timeout. \n
+ * CPU Brightness \n
+ * POWER_LOCK_CPU ON OFF \n
+ * POWER_LOCK_DISPLAY ON ON(normal) \n
+ * POWER_LOCK_DISPLAY_DIM ON ON(dim)
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks An application can lock the specific type.
+ * @remarks These enums are mutually exclusive.
+ * @remarks You cannot combine with an enum below.
+ *
+ */
+typedef enum
+{
+ POWER_LOCK_CPU, /**< CPU lock */
+ POWER_LOCK_DISPLAY, /**< Display normal lock */
+ POWER_LOCK_DISPLAY_DIM, /**< Display dim lock */
+} power_lock_e;
+
+/**
+ * @brief Locks the given lock state for a specified time.
+ * @details After the given @a timeout_ms (in milliseconds), unlock the given lock state automatically.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ *
+ * @remarks If the process dies, then every lock will be removed.
+ *
+ * @param[in] type The power type to request lock
+ * @param[in] timeout_ms The positive number in milliseconds or @c 0 for permanent lock \n
+ * So you must release the permanent lock of power state with #device_power_release_lock() if @a timeout_ms is zero.
+ *
+ * @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_power_release_lock()
+ */
+int device_power_request_lock(power_lock_e type, int timeout_ms);
+
+/**
+ * @brief Releases the given lock state locked before.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ *
+ * @param[in] type The power type to release lock
+ *
+ * @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_power_request_lock()
+ */
+int device_power_release_lock(power_lock_e type);
+
+/**
+ * @brief Changes the current power state to the normal/dim state.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/display
+ *
+ * @param[in] dim Set @c true to set the dim state,
+ * otherwise set @c false to not set the dim 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
+ *
+ * @post The device will be in #DISPLAY_STATE_NORMAL state.
+ */
+int device_power_wakeup(bool dim);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __TIZEN_SYSTEM_POWER_H__
Source0: %{name}-%{version}.tar.gz
Source1: capi-system-device.manifest
BuildRequires: cmake
-BuildRequires: pkgconfig(devman)
+BuildRequires: pkgconfig(deviced)
BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(dbus-glib-1)
%description
A Device library in TIZEN C API package.
%files devel
%manifest %{name}.manifest
-%{_includedir}/system/device.h
+%{_includedir}/device/*.h
+%{_includedir}/system/*.h
%{_libdir}/pkgconfig/*.pc
%{_libdir}/libcapi-system-device.so
/*
- * capi-system-device
- * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * 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
+ * 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,
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <devman.h>
+#include <errno.h>
#include <vconf.h>
-#include "device.h"
-#include "device_log.h"
-#define CHECK_ERR(val) \
- do { \
- if (val == DEVMAN_ERROR_NOT_SUPPORTED) \
- return DEVICE_ERROR_NOT_SUPPORTED; \
- else if (val == DEVMAN_ERROR_OPERATION_FAILED) \
- return DEVICE_ERROR_OPERATION_FAILED; \
- } while(0)
+#include "battery.h"
+#include "common.h"
+#include "dbus.h"
-int device_battery_get_percent(int* percent)
-{
- if (percent == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- int pct = device_get_battery_pct();
- CHECK_ERR(pct);
-
- *percent = pct;
- return DEVICE_ERROR_NONE;
-}
+#define METHOD_GET_PERCENT "GetPercent"
-int device_battery_get_detail(int* percent)
+int device_battery_get_percent(int *percent)
{
- if (percent == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- int pct = device_get_battery_pct_raw();
- CHECK_ERR(pct);
+ int ret;
- *percent = pct;
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_is_full(bool* full)
-{
- if (full == NULL)
+ if (!percent)
return DEVICE_ERROR_INVALID_PARAMETER;
- int f = device_is_battery_full();
- CHECK_ERR(f);
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY,
+ METHOD_GET_PERCENT, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
- *full = (f == 1) ? true : false;
+ *percent = ret;
return DEVICE_ERROR_NONE;
}
int device_battery_is_charging(bool *charging)
{
- // VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW
- int value, err;
+ int ret, val;
- if (charging == NULL)
+ if (!charging)
return DEVICE_ERROR_INVALID_PARAMETER;
- err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
- if (err < 0)
+ ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &val);
+ if (ret < 0 || val < 0 || val > 1)
return DEVICE_ERROR_OPERATION_FAILED;
- if (value == 1) {
- *charging = true;
- } else if (value == 0) {
- *charging = false;
- } else {
- return DEVICE_ERROR_OPERATION_FAILED;
- }
-
- return DEVICE_ERROR_NONE;
-}
-
-static device_battery_cb changed_callback = NULL;
-static void* changed_callback_user_data = NULL;
-
-static void battery_changed_inside_cb(keynode_t* key, void* user_data)
-{
- const char* keyname = vconf_keynode_get_name(key);
-
- if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) {
- int percent = 0;
- if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) {
- changed_callback(percent, changed_callback_user_data);
- }
- }
-}
-
-int device_battery_set_cb(device_battery_cb callback, void* user_data)
-{
- // VCONFKEY_SYSMAN_BATTERY_CAPACITY
- int err;
- if (callback == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- changed_callback = callback;
- changed_callback_user_data = user_data;
-
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL);
- if (err < 0)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_unset_cb(void)
-{
- int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
-
- changed_callback = NULL;
- changed_callback_user_data = NULL;
-
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_get_warning_status(device_battery_warn_e *status)
-{
- if (status == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- int value, err;
-
- err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
-
- if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) {
- *status = DEVICE_BATTERY_WARN_EMPTY;
- } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
- *status = DEVICE_BATTERY_WARN_CRITICAL;
- } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
- *status = DEVICE_BATTERY_WARN_LOW;
- } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) {
- *status = DEVICE_BATTERY_WARN_NORMAL;
- } else if (value == VCONFKEY_SYSMAN_BAT_FULL) {
- *status = DEVICE_BATTERY_WARN_FULL;
- } else {
- return DEVICE_ERROR_OPERATION_FAILED;
- }
-
- return DEVICE_ERROR_NONE;
-}
-
-static device_battery_warn_cb warn_changed_callback = NULL;
-static void* warn_changed_callback_user_data = NULL;
-static device_battery_level_cb level_changed_callback = NULL;
-static void* level_changed_callback_user_data = NULL;
-
-static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data)
-{
- const char* keyname = vconf_keynode_get_name(key);
-
- if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) {
- int bat_state = 0;
- if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) {
- warn_changed_callback(bat_state-1, warn_changed_callback_user_data);
- }
- }
-}
-
-static void battery_level_changed_inside_cb(keynode_t* key, void* user_data)
-{
- const char* keyname;
- keyname = vconf_keynode_get_name(key);
-
- if (keyname != NULL && level_changed_callback != NULL &&
- strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS) == 0) {
- int bat_state = 0;
- if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &bat_state) == 0) {
- level_changed_callback(bat_state, level_changed_callback_user_data);
- }
- }
-}
-
-int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data)
-{
- // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW
- int err;
-
- if (callback == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- warn_changed_callback = callback;
- warn_changed_callback_user_data = user_data;
-
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL);
- if (err < 0)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_warning_unset_cb(void)
-{
- int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
-
- warn_changed_callback = NULL;
- warn_changed_callback_user_data = NULL;
-
- return DEVICE_ERROR_NONE;
-}
-
-static device_battery_remaining_time_changed_cb timetofull_changed_cb = NULL;
-static device_battery_remaining_time_changed_cb timetoempty_changed_cb = NULL;
-static void* timetofull_cb_user_data = NULL;
-static void* timetoempty_cb_user_data = NULL;
-
-static void device_battery_time_timetofull_inside_cb(keynode_t* key, void* user_data)
-{
- const char* keyname = vconf_keynode_get_name(key);
- int time = -1, err= -1;
-
- if (keyname == NULL)
- return;
-
- if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOFULL) == 0) {
- if (timetofull_changed_cb != NULL) {
- err = device_battery_get_remaining_time(
- DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &time);
- if ((err == DEVICE_ERROR_NONE) && (time >= 0))
- timetofull_changed_cb(time, timetofull_cb_user_data);
- }
- }
-}
-
-static void device_battery_time_timetoempty_inside_cb(keynode_t* key, void* user_data)
-{
- const char* keyname = vconf_keynode_get_name(key);
- int time = -1, err= -1;
-
- if (keyname == NULL)
- return;
-
- if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOEMPTY) == 0) {
- if (timetoempty_changed_cb != NULL) {
- err = device_battery_get_remaining_time(
- DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED, &time);
- if ((err == DEVICE_ERROR_NONE) && (time >= 0))
- timetoempty_changed_cb(time, timetoempty_cb_user_data);
- }
- }
-}
-
-int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time)
-{
- bool charging = false;
- int err = -1;
-
- err = device_battery_is_charging(&charging);
- if (err != DEVICE_ERROR_NONE)
- return DEVICE_ERROR_OPERATION_FAILED;
-
- switch(type) {
- case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
- if (charging == false) {
- return DEVICE_ERROR_OPERATION_FAILED;
- } else {
- err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, time);
- if (err < 0 || time < 0) {
- return DEVICE_ERROR_OPERATION_FAILED;
- }
- }
- break;
- case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
- if (charging == true) {
- return DEVICE_ERROR_OPERATION_FAILED;
- } else {
- err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, time);
- if (err < 0 || time < 0) {
- return DEVICE_ERROR_OPERATION_FAILED;
- }
- }
- break;
- default:
- return DEVICE_ERROR_INVALID_PARAMETER;
- }
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_set_remaining_time_changed_cb(device_battery_remaining_time_type_e type,
- device_battery_remaining_time_changed_cb callback, void* user_data)
-{
- int err;
-
- if (callback == NULL)
- return DEVICE_ERROR_INVALID_PARAMETER;
-
- switch(type) {
- case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
- timetofull_changed_cb = callback;
- timetofull_cb_user_data = user_data;
- err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
- device_battery_time_timetofull_inside_cb, NULL);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
- break;
- case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
- timetoempty_changed_cb = callback;
- timetoempty_cb_user_data = user_data;
- err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
- device_battery_time_timetoempty_inside_cb, NULL);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
- break;
- default:
- return DEVICE_ERROR_INVALID_PARAMETER;
- }
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type)
-{
- int err;
-
- switch(type) {
- case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED:
- err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL,
- device_battery_time_timetofull_inside_cb);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
- timetofull_changed_cb = NULL;
- timetofull_cb_user_data = NULL;
- break;
- case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED:
- err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY,
- device_battery_time_timetoempty_inside_cb);
- if (err < 0)
- return DEVICE_ERROR_OPERATION_FAILED;
- timetoempty_changed_cb = NULL;
- timetoempty_cb_user_data = NULL;
- break;
- default:
- return DEVICE_ERROR_INVALID_PARAMETER;
- }
+ *charging = val;
return DEVICE_ERROR_NONE;
}
int device_battery_get_level_status(device_battery_level_e *status)
{
- int value, err;
+ int val, ret;
- if (status == NULL)
+ if (!status)
return DEVICE_ERROR_INVALID_PARAMETER;
-
- err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &value);
- if (err < 0)
+ ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &val);
+ if (ret < 0)
return DEVICE_ERROR_OPERATION_FAILED;
- if (value == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) {
+ if (val == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY)
*status = DEVICE_BATTERY_LEVEL_EMPTY;
- } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) {
+ else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL)
*status = DEVICE_BATTERY_LEVEL_CRITICAL;
- } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) {
+ else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_LOW)
*status = DEVICE_BATTERY_LEVEL_LOW;
- } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) {
+ else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH)
*status = DEVICE_BATTERY_LEVEL_HIGH;
- } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) {
+ else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_FULL)
*status = DEVICE_BATTERY_LEVEL_FULL;
- } else {
- return DEVICE_ERROR_OPERATION_FAILED;
- }
-
- return DEVICE_ERROR_NONE;
-}
-
-int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data)
-{
- int err;
-
-
- if (callback == NULL) {
- err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
- battery_level_changed_inside_cb);
- } else {
-
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
- battery_level_changed_inside_cb, NULL);
- }
- if (err < 0)
+ else
return DEVICE_ERROR_OPERATION_FAILED;
- level_changed_callback = callback;
- level_changed_callback_user_data = user_data;
-
return DEVICE_ERROR_NONE;
}
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <vconf.h>
+
+#include "callback.h"
+#include "battery.h"
+#include "display.h"
+#include "common.h"
+#include "dbus.h"
+#include "list.h"
+
+struct device_cb_info {
+ device_changed_cb cb;
+ void *data;
+};
+
+static dd_list *device_cb_list[DEVICE_CALLBACK_MAX];
+
+static void battery_capacity_cb(keynode_t *key, void *data)
+{
+ static device_callback_e type = DEVICE_CALLBACK_BATTERY_CAPACITY;
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ /* invoke the each callback with value */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info)
+ cb_info->cb(type, (void*)val, cb_info->data);
+}
+
+static void battery_charging_cb(keynode_t *key, void *data)
+{
+ static device_callback_e type = DEVICE_CALLBACK_BATTERY_CHARGING;
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ /* invoke the each callback with value */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info)
+ cb_info->cb(type, (void*)val, cb_info->data);
+}
+
+static void battery_level_cb(keynode_t *key, void *data)
+{
+ static device_callback_e type = DEVICE_CALLBACK_BATTERY_LEVEL;
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ int val, status;
+
+ val = vconf_keynode_get_int(key);
+
+ 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;
+ else
+ status = -1;
+
+ /* invoke the each callback with value */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info)
+ cb_info->cb(type, (void*)status, cb_info->data);
+}
+
+static void display_changed_cb(keynode_t *key, void *data)
+{
+ static device_callback_e type = DEVICE_CALLBACK_DISPLAY_STATE;
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ display_state_e state;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ switch(val) {
+ case 1: state = DISPLAY_STATE_NORMAL;
+ break;
+ case 2: state = DISPLAY_STATE_SCREEN_DIM;
+ break;
+ case 3: state = DISPLAY_STATE_SCREEN_OFF;
+ break;
+ default: state = -1;
+ break;
+ }
+
+ /* invoke the each callback with value */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info)
+ cb_info->cb(type, (void*)state, cb_info->data);
+}
+
+static int register_request(device_callback_e type)
+{
+ switch (type) {
+ case DEVICE_CALLBACK_BATTERY_CAPACITY:
+ return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY,
+ battery_capacity_cb, NULL);
+ case DEVICE_CALLBACK_BATTERY_LEVEL:
+ return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+ battery_level_cb, NULL);
+ case DEVICE_CALLBACK_BATTERY_CHARGING:
+ return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
+ battery_charging_cb, NULL);
+ case DEVICE_CALLBACK_DISPLAY_STATE:
+ return vconf_notify_key_changed(VCONFKEY_PM_STATE,
+ display_changed_cb, NULL);
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
+static int release_request(device_callback_e type)
+{
+ switch (type) {
+ case DEVICE_CALLBACK_BATTERY_CAPACITY:
+ return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY,
+ battery_capacity_cb);
+ case DEVICE_CALLBACK_BATTERY_LEVEL:
+ return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS,
+ battery_level_cb);
+ case DEVICE_CALLBACK_BATTERY_CHARGING:
+ return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
+ battery_charging_cb);
+ case DEVICE_CALLBACK_DISPLAY_STATE:
+ return vconf_ignore_key_changed(VCONFKEY_PM_STATE,
+ display_changed_cb);
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
+int device_add_callback(device_callback_e type, device_changed_cb cb, void *data)
+{
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ int ret, n;
+
+ if (type < 0 || type >= DEVICE_CALLBACK_MAX)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (!cb)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* check if it is the first request */
+ n = DD_LIST_LENGTH(device_cb_list[type]);
+ if (n == 0) {
+ ret = register_request(type);
+ if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ /* check for the same request */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) {
+ if (cb_info->cb == cb)
+ return DEVICE_ERROR_ALREADY_IN_PROGRESS;
+ }
+
+ /* add device changed callback to list (local) */
+ cb_info = malloc(sizeof(struct device_cb_info));
+ if (!cb_info)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ cb_info->cb = cb;
+ cb_info->data = data;
+
+ DD_LIST_APPEND(device_cb_list[type], cb_info);
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_remove_callback(device_callback_e type, device_changed_cb cb)
+{
+ struct device_cb_info *cb_info;
+ dd_list *elem;
+ int ret, n;
+
+ if (type < 0 || type >= DEVICE_CALLBACK_MAX)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (!cb)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* search for the same element with callback */
+ DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) {
+ if (cb_info->cb == cb)
+ break;
+ }
+
+ if (!cb_info)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* remove device callback from list (local) */
+ DD_LIST_REMOVE(device_cb_list[type], cb_info);
+ free(cb_info);
+
+ /* check if this callback is last element */
+ n = DD_LIST_LENGTH(device_cb_list[type]);
+ if (n == 0) {
+ ret = release_request(type);
+ if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ return DEVICE_ERROR_NONE;
+}
* limitations under the License.
*/
-#ifndef __DEVICE_LOG_H__
-#define __DEVICE_LOG_H__
+#ifndef __COMMON_H__
+#define __COMMON_H__
#ifdef FEATURE_DEVICE_DLOG
#define LOG_TAG "SYSTEM_DEVICE"
#include <dlog.h>
- #define DEVICE_LOG(fmt, args...) SLOGD(fmt, ##args)
- #define DEVICE_ERROR(fmt, args...) SLOGE(fmt, ##args)
+ #define _D(fmt, args...) SLOGD(fmt, ##args)
+ #define _I(fmt, args...) SLOGI(fmt, ##args)
+ #define _E(fmt, args...) SLOGE(fmt, ##args)
#else
- #define DEVICE_LOG(x, ...)
- #define DEVICE_ERROR(x, ...)
+ #define _D(x, ...)
+ #define _I(x, ...)
+ #define _E(x, ...)
#endif
-#endif /* __DEVICE_LOG_H__ */
+#ifndef __CONSTRUCTOR__
+#define __CONSTRUCTOR__ __attribute__ ((constructor))
+#endif
+
+#include "device-error.h"
+
+static inline int errno_to_device_error(int err)
+{
+ if (err == -ECOMM)
+ return DEVICE_ERROR_PERMISSION_DENIED;
+ else if (err == -ENODEV || err == -ENOENT)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+ else if (err < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ return DEVICE_ERROR_NONE;
+}
+
+#endif /* __COMMON_H__ */
#include <string.h>
#include <assert.h>
#include "device.h"
-#include "device_log.h"
+#include "common.h"
#define PROC_STAT "/proc/stat"
--- /dev/null
+/*
+ * system-dbus
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "common.h"
+#include "dbus.h"
+
+#define DBUS_REPLY_TIMEOUT (-1)
+
+struct pending_call_data {
+ dbus_pending_cb func;
+ void *data;
+};
+
+static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
+{
+ char *ch;
+ int i;
+ int int_type;
+ uint64_t int64_type;
+
+ if (!sig || !param)
+ return 0;
+
+ for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
+ switch (*ch) {
+ case 'i':
+ int_type = atoi(param[i]);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
+ break;
+ case 'u':
+ int_type = strtoul(param[i], NULL, 10);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
+ break;
+ case 't':
+ int64_type = atoll(param[i]);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
+ break;
+ case 's':
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]);
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+int dbus_method_sync(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[])
+{
+ DBusConnection *conn;
+ DBusMessage *msg;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ DBusError err;
+ int ret, result;
+
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ _E("dbus_bus_get error");
+ return -EPERM;
+ }
+
+ msg = dbus_message_new_method_call(dest, path, interface, method);
+ if (!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)",
+ path, interface, method);
+ return -EBADMSG;
+ }
+
+ dbus_message_iter_init_append(msg, &iter);
+ ret = append_variant(&iter, sig, param);
+ if (ret < 0) {
+ _E("append_variant error(%d) %s %s:%s-%s",
+ ret, dest, path, interface, method);
+ dbus_message_unref(msg);
+ return ret;
+ }
+
+ dbus_error_init(&err);
+
+ reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
+ dbus_message_unref(msg);
+ if (!reply) {
+ _E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
+ err.name, err.message, dest, path, interface, method);
+ dbus_error_free(&err);
+ return -ECOMM;
+ }
+
+ ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
+ dbus_message_unref(reply);
+ if (!ret) {
+ _E("no message : [%s:%s] %s %s:%s-%s",
+ err.name, err.message, dest, path, interface, method);
+ dbus_error_free(&err);
+ return -ENOMSG;
+ }
+
+ return result;
+}
+
+static void cb_pending(DBusPendingCall *pending, void *user_data)
+{
+ DBusMessage *msg;
+ DBusError err;
+ struct pending_call_data *data = user_data;
+ int ret;
+
+ ret = dbus_pending_call_get_completed(pending);
+ if (!ret) {
+ _I("dbus_pending_call_get_completed() fail");
+ dbus_pending_call_unref(pending);
+ return;
+ }
+
+ dbus_error_init(&err);
+ msg = dbus_pending_call_steal_reply(pending);
+ if (!msg) {
+ _E("no message : [%s:%s]", err.name, err.message);
+
+ if (data->func) {
+ dbus_set_error(&err, "org.tizen.system.deviced.NoReply",
+ "There was no reply to this method call");
+ data->func(data->data, NULL, &err);
+ dbus_error_free(&err);
+ }
+ return;
+ }
+
+ ret = dbus_set_error_from_message(&err, msg);
+ if (ret) {
+ _E("error msg : [%s:%s]", err.name, err.message);
+
+ if (data->func)
+ data->func(data->data, NULL, &err);
+ dbus_error_free(&err);
+ } else {
+ if (data->func)
+ data->func(data->data, msg, &err);
+ }
+
+ dbus_message_unref(msg);
+ dbus_pending_call_unref(pending);
+}
+
+int dbus_method_async_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data)
+{
+ DBusConnection *conn;
+ DBusMessage *msg;
+ DBusMessageIter iter;
+ DBusPendingCall *pending = NULL;
+ struct pending_call_data *pdata;
+ int ret;
+
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ _E("dbus_bus_get error");
+ return -EPERM;
+ }
+
+ /* this function should be invoked to receive dbus messages
+ * does nothing if it's already been done */
+ dbus_connection_setup_with_g_main(conn, NULL);
+
+ msg = dbus_message_new_method_call(dest, path, interface, method);
+ if (!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)",
+ path, interface, method);
+ return -EBADMSG;
+ }
+
+ dbus_message_iter_init_append(msg, &iter);
+ ret = append_variant(&iter, sig, param);
+ if (ret < 0) {
+ _E("append_variant error(%d)%s %s:%s-%s",
+ ret, dest, path, interface, method);
+ dbus_message_unref(msg);
+ return ret;
+ }
+
+ ret = dbus_connection_send_with_reply(conn, msg, &pending, timeout);
+ if (!ret) {
+ dbus_message_unref(msg);
+ _E("dbus_connection_send error(%s %s:%s-%s)",
+ dest, path, interface, method);
+ return -ECOMM;
+ }
+
+ dbus_message_unref(msg);
+
+ if (cb && pending) {
+ pdata = malloc(sizeof(struct pending_call_data));
+ if (!pdata)
+ return -ENOMEM;
+
+ pdata->func = cb;
+ pdata->data = data;
+
+ ret = dbus_pending_call_set_notify(pending, cb_pending, pdata, free);
+ if (!ret) {
+ free(pdata);
+ dbus_pending_call_cancel(pending);
+ return -ECOMM;
+ }
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * system-dbus
+ *
+ * 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.
+ */
+
+
+#ifndef __DBUS_H__
+#define __DBUS_H__
+
+#include <dbus/dbus.h>
+
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD"
+#define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME
+
+/* Display service: start/stop display(pm), get/set brightness operations about display */
+#define DEVICED_PATH_DISPLAY DEVICED_OBJECT_PATH"/Display"
+#define DEVICED_INTERFACE_DISPLAY DEVICED_INTERFACE_NAME".display"
+
+/* Battery service */
+#define DEVICED_PATH_BATTERY DEVICED_OBJECT_PATH"/Battery"
+#define DEVICED_INTERFACE_BATTERY DEVICED_INTERFACE_NAME".Battery"
+
+/* Haptic service: operatioins about haptic */
+#define DEVICED_PATH_HAPTIC DEVICED_OBJECT_PATH"/Haptic"
+#define DEVICED_INTERFACE_HAPTIC DEVICED_INTERFACE_NAME".haptic"
+
+/* Led service: play/stop led operations about led */
+#define DEVICED_PATH_LED DEVICED_OBJECT_PATH"/Led"
+#define DEVICED_INTERFACE_LED DEVICED_INTERFACE_NAME".Led"
+
+int dbus_method_sync(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[]);
+
+typedef void (*dbus_pending_cb)(void *data, DBusMessage *msg, DBusError *err);
+
+int dbus_method_async_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data);
+
+#endif
/*
- * capi-system-device
- * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * 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
+ * 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,
#include <stdio.h>
-#include <devman.h>
+#include <string.h>
+#include <errno.h>
+#include <dd-display.h>
+#include <dd-battery.h>
+#include <vconf.h>
+
#include "device.h"
-#include "device_log.h"
+#include "common.h"
#define CHECK_ERR(val) \
do { \
- if (val == DEVMAN_ERROR_NOT_SUPPORTED) \
- return DEVICE_ERROR_NOT_SUPPORTED; \
- else if (val == DEVMAN_ERROR_OPERATION_FAILED) \
+ if (val < 0) { \
+ if (errno == ENODEV) \
+ return DEVICE_ERROR_NOT_SUPPORTED; \
return DEVICE_ERROR_OPERATION_FAILED; \
+ } \
} while(0)
-static int _display[] = {
- DEV_DISPLAY_0,
- DEV_DISPLAY_1,
-};
-
int device_get_display_numbers(int* device_number)
{
if(device_number == NULL)
return DEVICE_ERROR_INVALID_PARAMETER;
- *device_number = device_get_display_count();
+ *device_number = display_get_count();
CHECK_ERR(*device_number);
return DEVICE_ERROR_NONE;
int device_get_brightness(int disp_idx, int* value)
{
- int val, disp, max_id, ret;
+ int val, max_id, ret;
if(value == NULL)
return DEVICE_ERROR_INVALID_PARAMETER;
if(disp_idx < 0 || disp_idx >= max_id)
return DEVICE_ERROR_INVALID_PARAMETER;
- disp = _display[disp_idx];
- val = device_get_display_brt(disp);
+ val = display_get_brightness();
CHECK_ERR(val);
*value = val;
int device_set_brightness(int disp_idx, int new_value)
{
- int max_value, val;
- int disp, max_id, ret;
+ int max_value, val, max_id, ret;
if(new_value < 0)
return DEVICE_ERROR_INVALID_PARAMETER;
if(disp_idx < 0 || disp_idx >= max_id)
return DEVICE_ERROR_INVALID_PARAMETER;
- disp = _display[disp_idx];
- ret = device_get_max_brightness(disp, &max_value);
+ ret = device_get_max_brightness(disp_idx, &max_value);
if (ret != DEVICE_ERROR_NONE)
return ret;
if(new_value > max_value)
return DEVICE_ERROR_INVALID_PARAMETER;
- val = device_set_display_brt(disp, new_value);
+ val = display_set_brightness(new_value);
CHECK_ERR(val);
return DEVICE_ERROR_NONE;
int device_get_max_brightness(int disp_idx, int* max_value)
{
- int val, disp, max_id, ret;
+ int val, max_id, ret;
if(max_value == NULL)
return DEVICE_ERROR_INVALID_PARAMETER;
ret = device_get_display_numbers(&max_id);
+ _E("max id : %d", max_id);
if (ret != DEVICE_ERROR_NONE)
return ret;
if(disp_idx < 0 || disp_idx >= max_id)
return DEVICE_ERROR_INVALID_PARAMETER;
-
- disp = _display[disp_idx];
- val = device_get_max_brt(disp);
+
+ val = display_get_max_brightness();
CHECK_ERR(val);
*max_value = val;
int device_set_brightness_from_settings(int disp_idx)
{
- int max_id, disp, val, ret;
+ int max_id, val, ret;
ret = device_get_display_numbers(&max_id);
if (ret != DEVICE_ERROR_NONE)
if(disp_idx < 0 || disp_idx >= max_id)
return DEVICE_ERROR_INVALID_PARAMETER;
- disp = _display[disp_idx];
- val = device_release_brt_ctrl(disp);
+ val = display_release_brightness();
CHECK_ERR(val);
return DEVICE_ERROR_NONE;
int device_set_brightness_to_settings(int disp_idx, int new_value)
{
- int max_value, val;
- int disp, max_id, ret;
+ int max_value, val, max_id, ret;
if(new_value < 0)
return DEVICE_ERROR_INVALID_PARAMETER;
if(disp_idx < 0 || disp_idx >= max_id)
return DEVICE_ERROR_INVALID_PARAMETER;
- disp = _display[disp_idx];
- ret = device_get_max_brightness(disp, &max_value);
+ ret = device_get_max_brightness(disp_idx, &max_value);
if (ret != DEVICE_ERROR_NONE)
return ret;
if(new_value > max_value)
return DEVICE_ERROR_INVALID_PARAMETER;
- val = device_set_display_brt_with_settings(disp, new_value);
+ val = display_set_brightness_with_setting(new_value);
CHECK_ERR(val);
return DEVICE_ERROR_NONE;
}
-int device_flash_get_brightness(int *brightness)
+int device_battery_get_detail(int *percent)
{
- int value;
+ _E("Deprecated api. Use device_battery_get_percent()");
+ return DEVICE_ERROR_NOT_SUPPORTED;
+}
- if (brightness == NULL)
+int device_battery_is_full(bool* full)
+{
+ if (full == NULL)
return DEVICE_ERROR_INVALID_PARAMETER;
- value = device_get_led_brt();
- CHECK_ERR(value);
+ int f = battery_is_full();
+ CHECK_ERR(f);
- *brightness = value;
+ *full = (f == 1) ? true : false;
return DEVICE_ERROR_NONE;
}
-int device_flash_set_brightness(int brightness)
+int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int *time)
{
- int max_value, value, ret;
+ _E("Deprecated api.");
+ return DEVICE_ERROR_NOT_SUPPORTED;
+}
- ret = device_flash_get_max_brightness(&max_value);
- if (ret != DEVICE_ERROR_NONE)
- return ret;
+int device_battery_set_remaining_time_changed_cb(device_battery_remaining_time_type_e type,
+ device_battery_remaining_time_changed_cb callback, void* user_data)
+{
+ _E("Deprecated api.");
+ return DEVICE_ERROR_NOT_SUPPORTED;
+}
- if (brightness < 0 || brightness > max_value)
+int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type)
+{
+ _E("Deprecated api.");
+ return DEVICE_ERROR_NOT_SUPPORTED;
+}
+
+static device_battery_cb changed_callback = NULL;
+static void* changed_callback_user_data = NULL;
+
+static void battery_changed_inside_cb(keynode_t* key, void* user_data)
+{
+ const char* keyname = vconf_keynode_get_name(key);
+
+ if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) {
+ int percent = 0;
+ if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) {
+ changed_callback(percent, changed_callback_user_data);
+ }
+ }
+}
+
+int device_battery_set_cb(device_battery_cb callback, void* user_data)
+{
+ // VCONFKEY_SYSMAN_BATTERY_CAPACITY
+ int err;
+ if (callback == NULL)
return DEVICE_ERROR_INVALID_PARAMETER;
- value = device_set_led_brt(brightness);
- CHECK_ERR(value);
+ changed_callback = callback;
+ changed_callback_user_data = user_data;
+
+ err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL);
+ if (err < 0)
+ return DEVICE_ERROR_INVALID_PARAMETER;
return DEVICE_ERROR_NONE;
}
-int device_flash_get_max_brightness(int *max_brightness)
+int device_battery_unset_cb(void)
{
- int value;
+ int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb);
+ if (err < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ changed_callback = NULL;
+ changed_callback_user_data = NULL;
- if (max_brightness == NULL)
+ return DEVICE_ERROR_NONE;
+}
+
+int device_battery_get_warning_status(device_battery_warn_e *status)
+{
+ if (status == NULL)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ int value, err;
+
+ err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value);
+ if (err < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) {
+ *status = DEVICE_BATTERY_WARN_EMPTY;
+ } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
+ *status = DEVICE_BATTERY_WARN_CRITICAL;
+ } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
+ *status = DEVICE_BATTERY_WARN_LOW;
+ } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) {
+ *status = DEVICE_BATTERY_WARN_NORMAL;
+ } else if (value == VCONFKEY_SYSMAN_BAT_FULL) {
+ *status = DEVICE_BATTERY_WARN_FULL;
+ } else {
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ return DEVICE_ERROR_NONE;
+}
+
+static device_battery_warn_cb warn_changed_callback = NULL;
+static void* warn_changed_callback_user_data = NULL;
+
+static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data)
+{
+ const char* keyname = vconf_keynode_get_name(key);
+
+ if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) {
+ int bat_state = 0;
+ if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) {
+ warn_changed_callback(bat_state-1, warn_changed_callback_user_data);
+ }
+ }
+}
+
+int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data)
+{
+ // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW
+ int err;
+
+ if (callback == NULL)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ warn_changed_callback = callback;
+ warn_changed_callback_user_data = user_data;
+
+ err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL);
+ if (err < 0)
return DEVICE_ERROR_INVALID_PARAMETER;
- value = device_get_max_led();
- CHECK_ERR(value);
+ return DEVICE_ERROR_NONE;
+}
+
+int device_battery_warning_unset_cb(void)
+{
+ int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb);
+ if (err < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ warn_changed_callback = NULL;
+ warn_changed_callback_user_data = NULL;
- *max_brightness = value;
return DEVICE_ERROR_NONE;
}
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <vconf.h>
+
+#include "display.h"
+#include "common.h"
+#include "dbus.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 STR_LCD_OFF "lcdoff"
+#define STR_LCD_DIM "lcddim"
+#define STR_LCD_ON "lcdon"
+
+static int display_cnt = -1;
+struct display {
+ int 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].max = -1;
+
+ return 0;
+}
+
+int device_display_get_numbers(int *device_number)
+{
+ int ret;
+
+ if (!device_number)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* if it is a first request */
+ if (display_cnt < 0) {
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_GET_DISPLAY_COUNT, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+ 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;
+
+ if (!max_brightness)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (display_cnt < 0)
+ device_display_get_numbers(&display_cnt);
+
+ 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].max < 0) {
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+ display_arr[display_index].max = ret;
+ }
+
+ *max_brightness = display_arr[display_index].max;
+ return DEVICE_ERROR_NONE;
+}
+
+int device_display_get_brightness(int display_index, int *brightness)
+{
+ int ret;
+
+ if (!brightness)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (display_cnt < 0)
+ device_display_get_numbers(&display_cnt);
+
+ if (display_index < 0 || display_index >= display_cnt)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_GET_BRIGHTNESS, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ *brightness = ret;
+ return DEVICE_ERROR_NONE;
+}
+
+int device_display_set_brightness(int display_index, int brightness)
+{
+ char *arr[1];
+ char str_val[32];
+ int ret, max;
+
+ if (display_cnt < 0)
+ device_display_get_numbers(&display_cnt);
+
+ if (display_index < 0 || display_index >= display_cnt)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (display_arr[display_index].max < 0)
+ device_display_get_max_brightness(display_index, &max);
+
+ if (brightness < 0 || brightness > display_arr[display_index].max)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ snprintf(str_val, sizeof(str_val), "%d", brightness);
+ arr[0] = str_val;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_SET_BRIGHTNESS, "i", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_display_get_state(display_state_e *state)
+{
+ int ret, val;
+
+ 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)
+ *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;
+}
+
+int device_display_change_state(display_state_e state)
+{
+ char *str, *arr[1];
+ int ret;
+
+ if (state < DISPLAY_STATE_NORMAL || state > DISPLAY_STATE_SCREEN_OFF)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ str = get_state_str(state);
+ if (!str)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ arr[0] = str;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_CHANGE_STATE, "s", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <errno.h>
+
+#include "haptic.h"
+#include "common.h"
+#include "dbus.h"
+
+#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"
+
+enum feedback_e
+{
+ HAPTIC_FEEDBACK_MIN = 0,
+ HAPTIC_FEEDBACK_MAX = 100,
+};
+
+enum priority_e
+{
+ HAPTIC_PRIORITY_MIN = 0,
+ HAPTIC_PRIORITY_MIDDLE,
+ HAPTIC_PRIORITY_HIGH,
+};
+
+int device_haptic_get_count(int *device_number)
+{
+ int ret;
+
+ if (!device_number)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* request to deviced to get haptic count */
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+ METHOD_GET_COUNT, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ *device_number = ret;
+ return DEVICE_ERROR_NONE;
+}
+
+int device_haptic_open(int device_index, haptic_device_h *device_handle)
+{
+ char str_index[32];
+ char *arr[1];
+ int ret, max;
+
+ 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;
+
+ snprintf(str_index, sizeof(str_index), "%d", device_index);
+ arr[0] = str_index;
+
+ /* request to deviced to open haptic device */
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+ METHOD_OPEN_DEVICE, "i", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ *device_handle = (haptic_device_h)ret;
+ return DEVICE_ERROR_NONE;
+}
+
+int device_haptic_close(haptic_device_h device_handle)
+{
+ char str_handle[32];
+ char *arr[1];
+ int ret;
+
+ if (!device_handle)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
+ arr[0] = str_handle;
+
+ /* request to deviced to open haptic device */
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+ METHOD_CLOSE_DEVICE, "u", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle)
+{
+ char str_handle[32];
+ char str_duration[32];
+ char str_feedback[32];
+ char str_priority[32];
+ char *arr[4];
+ int ret, priority;
+
+ 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;
+
+ priority = HAPTIC_PRIORITY_MIN;
+
+ snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
+ arr[0] = str_handle;
+ snprintf(str_duration, sizeof(str_duration), "%d", duration);
+ arr[1] = str_duration;
+ snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
+ arr[2] = str_feedback;
+ snprintf(str_priority, sizeof(str_priority), "%d", priority);
+ arr[3] = str_priority;
+
+ /* request to deviced to vibrate haptic device */
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+ METHOD_VIBRATE_MONOTONE, "uiii", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ 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)
+{
+ char str_handle[32];
+ char *arr[1];
+ int ret;
+
+ if (!device_handle)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* TODO : support to stop haptic effect */
+ snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
+ arr[0] = str_handle;
+
+ /* request to deviced to open haptic device */
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
+ METHOD_STOP_DEVICE, "u", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <system_info.h>
+
+#include "led.h"
+#include "common.h"
+#include "dbus.h"
+
+#define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness"
+#define METHOD_GET_BRIGHTNESS "GetBrightness"
+#define METHOD_SET_BRIGHTNESS "SetBrightness"
+#define METHOD_PLAY_CUSTOM "playcustom"
+#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 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_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ *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_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_GET_BRIGHTNESS, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ *brightness = ret;
+ return DEVICE_ERROR_NONE;
+}
+
+int device_flash_set_brightness(int brightness)
+{
+ char *arr[2];
+ char buf_val[32];
+ char buf_noti[32];
+ 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;
+
+ snprintf(buf_val, sizeof(buf_val), "%d", brightness);
+ arr[0] = buf_val;
+ snprintf(buf_noti, sizeof(buf_noti), "%d", 0);
+ arr[1] = buf_noti;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_SET_BRIGHTNESS, "ii", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags)
+{
+ char *arr[4];
+ char str_on[32], str_off[32];
+ char str_color[32], str_flags[32];
+ int ret;
+
+ if (!support_front_led)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
+ if (on < 0 || off < 0)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ snprintf(str_on, sizeof(str_on), "%d", on);
+ arr[0] = str_on;
+ snprintf(str_off, sizeof(str_off), "%d", off);
+ arr[1] = str_off;
+ snprintf(str_color, sizeof(str_color), "%lu", (long unsigned int)color);
+ arr[2] = str_color;
+ snprintf(str_flags, sizeof(str_flags), "%lu", (long unsigned int)flags);
+ arr[3] = str_flags;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_PLAY_CUSTOM, "iiuu", arr);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_led_stop_custom(void)
+{
+ int ret;
+
+ if (!support_front_led)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
+ ret = dbus_method_sync(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_STOP_CUSTOM, NULL, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret);
+
+ return DEVICE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * 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 <stdio.h>
+
+#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 <Ecore.h>
+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 <glib.h>
+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
#include <string.h>
#include <assert.h>
#include "device.h"
-#include "device_log.h"
+#include "common.h"
#define PROC_MEMORY "/proc/meminfo"
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include "power.h"
+#include "display.h"
+#include "common.h"
+#include "dbus.h"
+
+/**
+ * Parameters for device_power_request_lock()
+ */
+#define STAY_CUR_STATE 0x1
+#define GOTO_STATE_NOW 0x2
+#define HOLD_KEY_BLOCK 0x4
+#define STANDBY_MODE 0x8
+
+/**
+ * Parameters for device_power_request_unlock()
+ */
+#define PM_SLEEP_MARGIN 0x0 /**< keep guard time for unlock */
+#define PM_RESET_TIMER 0x1 /**< reset timer for unlock */
+#define PM_KEEP_TIMER 0x2 /**< keep timer for unlock */
+
+#define METHOD_LOCK_STATE "lockstate"
+#define METHOD_UNLOCK_STATE "unlockstate"
+#define METHOD_CHANGE_STATE "changestate"
+
+#define STR_STAYCURSTATE "staycurstate"
+#define STR_GOTOSTATENOW "gotostatenow"
+
+#define STR_HOLDKEYBLOCK "holdkeyblock"
+#define STR_STANDBYMODE "standbymode"
+#define STR_NULL "NULL"
+
+#define STR_SLEEP_MARGIN "sleepmargin"
+#define STR_RESET_TIMER "resettimer"
+#define STR_KEEP_TIMER "keeptimer"
+
+#define STR_LCD_OFF "lcdoff"
+#define STR_LCD_DIM "lcddim"
+#define STR_LCD_ON "lcdon"
+
+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 lock_cb(void *data, DBusMessage *msg, DBusError *unused)
+{
+ DBusError err;
+ int ret, val;
+
+ if (!msg)
+ return;
+
+ dbus_error_init(&err);
+ ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
+ if (!ret) {
+ _E("no message [%s:%s]", err.name, err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_LOCK_STATE, val);
+}
+
+static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
+{
+ char *arr[4];
+ char str_timeout[32];
+
+ arr[0] = get_state_str(state);
+ if (!arr[0])
+ return -EINVAL;
+
+ if (flag & GOTO_STATE_NOW)
+ arr[1] = STR_GOTOSTATENOW;
+ else
+ arr[1] = STR_STAYCURSTATE;
+
+ if (flag & HOLD_KEY_BLOCK)
+ arr[2] = STR_HOLDKEYBLOCK;
+ else if (flag & STANDBY_MODE)
+ arr[2] = STR_STANDBYMODE;
+ else
+ arr[2] = STR_NULL;
+
+ snprintf(str_timeout, sizeof(str_timeout), "%d", timeout_ms);
+ arr[3] = str_timeout;
+
+ return dbus_method_async_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_LOCK_STATE, "sssi", arr, lock_cb, -1, NULL);
+}
+
+static void unlock_cb(void *data, DBusMessage *msg, DBusError *unused)
+{
+ DBusError err;
+ int ret, val;
+
+ if (!msg)
+ return;
+
+ dbus_error_init(&err);
+ ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
+ if (!ret) {
+ _E("no message [%s:%s]", err.name, err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_UNLOCK_STATE, val);
+}
+
+static int unlock_state(display_state_e state, unsigned int flag)
+{
+ char *arr[2];
+
+ arr[0] = get_state_str(state);
+ if (!arr[0])
+ return -EINVAL;
+
+ if (flag == PM_SLEEP_MARGIN)
+ arr[1] = STR_SLEEP_MARGIN;
+ else if (flag == PM_RESET_TIMER)
+ arr[1] = STR_RESET_TIMER;
+ else if (flag == PM_KEEP_TIMER)
+ arr[1] = STR_KEEP_TIMER;
+ else
+ return -EINVAL;
+
+ return dbus_method_async_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
+ METHOD_UNLOCK_STATE, "ss", arr, unlock_cb, -1, NULL);
+}
+
+int device_power_request_lock(power_lock_e type, int timeout_ms)
+{
+ int ret;
+
+ if (timeout_ms < 0)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (type == POWER_LOCK_CPU)
+ ret = lock_state(DISPLAY_STATE_SCREEN_OFF, STAY_CUR_STATE, timeout_ms);
+ else if (type == POWER_LOCK_DISPLAY)
+ ret = lock_state(DISPLAY_STATE_NORMAL, STAY_CUR_STATE, timeout_ms);
+ else if (type == POWER_LOCK_DISPLAY_DIM)
+ ret = lock_state(DISPLAY_STATE_SCREEN_DIM, STAY_CUR_STATE, timeout_ms);
+ else
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (ret == -ECOMM)
+ return DEVICE_ERROR_PERMISSION_DENIED;
+ else if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_power_release_lock(power_lock_e type)
+{
+ int ret;
+
+ if (type == POWER_LOCK_CPU)
+ ret = unlock_state(DISPLAY_STATE_SCREEN_OFF, PM_SLEEP_MARGIN);
+ else if (type == POWER_LOCK_DISPLAY)
+ ret = unlock_state(DISPLAY_STATE_NORMAL, PM_KEEP_TIMER);
+ else if (type == POWER_LOCK_DISPLAY_DIM)
+ ret = unlock_state(DISPLAY_STATE_SCREEN_DIM, PM_KEEP_TIMER);
+ else
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (ret == -ECOMM)
+ return DEVICE_ERROR_PERMISSION_DENIED;
+ else if (ret < 0)
+ return DEVICE_ERROR_OPERATION_FAILED;
+
+ return DEVICE_ERROR_NONE;
+}
+
+int device_power_wakeup(bool dim)
+{
+ if (dim)
+ return device_display_change_state(DISPLAY_STATE_SCREEN_DIM);
+
+ return device_display_change_state(DISPLAY_STATE_NORMAL);
+}