DBus-1-TQt  1.0
tqdbusunixfd.cpp
Go to the documentation of this file.
1 /* tqdbusunixfd.cpp DBUS unix file handle data type
2  *
3  * Copyright (C) 2013 Slávek Banko <slavek.banko@axis.cz>
4  *
5  * Licensed under the Academic Free License version 2.1
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20  * USA.
21  *
22  */
23 
24 #include <unistd.h>
25 #include "tqdbusunixfd.h"
26 
28 {
29  d->ref();
30  d->fd = -1;
31 };
32 
34 {
35  d->ref();
36 }
37 
39 {
40  setFileDescriptor(other);
41 }
42 
44 {
45  if (d && d->deref() ) {
46  if ( isValid() ) {
47  close(d->fd);
48  }
49  delete d;
50  }
51 }
52 
54 {
55  return d ? d->fd != -1 : false;
56 }
57 
59 {
60  return d ? d->fd : -1;
61 }
62 
63 void TQT_DBusUnixFd::setFileDescriptor(int fileDescriptor)
64 {
66 }
67 
68 void TQT_DBusUnixFd::giveFileDescriptor(int fileDescriptor)
69 {
70  if ( d && d->deref() ) {
71  if ( isValid() ) {
72  close(d->fd);
73  }
74  }
75  else {
77  }
78  d->ref();
79  d->fd = fileDescriptor;
80 }
81 
83 {
84  if (other.d) {
85  other.d->ref();
86  }
87  if ( d && d->deref() ) {
88  if ( isValid() ) {
89  close(d->fd);
90  }
91  delete d;
92  }
93  d = other.d;
94  return *this;
95 }
TQT_DBusUnixFd::TQT_DBusUnixFdPrivate
Definition: tqdbusunixfd.h:144
TQT_DBusUnixFd::TQT_DBusUnixFd
TQT_DBusUnixFd()
Creates an empty and invalid unix file handle.
Definition: tqdbusunixfd.cpp:27
TQT_DBusUnixFd::operator=
TQT_DBusUnixFd & operator=(const TQT_DBusUnixFd &other)
Copy unix file handle from TQT_DBusUnixFd.
Definition: tqdbusunixfd.cpp:82
TQT_DBusUnixFd::TQT_DBusUnixFdPrivate::fd
int fd
Definition: tqdbusunixfd.h:145
TQT_DBusUnixFd
Class for representing D-Bus unix file handles.
Definition: tqdbusunixfd.h:51
TQT_DBusUnixFd::giveFileDescriptor
void giveFileDescriptor(int fileDescriptor)
Give unix file handle.
Definition: tqdbusunixfd.cpp:68
tqdbusunixfd.h
TQT_DBusUnixFd::~TQT_DBusUnixFd
virtual ~TQT_DBusUnixFd()
Destroys the unix file handle.
Definition: tqdbusunixfd.cpp:43
TQT_DBusUnixFd::isValid
bool isValid() const
Returns whether the current content is considered a valid unix file handle.
Definition: tqdbusunixfd.cpp:53
TQT_DBusUnixFd::d
TQT_DBusUnixFd::TQT_DBusUnixFdPrivate * d
TQT_DBusUnixFd::setFileDescriptor
void setFileDescriptor(int fileDescriptor)
Set new unix file handle.
Definition: tqdbusunixfd.cpp:63
TQT_DBusUnixFd::fileDescriptor
int fileDescriptor() const
Get unix file handle.
Definition: tqdbusunixfd.cpp:58