dbusoperationqueuehandler.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00023 
00024 #ifndef DBUSOPERATIONQUEUEHANDLER_H
00025 #define DBUSOPERATIONQUEUEHANDLER_H
00026 
00027 #include <QQueue>
00028 #include <QDBusInterface>
00029 
00030 
00031 #define SIGNOND_NORMALIZE_METHOD_SIGNATURE(method) \
00032     DBusOperationQueueHandler::normalizedOperationSignature(method).data()
00033 
00034 /*
00035  * @cond IMPL
00036  */
00037 namespace SignOn {
00038 
00039 class DBusOperationQueueHandler
00040 {
00041 public:
00042     struct Operation
00043     {
00044         Operation(const char *name,
00045                   QList<QGenericArgument *> args = QList<QGenericArgument *>());
00046         ~Operation();
00047 
00048         inline bool operator==(const Operation &op) const
00049             { return QLatin1String(op.m_name) == m_name; }
00050 
00051         char *m_name;
00052         QList<QGenericArgument *> m_args;
00053 
00054     private:
00055         void copy(const char *name,
00056                   const QList<QGenericArgument *> &args);
00057     };
00058 
00059 public:
00060     DBusOperationQueueHandler(QObject *clientObject);
00061     ~DBusOperationQueueHandler();
00062 
00063     void enqueueOperation(Operation *operation);
00064     void enqueueOperation(const char *name,
00065                           QList<QGenericArgument *> args = QList<QGenericArgument *>());
00066 
00067     void execQueuedOperations();
00068     int queuedOperationsCount() const { return m_operationsQueue.count(); }
00069     void clearOperationsQueue() { m_operationsQueue.clear(); }
00070 
00071     void removeOperation(const char *name, bool removeAll = true);
00072 
00073     bool queueContainsOperation(const char *name);
00074     void stopOperationsProcessing() { m_operationsStopped = true; }
00075 
00076     static QByteArray normalizedOperationSignature(const char *operationName)
00077         { return QMetaObject::normalizedSignature(operationName); }
00078 
00079 private:
00080     QObject *m_clientObject;
00081     const int m_maxNumberOfOperationParameters;
00082     QQueue<Operation *> m_operationsQueue;
00083     bool m_operationsStopped;
00084 };
00085 
00086 } //SignOn
00087 
00088 /*
00089  * @endcond IMPL
00090  */
00091 
00092 #endif // DBUSOPERATIONQUEUEHANDLER_H