4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "ipc_client.h"
22 #include "sensor_log.h"
23 #include "stream_socket.h"
24 #include "event_handler.h"
25 #include "channel_event_handler.h"
29 ipc_client::ipc_client(const std::string &path)
34 ipc_client::~ipc_client()
38 bool ipc_client::set_option(int option, int value)
43 bool ipc_client::set_option(const std::string &option, int value)
48 channel *ipc_client::connect(channel_handler *handler)
50 return connect(handler, NULL);
53 channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bind)
57 channel_event_handler *ev_handler;
59 sock = new(std::nothrow) stream_socket();
60 retvm_if(!sock, NULL, "Failed to allocate memory");
62 if (!sock->create(m_path)) {
67 ch = new(std::nothrow) channel(sock);
70 _E("Failed to allocate memory");
74 ev_handler = new(std::nothrow) channel_event_handler(ch, handler);
78 _E("Faield to allocate memory");
82 ch->connect(ev_handler, loop);
85 uint64_t id = loop->add_event(sock->get_fd(),
86 (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);