~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to include/shared/mir/fd.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 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
 
{
31
 
    int int_owned_fd;
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;
44
 
    Fd& operator=(Fd);
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_