Mir
fd.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2 or 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 #ifndef MIR_FD_H_
19 #define MIR_FD_H_
20 
21 #include <memory>
22 
23 namespace mir
24 {
25 //TODO: remove once mir::Fd is used more pervasively.
26 // some existing code does not really allow us to transfer or share the ownership
27 // of the fd. Constructing using mir::Fd(IntOwnedFd(int)) will help transition the existing
28 // code to using the mir::Fd type properly.
29 struct IntOwnedFd
30 {
32 };
33 class Fd
34 {
35 public:
36  //transfer ownership of the POD-int to the object. The int no longer needs close()ing,
37  //and has the lifetime of the Fd object.
38  explicit Fd(int fd);
39  explicit Fd(IntOwnedFd);
40  static int const invalid{-1};
41  Fd(); //Initializes fd to the mir::Fd::invalid;
42  Fd(Fd&&);
43  Fd(Fd const&) = default;
45 
46  //bit of a convenient kludge. take care not to close or otherwise destroy the FD.
47  operator int() const;
48 
49 private:
50  std::shared_ptr<int> fd;
51 };
52 } // namespace mir
53 
54 #endif // MIR_FD_H_
Definition: fd.h:34
Fd(Fd &&)
Fd(Fd const &)=default
Fd & operator=(Fd)
Fd(int fd)
Fd(IntOwnedFd)
static int const invalid
Definition: fd.h:40
Definition: splash_session.h:24
Definition: fd.h:30
int int_owned_fd
Definition: fd.h:31

Copyright © 2012-2021 Canonical Ltd.
Generated on Mon Jul 5 13:30:06 UTC 2021
This documentation is licensed under the GPL version 2 or 3.