]> Some of my projects - anidbudpclient.git/commitdiff
Add automatic cleanup of Client instance
authorAPTX <marek321@gmail.com>
Thu, 7 Jun 2012 01:04:29 +0000 (03:04 +0200)
committerAPTX <marek321@gmail.com>
Thu, 7 Jun 2012 01:04:29 +0000 (03:04 +0200)
client.cpp
client.h

index aecddc3aeeac6dececeada47accad61c2f1b98e0..e8afc70671ec9b5e00301f19e0c7d888f0dc6ceb 100644 (file)
@@ -32,6 +32,8 @@ Client::Client(QObject *parent) : ClientInterface(parent)
 #ifdef ANIDBUDPCLIENT_CLIENT_MISC_DEBUG
 qDebug() << "Api instance init!";
 #endif
+       init();
+
        authReply = 0;
        uptimeReply = 0;
        encryptReply = 0;
@@ -848,6 +850,8 @@ Client *Client::instance()
 
 void Client::destroy()
 {
+       if (!m_instance)
+               return;
        delete m_instance;
        m_instance = 0;
 }
@@ -1025,6 +1029,16 @@ bool Client::possiblyValid(const QByteArray &reply) const
        return false;
 }
 
+void Client::init()
+{
+       static bool done = false;
+       if (done)
+               return;
+       done = true;
+
+       qAddPostRoutine(Client::destroy);
+}
+
 void Client::commandTimeout()
 {
        Q_ASSERT(!sentCommandOrder.isEmpty());
index 7ff5348edc3dc2070e694d8138195898a4557ae0..5784f55bf461da36cc64acf56f033bdce348a8c5 100644 (file)
--- a/client.h
+++ b/client.h
@@ -203,6 +203,7 @@ private:
        EncryptCommand encryptCommand;
        EncryptReply *encryptReply;
 
+       static void init();
        static Client *m_instance;
 
        static const int UDP_DATAGRAM_MAXIMUM_SIZE = 1400;