Disable gcov
[platform/upstream/csr-framework.git] / src / framework / common / connection.cpp
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 /*
17  * @file        connection.cpp
18  * @author      Kyungwook Tak (k.tak@samsung.com)
19  * @version     1.0
20  * @brief
21  */
22 #include "common/connection.h"
23
24 #include <utility>
25
26 #ifdef TIZEN_TEST_GCOV
27 extern "C" void __gcov_flush();
28 #endif
29
30 namespace Csr {
31
32 Connection::Connection(Socket &&socket) noexcept :
33         m_socket(std::move(socket))
34 {
35 }
36
37 Connection::Connection(Connection &&other) noexcept :
38         m_socket(std::move(other.m_socket))
39 {
40 }
41
42 Connection::~Connection()
43 {
44 }
45
46 Connection &Connection::operator=(Connection &&other) noexcept
47 {
48         if (this == &other)
49                 return *this;
50
51         this->m_socket = std::move(other.m_socket);
52         return *this;
53 }
54
55 void Connection::send(const RawBuffer &buf) const
56 {
57 #ifdef TIZEN_TEST_GCOV
58         __gcov_flush();
59 #endif
60         std::lock_guard<std::mutex> lock(this->m_mSend);
61         this->m_socket.write(buf);
62 }
63
64 RawBuffer Connection::receive() const
65 {
66         std::lock_guard<std::mutex> lock(this->m_mRecv);
67         return this->m_socket.read();
68 }
69
70 SockId Connection::getSockId() const noexcept
71 {
72         return this->m_socket.getSockId();
73 }
74
75 int Connection::getFd() const noexcept
76 {
77         return this->m_socket.getFd();
78 }
79
80 const Credential &Connection::getCredential()
81 {
82         if (this->m_cred)
83                 return *this->m_cred;
84
85         this->m_cred = Credential::get(getFd());
86
87         return *this->m_cred;
88 }
89
90 }