filedescriptor.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later OR BSD-3-Clause
2 /***************************************************************************
3  * Copyright (C) 2009,2010 by Rick L. Vinyard, Jr. *
4  * rvinyard@cs.nmsu.edu *
5  * Copyright (C) 2014- by Robert Middleton *
6  * *
7  * This file is part of the dbus-cxx library. *
8  ***************************************************************************/
9 
10 #ifndef DBUS_CXX_FILEDESCRIPTOR
11 #define DBUS_CXX_FILEDESCRIPTOR
12 
13 #include <memory>
14 
15 namespace DBus {
16 
22 protected:
24  m_valid( false ),
25  m_fd( -1 ) {}
26 
27  explicit FileDescriptor( int fd ) :
28  m_valid( true ),
29  m_fd( fd ) {}
30 
31  explicit FileDescriptor( const FileDescriptor& other ) :
32  m_valid( other.m_valid ),
33  m_fd( other.m_fd ) {}
34 
35 public:
36  static std::shared_ptr<FileDescriptor> create( int fd ) {
37  std::shared_ptr<FileDescriptor> p( new FileDescriptor( fd ) );
38  return p;
39  }
40 
42 
43  int descriptor() const {
44  return m_fd;
45  }
46 
47  operator bool() const {
48  return m_valid;
49  }
50 
51 private:
52  bool m_valid;
53  int m_fd;
54 };
55 
56 }
57 
58 #endif
A FileDescriptor holds a UNIX file descriptor that can be passed between processes.
Definition: filedescriptor.h:21
static std::shared_ptr< FileDescriptor > create(int fd)
Definition: filedescriptor.h:36
FileDescriptor(int fd)
Definition: filedescriptor.h:27
FileDescriptor(const FileDescriptor &other)
Definition: filedescriptor.h:31
int m_fd
Definition: filedescriptor.h:53
bool m_valid
Definition: filedescriptor.h:52
FileDescriptor()
Definition: filedescriptor.h:23
int descriptor() const
Definition: filedescriptor.h:43
~FileDescriptor()
Definition: filedescriptor.h:41
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18