Fix the problem that the Sensor Frameowk and UAF use different data
[platform/core/connectivity/ua-manager.git] / ua-daemon / src / pm / ua-motion-plugin-handler.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <ua-plugin.h>
22 #include <ua-plugin-manager.h>
23 #include "ua-pm-util.h"
24
25 void motion_state_changed_callback(int state)
26 {
27         FUNC_ENTRY;
28
29         UAM_DBG("Motion: %s", state == UAS_STATE_READY ? "READY" : "NOT_READY");
30
31         FUNC_EXIT;
32 }
33
34 static void motion_detection_state_changed_cb(int state)
35 {
36         FUNC_ENTRY;
37
38         if (state)
39                 _uam_core_handle_detection_started(UAM_SENSOR_BITMASK_MOTION);
40         else
41                 _uam_core_handle_detection_stopped(UAM_SENSOR_BITMASK_MOTION);
42
43         FUNC_EXIT;
44 }
45
46
47 static void motion_detection_status_changed_cb(uas_detection_type_e type,
48         void *sensor_info)
49 {
50         FUNC_ENTRY;
51
52         uas_sensor_info_t *info = NULL;
53         uam_sensor_info_s *motion_info = NULL;
54
55         UAM_DBG("Motion: %s", type == UAS_PRESENCE ? "PRESENCE" : "ABSENCE");
56
57         if (sensor_info)
58                 info = sensor_info;
59         motion_info = _pm_util_uas_sensor_info_to_uam_sensor_info(info);
60
61         _uam_core_handle_status_changed(UAM_SENSOR_BITMASK_MOTION, type, motion_info);
62
63         g_free(motion_info);
64
65         FUNC_EXIT;
66 }
67
68 void motion_detection_callback(uas_detection_type_e type, void *sensor_info)
69 {
70         FUNC_ENTRY;
71         uas_sensor_info_t *info = NULL;
72         uam_sensor_info_s *motion_info = NULL;
73
74         UAM_DBG("Motion: %s", type == UAS_PRESENCE ? "PRESENCE" : "ABSENCE");
75
76         if (sensor_info)
77                 info = sensor_info;
78         motion_info = _pm_util_uas_sensor_info_to_uam_sensor_info(info);
79
80         if (UAS_PRESENCE == type) {
81                 UAM_DBG("Presence detected by motion sensor");
82                 _uam_core_handle_presence_detected(UAM_SENSOR_BITMASK_MOTION, 0, motion_info);
83         } else {
84                 UAM_DBG("Absence detected by motion sensor");
85                 _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_MOTION, 0, motion_info);
86         }
87
88         g_free(motion_info);
89
90         FUNC_EXIT;
91 }
92
93 uas_callbacks_t motion_cbs = {
94         .state_changed_cb = motion_state_changed_callback,
95         .detection_state_cb = motion_detection_state_changed_cb,
96         .detection_status_cb = motion_detection_status_changed_cb,
97         .detected_cb = motion_detection_callback,
98         .device_detected_cb = NULL,
99         .device_added_cb = NULL,
100         .active_scan_cb = NULL,
101 };