24 #include "dbusoperationqueuehandler.h"
26 #include <QMetaMethod>
30 #include "libsignoncommon.h"
31 #include "identityinfo.h"
40 DBusOperationQueueHandler::Operation::Operation(
const char *name,
41 QList<QGenericArgument *> args)
47 void DBusOperationQueueHandler::Operation::copy(
const char *name,
48 const QList<QGenericArgument *> &args)
50 Q_ASSERT(name != NULL);
52 m_name =
new char[qstrlen(name) + 1];
53 qstrcpy(m_name, name);
55 QListIterator<QGenericArgument *> it(args);
56 while (it.hasNext()) {
57 QGenericArgument *arg = it.next();
58 int type = QMetaType::type(arg->name());
59 if (!QMetaType::isRegistered(type)) {
62 << QString(QLatin1String(
"Type %1 not registered."))
63 .arg(QLatin1String(arg->name()));
65 Q_ASSERT(arg->name() != NULL);
67 char *localName =
new char[qstrlen(arg->name()) + 1];
68 qstrcpy(localName, arg->name());
69 void *localData = QMetaType::construct(type, arg->data());
71 m_args << (
new QGenericArgument(localName, localData));
76 DBusOperationQueueHandler::Operation::~Operation()
81 foreach (QGenericArgument *arg, m_args) {
82 QMetaType::destroy(QMetaType::type(arg->name()), arg->data());
84 delete [] arg->name();
91 DBusOperationQueueHandler::DBusOperationQueueHandler(QObject *clientObject):
92 m_clientObject(clientObject),
93 m_maxNumberOfOperationParameters(6),
94 m_operationsStopped(false)
98 DBusOperationQueueHandler::~DBusOperationQueueHandler()
102 void DBusOperationQueueHandler::enqueueOperation(Operation *operation)
104 m_operationsQueue.enqueue(operation);
107 void DBusOperationQueueHandler::enqueueOperation(
const char *name,
108 QList<QGenericArgument *> args)
110 m_operationsQueue.enqueue(
new Operation(name, args));
113 void DBusOperationQueueHandler::execQueuedOperations()
115 m_operationsStopped =
false;
117 while (m_operationsStopped ==
false && !m_operationsQueue.empty()) {
118 Operation *op = m_operationsQueue.dequeue();
120 if (op->m_args.size() > m_maxNumberOfOperationParameters) {
121 qWarning() <<
"DBusOperationQueueHandler::execQueuedOperations(): "
122 "Maximum number of operation parameters exceeded(6).";
126 int indexOfMethod = m_clientObject->metaObject()->indexOfMethod(
127 QMetaObject::normalizedSignature(op->m_name));
129 QMetaMethod method = m_clientObject->metaObject()->method(indexOfMethod);
131 TRACE() <<
"Executing cached oparation: SIGNATURE:" <<
134 switch (op->m_args.count()) {
135 case 0: TRACE(); method.invoke(m_clientObject);
break;
136 case 1: TRACE(); method.invoke(
138 *(op->m_args.at(0)));
break;
139 case 2: TRACE(); method.invoke(
142 *(op->m_args.at(1)));
break;
143 case 3: TRACE(); method.invoke(
147 *(op->m_args.at(2)));
break;
148 case 4: TRACE(); method.invoke(
153 *(op->m_args.at(3)));
break;
154 case 5: TRACE(); method.invoke(
160 *(op->m_args.at(4)));
break;
161 case 6: TRACE(); method.invoke(
168 *(op->m_args.at(5)));
break;
169 default: TRACE(); method.invoke(m_clientObject);
break;
175 void DBusOperationQueueHandler::removeOperation(
const char *name,
bool removeAll)
177 foreach (Operation *operation, m_operationsQueue) {
178 if (operation != NULL && qstrcmp(operation->m_name, name) == 0) {
179 m_operationsQueue.removeOne(operation);
186 bool DBusOperationQueueHandler::queueContainsOperation(
const char *name)
188 foreach (Operation *operation, m_operationsQueue)
189 if (operation != NULL && qstrcmp(operation->m_name, name) == 0)