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 = NULL;
59 retvm_if(access(m_path.c_str(), F_OK), NULL,
60 "Failed to access to %s", m_path.c_str());
62 sock = new(std::nothrow) stream_socket();
63 retvm_if(!sock, NULL, "Failed to allocate memory");
65 if (!sock->create(m_path)) {
70 ch = new(std::nothrow) channel(sock);
73 _E("Failed to allocate memory");
77 ev_handler = new(std::nothrow) channel_event_handler(ch, handler);
81 _E("Faield to allocate memory");
85 ret = ch->connect(ev_handler, loop);
90 _E("Faield to connect");
95 uint64_t id = loop->add_event(sock->get_fd(),
96 (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);