File indexing completed on 2024-05-26 04:48:24

0001 /*
0002  * qca_safeobj.h - Qt Cryptographic Architecture
0003  * Copyright (C) 2008  Justin Karneges <justin@affinix.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018  * 02110-1301  USA
0019  *
0020  */
0021 
0022 #include "qca_safeobj.h"
0023 
0024 namespace QCA {
0025 
0026 // This function performs the following steps:
0027 //   obj->disconnect(owner); // to prevent future signals to owner
0028 //   obj->setParent(0);      // to prevent delete if parent is deleted
0029 //   obj->deleteLater();     // now we can forget about the object
0030 inline void releaseAndDeleteLater(QObject *owner, QObject *obj)
0031 {
0032     obj->disconnect(owner);
0033     obj->setParent(nullptr);
0034     obj->deleteLater();
0035 }
0036 
0037 SafeSocketNotifier::SafeSocketNotifier(qintptr socket, QSocketNotifier::Type type, QObject *parent)
0038     : QObject(parent)
0039 {
0040     sn = new QSocketNotifier(socket, type, this);
0041     connect(sn, &QSocketNotifier::activated, this, &SafeSocketNotifier::activated);
0042 }
0043 
0044 SafeSocketNotifier::~SafeSocketNotifier()
0045 {
0046     sn->setEnabled(false);
0047     releaseAndDeleteLater(this, sn);
0048 }
0049 
0050 }