dbusoperationqueuehandler.h
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
7  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #ifndef DBUSOPERATIONQUEUEHANDLER_H
25 #define DBUSOPERATIONQUEUEHANDLER_H
26 
27 #include <QQueue>
28 #include <QDBusInterface>
29 
30 
31 #define SIGNOND_NORMALIZE_METHOD_SIGNATURE(method) \
32  DBusOperationQueueHandler::normalizedOperationSignature(method).data()
33 
34 /*
35  * @cond IMPL
36  */
37 namespace SignOn {
38 
39 class DBusOperationQueueHandler
40 {
41 public:
42  struct Operation
43  {
44  Operation(const char *name,
45  QList<QGenericArgument *> args = QList<QGenericArgument *>());
46  ~Operation();
47 
48  inline bool operator==(const Operation &op) const
49  { return qstrcmp(op.m_name, m_name) == 0; }
50 
51  char *m_name;
52  QList<QGenericArgument *> m_args;
53 
54  private:
55  void copy(const char *name,
56  const QList<QGenericArgument *> &args);
57  };
58 
59 public:
60  DBusOperationQueueHandler(QObject *clientObject);
61  ~DBusOperationQueueHandler();
62 
63  void enqueueOperation(Operation *operation);
64  void enqueueOperation(const char *name,
65  QList<QGenericArgument *> args = QList<QGenericArgument *>());
66 
67  void execQueuedOperations();
68  int queuedOperationsCount() const { return m_operationsQueue.count(); }
69  void clearOperationsQueue() { m_operationsQueue.clear(); }
70 
71  void removeOperation(const char *name, bool removeAll = true);
72 
73  bool queueContainsOperation(const char *name);
74  void stopOperationsProcessing() { m_operationsStopped = true; }
75 
76  static QByteArray normalizedOperationSignature(const char *operationName)
77  { return QMetaObject::normalizedSignature(operationName); }
78 
79 private:
80  QObject *m_clientObject;
81  const int m_maxNumberOfOperationParameters;
82  QQueue<Operation *> m_operationsQueue;
83  bool m_operationsStopped;
84 };
85 
86 } //SignOn
87 
88 /*
89  * @endcond IMPL
90  */
91 
92 #endif // DBUSOPERATIONQUEUEHANDLER_H