Added WiFi plugin callback handler
authorAtul Rai <a.rai@samsung.com>
Wed, 9 Jan 2019 07:55:30 +0000 (13:25 +0530)
committer김새롬/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <saerome.kim@samsung.com>
Wed, 9 Jan 2019 13:36:49 +0000 (22:36 +0900)
Signed-off-by: Atul Rai <a.rai@samsung.com>
ua-daemon/CMakeLists.txt
ua-daemon/src/pm/ua-plugin-manager.c
ua-daemon/src/pm/ua-wifi-plugin-handler.c [new file with mode: 0644]

index de24426..9dacd4d 100644 (file)
@@ -16,6 +16,7 @@ SET(SRCS
        src/pm/ua-power-plugin-manager.c
        src/pm/ua-pm-util.c
        src/pm/ua-ble-plugin-handler.c
+       src/pm/ua-wifi-plugin-handler.c
        src/pm/ua-light-plugin-handler.c
        src/pm/ua-motion-plugin-handler.c
        src/pm/ua-power-plugin-handler.c
index c7420aa..e6a81d3 100644 (file)
@@ -31,6 +31,7 @@
 static unsigned int available_sensors = 0;
 
 extern const uas_callbacks_t ble_cbs;
+extern const uas_callbacks_t wifi_cbs;
 extern const uas_callbacks_t light_cbs;
 extern const uas_callbacks_t motion_cbs;
 
@@ -197,6 +198,21 @@ static int __init_sensor_plugins(void)
 
                        available_sensors |= UAM_SENSOR_BITMASK_BLE;
                        break;
+               case UAS_PLUGIN_ID_WIFI:
+                       status = plugin->api->init(&wifi_cbs);
+                       if (UAS_STATUS_SUCCESS != status) {
+                               /* Deinit plugin */
+                               continue;
+                       }
+
+                       plugin->capability = UAS_NOT_SUPPORT_USER;
+                       if (UAS_STATUS_SUCCESS != plugin->api->get_capability(
+                                               &plugin->capability))
+                               plugin->capability = UAS_NOT_SUPPORT_USER;
+
+                       available_sensors |= UAM_SENSOR_BITMASK_WIFI;
+                       break;
+
                case UAS_PLUGIN_ID_LIGHT:
                        status = plugin->api->init(&light_cbs);
                        if (UAS_STATUS_SUCCESS != status) {
diff --git a/ua-daemon/src/pm/ua-wifi-plugin-handler.c b/ua-daemon/src/pm/ua-wifi-plugin-handler.c
new file mode 100644 (file)
index 0000000..14f83e8
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * User Awareness WIFI plugin callback handler
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ua-plugin.h>
+#include <ua-manager-core.h>
+#include <ua-plugin-manager.h>
+
+#include "ua-pm-util.h"
+
+static void wifi_state_changed_callback(int state)
+{
+       FUNC_ENTRY;
+       gboolean is_ready = FALSE;
+
+       if (UAS_STATE_READY == state)
+               is_ready = TRUE;
+
+       _uam_core_handle_sensor_ready(UAM_SENSOR_BITMASK_WIFI, is_ready);
+
+       FUNC_EXIT;
+}
+
+static void wifi_lpm_detection_callback(uas_detection_type_e type)
+{
+       FUNC_ENTRY;
+
+       /* Currently, in lpm mode only Presence is detected */
+       if (UAS_PRESENCE == type) {
+               UAM_DBG("Presence detected");
+               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_WIFI, -1, NULL);
+       } else {
+               UAM_WARN("Unlikely Absence detected");
+       }
+
+       FUNC_EXIT;
+}
+
+static void wifi_device_detection_callback(uas_detection_type_e type, uas_device_info_t *device)
+{
+       FUNC_ENTRY;
+       uam_device_info_t *dev_info;
+
+       ret_if(NULL == device);
+
+       dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device);
+       ret_if(NULL == dev_info);
+
+       if (UAS_PRESENCE == type) {
+               UAM_DBG("Presence detected for %s", dev_info->device_id);
+               _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_WIFI, device->user_id, dev_info);
+       } else {
+               UAM_DBG("Absence detected for %s", dev_info->device_id);
+               _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_WIFI, device->user_id, dev_info);
+       }
+
+       g_free(dev_info);
+       FUNC_EXIT;
+}
+
+static void wifi_device_added_callback(int status, uas_device_info_t *device)
+{
+       FUNC_ENTRY;
+       uam_device_info_t *dev_info;
+
+       ret_if(NULL == device);
+
+       dev_info = _pm_util_uas_dev_info_to_uam_dev_info(device);
+       ret_if(NULL == dev_info);
+
+       dev_info->type = UAM_TECH_TYPE_WIFI;
+       UAM_INFO("Status: %s", _pm_util_uas_status_to_str(status));
+       if (UAS_STATUS_SUCCESS != status)
+               status = UAM_ERROR_INTERNAL;
+       else
+               status = UAM_ERROR_NONE;
+
+       _uam_core_handle_device_added(status, device->user_id, dev_info);
+       g_free(dev_info);
+       FUNC_EXIT;
+}
+
+uas_callbacks_t wifi_cbs = {
+       .state_changed_cb = wifi_state_changed_callback,
+       .detected_cb = wifi_lpm_detection_callback,
+       .device_detected_cb = wifi_device_detection_callback,
+       .device_added_cb = wifi_device_added_callback
+};