sensor: check if the event value is NaN
[platform/core/system/sensord.git] / src / shared / channel_event_handler.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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 "channel_event_handler.h"
21
22 #include "channel.h"
23 #include "channel_handler.h"
24 #include "sensor_log.h"
25
26 using namespace ipc;
27
28 channel_event_handler::channel_event_handler(channel *ch, channel_handler *handler)
29 : m_ch(ch)
30 , m_handler(handler)
31 {
32 }
33
34 channel_event_handler::~channel_event_handler()
35 {
36         m_ch = NULL;
37         m_handler = NULL;
38 }
39
40 bool channel_event_handler::handle(int fd, event_condition condition)
41 {
42         message msg;
43
44         if (!m_ch || !m_ch->is_connected())
45                 return false;
46
47         if (condition & (EVENT_HUP)) {
48                 m_ch->disconnect();
49                 m_ch = NULL;
50                 return false;
51         }
52
53         if (!m_ch->read_sync(msg, false)) {
54                 m_ch->disconnect();
55                 m_ch = NULL;
56                 return false;
57         }
58
59         return true;
60 }
61
62 void channel_event_handler::connected(channel *ch)
63 {
64         if (m_handler)
65                 m_handler->connected(ch);
66 }
67
68 void channel_event_handler::disconnected(channel *ch)
69 {
70         if (m_handler)
71                 m_handler->disconnected(ch);
72 }
73
74 void channel_event_handler::read(channel *ch, message &msg)
75 {
76         if (m_handler)
77                 m_handler->read(ch, msg);
78 }
79
80 void channel_event_handler::read_complete(channel *ch)
81 {
82         if (m_handler)
83                 m_handler->read_complete(ch);
84 }
85
86 void channel_event_handler::error_caught(channel *ch, int error)
87 {
88         if (m_handler)
89                 m_handler->error_caught(ch, error);
90 }