2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file message_pipe.cpp
18 * @author Zofia Abramowska
20 * @brief Simple wrapper for message pipe
23 #include "message_pipe.h"
25 static void closeFd(int *fd) {
32 MessagePipe::MessagePipe() {
33 auto ret = pipe(m_pipeCP);
34 RUNNER_ASSERT_ERRNO_MSG(ret == 0, "pipe failed");
37 RUNNER_ASSERT_ERRNO_MSG(ret == 0, "pipe failed");
40 MessagePipe::~MessagePipe() {
41 closeFd(m_pipeCP + 0);
42 closeFd(m_pipeCP + 1);
43 closeFd(m_pipePC + 0);
44 closeFd(m_pipePC + 1);
47 void MessagePipe::claimParentEp() {
51 m_readEp = m_pipeCP[0];
52 closeFd(m_pipeCP + 1);
54 m_writeEp = m_pipePC[1];
55 closeFd(m_pipePC + 0);
60 void MessagePipe::claimChildEp() {
64 m_readEp = m_pipePC[0];
65 closeFd(m_pipePC + 1);
67 m_writeEp = m_pipeCP[1];
68 closeFd(m_pipeCP + 0);