2 Copyright (c) 2018-2019 Nokia.
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.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #ifndef SHAREDDATALAYER_FILEDESCRIPTOR_HPP_
23 #define SHAREDDATALAYER_FILEDESCRIPTOR_HPP_
27 namespace shareddatalayer
32 * @brief Wrapper for native file descriptor
34 * FileDescriptor provides a clever wrapper for native file descriptor and
35 * takes care of closing it in destructor.
41 * Take ownership of the given native file descriptor.
43 * @param fd The native file descriptor to wrap.
45 explicit FileDescriptor(int fd) noexcept;
48 * Take ownership of the given native file descriptor.
50 * @param fd The native file descriptor to wrap.
51 * @param system System instance to use.
53 FileDescriptor(System& system, int fd) noexcept;
56 * Move ownership of the given fd.
58 * @param fd The file descriptor to move.
60 FileDescriptor(FileDescriptor&& fd) noexcept;
63 * Move ownership of the given fd.
65 * @param fd The file descriptor to move.
67 FileDescriptor& operator = (FileDescriptor&& fd) noexcept;
70 * Close the wrapped native file descriptor. If <i>at close</i> function
71 * is set, then it is called just before closing the file descriptor.
78 * Get the wrapped native file descriptor.
80 * @return The wrapped native file descriptor.
82 operator int() const noexcept { return fd; }
85 * Set function to be called just before closing the native file
88 void atClose(std::function<void(int)>);
91 * Close the native file descriptor.
95 FileDescriptor(const FileDescriptor&) = delete;
96 FileDescriptor& operator = (const FileDescriptor&) = delete;
101 std::function<void(int)> atCloseCb;