Fix build error : Add mmutil-imgp
[platform/core/messaging/msg-service.git] / msg_helper / MsgSensorWrapper.cpp
1 /*
2  * msg-service
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18 */
19
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgHelper.h"
24
25 #include <sensor.h>
26
27 /*==================================================================================================
28                                      VARIABLES
29 ==================================================================================================*/
30 int sensorHandler = -1;
31
32 msg_sensor_cb cbFunction = NULL;
33
34 /*==================================================================================================
35                                      FUNCTION IMPLEMENTATION
36 ==================================================================================================*/
37
38 void MsgSensorCB(unsigned int event_type, sensor_event_data_t *event_data , void *data)
39 {
40         int *my_event_data;
41
42         my_event_data = (int *)(event_data->event_data);
43
44         if (event_type == MOTION_ENGINE_EVENT_TOP_TO_BOTTOM)
45                 if(*my_event_data == MOTION_ENGIEN_TOP_TO_BOTTOM_DETECTION) {
46                         MSG_DEBUG("top to bottom event detected.");
47                         if(MsgSettingGetInt(VCONFKEY_SETAPPL_MOTION_ACTIVATION))
48                                 if(MsgSettingGetInt(VCONFKEY_SETAPPL_USE_TURN_OVER))
49                                         cbFunction();
50                 }
51 }
52
53
54 msg_error_t MsgSensorConnect()
55 {
56         sensorHandler = sf_connect(MOTION_SENSOR);
57         if (sensorHandler < 0) {
58                 MSG_DEBUG("sensor attach fail.");
59                 return MSG_ERR_UNKNOWN;
60         }
61
62         return MSG_SUCCESS;
63 }
64
65
66 void MsgSensorDisconnect()
67 {
68         if(cbFunction != NULL)
69                 cbFunction = NULL;
70
71         if (sensorHandler < 0)
72                 return;
73
74         try
75         {
76                 sf_stop(sensorHandler);
77         }
78         catch(int exception)
79         {
80                 MSG_FATAL("sf_stop error[%d]", exception);
81         }
82         sf_disconnect(sensorHandler);
83 }
84
85
86 msg_error_t MsgRegSensorCB(msg_sensor_cb cb)
87 {
88         int resultCondition = -1;
89
90         if (sensorHandler < 0) {
91                 MSG_DEBUG("Not connected to sensor FW.");
92                 return MSG_ERR_UNKNOWN;
93         }
94
95         if(cb != NULL) {
96                 // regist cb.
97                 cbFunction = cb;
98         } else {
99                 MSG_DEBUG("cb is NULL.");
100                 return MSG_ERR_UNKNOWN;
101         }
102
103         resultCondition = sf_register_event(sensorHandler, MOTION_ENGINE_EVENT_TOP_TO_BOTTOM , NULL , MsgSensorCB,NULL);
104         if (resultCondition < 0) {
105                 MSG_DEBUG("SLP_sensor_register_cb fail to gather data.");
106                 return MSG_ERR_UNKNOWN;
107         }
108
109         MSG_DEBUG("Start SF.");
110         resultCondition = sf_start(sensorHandler, 0);
111         if (resultCondition < 0) {
112                 MSG_DEBUG("SLP_sensor_start fail.");
113                 return MSG_ERR_UNKNOWN;
114         }
115
116         return MSG_SUCCESS;
117 }