sensord: resize message size
[platform/core/system/sensord.git] / src / shared / ipc_client.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 "ipc_client.h"
21
22 #include "sensor_log.h"
23 #include "stream_socket.h"
24 #include "event_handler.h"
25 #include "channel_event_handler.h"
26
27 using namespace ipc;
28
29 ipc_client::ipc_client(const std::string &path)
30 {
31         m_path = path;
32 }
33
34 ipc_client::~ipc_client()
35 {
36 }
37
38 bool ipc_client::set_option(int option, int value)
39 {
40         return true;
41 }
42
43 bool ipc_client::set_option(const std::string &option, int value)
44 {
45         return true;
46 }
47
48 channel *ipc_client::connect(channel_handler *handler)
49 {
50         return connect(handler, NULL);
51 }
52
53 channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bind)
54 {
55         socket *sock;
56         channel *ch;
57         channel_event_handler *ev_handler;
58
59         sock = new(std::nothrow) stream_socket();
60         retvm_if(!sock, NULL, "Failed to allocate memory");
61
62         if (!sock->create(m_path)) {
63                 delete sock;
64                 return NULL;
65         }
66
67         ch = new(std::nothrow) channel(sock);
68         if (!ch) {
69                 delete sock;
70                 _E("Failed to allocate memory");
71                 return NULL;
72         }
73
74         ev_handler = new(std::nothrow) channel_event_handler(ch, handler);
75         if (!ev_handler) {
76                 delete ch;
77                 delete sock;
78                 _E("Faield to allocate memory");
79                 return NULL;
80         }
81
82         ch->connect(ev_handler, loop);
83
84         if (loop && bind) {
85                 uint64_t id = loop->add_event(sock->get_fd(),
86                                 (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);
87                 ch->set_event_id(id);
88         }
89
90         _I("Connected");
91         return ch;
92 }