Add device_thermal_get_temperature for public API 53/196353/17 accepted/tizen/unified/20190219.154146 accepted/tizen/unified/20190221.165802 submit/tizen/20190218.105211 submit/tizen/20190220.073046
authorlokilee73 <changjoo.lee@samsung.com>
Thu, 27 Dec 2018 11:35:51 +0000 (20:35 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Mon, 18 Feb 2019 10:24:32 +0000 (19:24 +0900)
Change-Id: I20855ea5557aef442db52076bcff3c78143bd30e
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
doc/device_doc.h
include/temperature.h [new file with mode: 0644]
src/dbus.h
src/temperature.c [new file with mode: 0644]

index 187b051..e18706d 100644 (file)
@@ -29,8 +29,9 @@
  *   \#include <device/display.h> \n
  *   \#include <device/haptic.h> \n
  *   \#include <device/led.h> \n
- *   \#include <device/power.h>
- *   \#include <device/ir.h>
+ *   \#include <device/power.h> \n
+ *   \#include <device/ir.h> \n
+ *   \#include <device/temperature.h> \n
  *
  * @section CAPI_SYSTEM_DEVICE_MODULE_OVERVIEW Overview
  * The DEVICE API provides functions to control devices or to get status of devices.
@@ -42,6 +43,7 @@
  * - LED
  * - Power
  * - IR
+ * - Temperature
  */
 
 /**
  *
  */
 
+/**
+ * @ingroup CAPI_SYSTEM_DEVICE_MODULE
+ * @defgroup CAPI_SYSTEM_DEVICE_THERMAL_MODULE Thermal
+ * @brief The Temperature API provides functions to get information about the temperature.
+ *
+ * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_HEADER Required Header
+ *   \#include <device/temperature.h> \n
+ *
+ * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_OVERVIEW Overview
+ * The Temperature API provides the way to get the current thermal value such as Application Processor, Communication Processor and Battery.
+ *
+ * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_OVERVIEW Related Features
+ * This API is related with the following features:\n
+ * - %http://tizen.org/feature/thermistor.ap\n
+ * - %http://tizen.org/feature/thermistor.cp\n
+ * - %http://tizen.org/feature/thermistor.battery\n
+ *
+ * It is recommended to use features in your application for reliability.\n
+ *
+ * You can check if the device supports the related features for this API by using System Information, and control your application's actions accordingly.\n
+ *
+ * To ensure your application is running only on devices with specific features, please define the features in your manifest file using the manifest editor in the SDK.
+ *
+ * More details on using features in your application can be found in the <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>feature element description</b></a>.
+ *
+ *
+ */
+
 #endif /* __TIZEN_SYSTEM_DEVICE_DOC_H__ */
diff --git a/include/temperature.h b/include/temperature.h
new file mode 100644 (file)
index 0000000..38da4e1
--- /dev/null
@@ -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 <stdbool.h>
+#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__ */
index c502284..2ae4d77 100644 (file)
 #define DEVICED_PATH_IR                  DEVICED_OBJECT_PATH"/Ir"
 #define DEVICED_INTERFACE_IR             DEVICED_INTERFACE_NAME".ir"
 
+/* Thermal service: operatioins about temperature */
+#define DEVICED_PATH_TEMPERATURE                  DEVICED_OBJECT_PATH"/Temperature"
+#define DEVICED_INTERFACE_TEMPERATURE             DEVICED_INTERFACE_NAME".temperature"
+
 struct dbus_int {
        int *list;
        int size;
diff --git a/src/temperature.c b/src/temperature.c
new file mode 100644 (file)
index 0000000..12f5c5b
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <glib.h>
+#include <system_info.h>
+#include "common.h"
+#include "dbus.h"
+#include "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) {
+               _E("Failed to get value of temp feature : %d", ret);
+               return false;
+       } else if (ret == 0 && !thermal_avail) {
+               _D("Temperature is not supported");
+               return false;
+       } else
+               return true;
+}
+
+int device_thermal_get_temperature(device_thermal_e type, int *temp)
+{
+       char *arr[1];
+       char str_val[32];
+       int ret;
+
+       if (type > DEVICE_THERMAL_BATTERY)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       ret = is_temperature_supported(type);
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
+       snprintf(str_val, sizeof(str_val), "%d", type);
+       arr[0] = str_val;
+
+       ret = dbus_method_sync(DEVICED_BUS_NAME,
+                       DEVICED_PATH_TEMPERATURE,
+                       DEVICED_INTERFACE_TEMPERATURE,
+                       METHOD_GET_TEMPERATURE, "i", arr);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       *temp = ret;
+       return DEVICE_ERROR_NONE;
+}
+