Rectifyng this poniter deletion from member function
[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                 return false;
50         }
51
52         if (!m_ch->read_sync(msg, false)) {
53                 m_ch->disconnect();
54                 return false;
55         }
56
57         return true;
58 }
59
60 void channel_event_handler::connected(channel *ch)
61 {
62         if (m_handler)
63                 m_handler->connected(ch);
64 }
65
66 void channel_event_handler::disconnected(channel *ch)
67 {
68         if (m_handler)
69                 m_handler->disconnected(ch);
70 }
71
72 void channel_event_handler::read(channel *ch, message &msg)
73 {
74         if (m_handler)
75                 m_handler->read(ch, msg);
76 }
77
78 void channel_event_handler::read_complete(channel *ch)
79 {
80         if (m_handler)
81                 m_handler->read_complete(ch);
82 }
83
84 void channel_event_handler::error_caught(channel *ch, int error)
85 {
86         if (m_handler)
87                 m_handler->error_caught(ch, error);
88 }