[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the plugins of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef QDBUSBINDING_H
|
---|
| 43 | #define QDBUSBINDING_H
|
---|
| 44 |
|
---|
| 45 | #include <QtDBus/QtDBus>
|
---|
| 46 | #include <QtScript/qscriptable.h>
|
---|
| 47 | #include <QtScript/qscriptengine.h>
|
---|
| 48 |
|
---|
[846] | 49 | #ifndef QT_NO_DBUS
|
---|
| 50 |
|
---|
[2] | 51 | class QDBusConnectionConstructor : public QObject,
|
---|
| 52 | public QScriptable
|
---|
| 53 | {
|
---|
| 54 | Q_OBJECT
|
---|
| 55 | Q_PROPERTY(QScriptValue sessionBus READ sessionBus)
|
---|
| 56 | Q_PROPERTY(QScriptValue systemBus READ systemBus)
|
---|
| 57 |
|
---|
| 58 | public:
|
---|
| 59 | QDBusConnectionConstructor(QScriptEngine *engine, QScriptValue extensionObject);
|
---|
| 60 |
|
---|
| 61 | QScriptValue sessionBus() const;
|
---|
| 62 | QScriptValue systemBus() const;
|
---|
| 63 |
|
---|
| 64 | public Q_SLOTS:
|
---|
| 65 | QObject *qscript_call(const QString &name);
|
---|
| 66 |
|
---|
| 67 | void disconnectFromBus(const QString &name);
|
---|
| 68 | QDBusConnection connectToBus(const QString &address, const QString &name);
|
---|
| 69 | QDBusConnection connectToBus(QDBusConnection::BusType type, const QString &name);
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | class QScriptDBusConnection : public QObject,
|
---|
| 73 | public QScriptable
|
---|
| 74 | {
|
---|
| 75 | Q_OBJECT
|
---|
| 76 | Q_PROPERTY(QString baseService READ baseService)
|
---|
| 77 | Q_PROPERTY(bool isConnected READ isConnected)
|
---|
| 78 | Q_PROPERTY(QScriptValue dbusInterface READ dbusInterface)
|
---|
| 79 | public:
|
---|
| 80 | QScriptDBusConnection(const QDBusConnection &conn, QObject *parent);
|
---|
| 81 |
|
---|
| 82 | inline QString baseService() const { return connection.baseService(); }
|
---|
| 83 | inline bool isConnected() const { return connection.isConnected(); }
|
---|
| 84 | QScriptValue dbusInterface() const;
|
---|
| 85 |
|
---|
| 86 | inline QDBusConnection dbusConnection() const { return connection; }
|
---|
| 87 |
|
---|
| 88 | public Q_SLOTS:
|
---|
| 89 | inline bool send(const QDBusMessage &message) const
|
---|
| 90 | { return connection.send(message); }
|
---|
| 91 | inline QDBusMessage call(const QDBusMessage &message, int callMode = QDBus::Block, int timeout = -1) const
|
---|
| 92 | { return connection.call(message, QDBus::CallMode(callMode), timeout); }
|
---|
| 93 |
|
---|
| 94 | inline bool registerService(const QString &serviceName)
|
---|
| 95 | { return connection.registerService(serviceName); }
|
---|
| 96 | inline bool unregisterService(const QString &serviceName)
|
---|
| 97 | { return connection.unregisterService(serviceName); }
|
---|
| 98 |
|
---|
| 99 | inline QDBusError lastError() const
|
---|
| 100 | { return connection.lastError(); }
|
---|
| 101 |
|
---|
| 102 | inline void unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode = QDBusConnection::UnregisterNode)
|
---|
| 103 | { return connection.unregisterObject(path, mode); }
|
---|
| 104 | inline QObject *objectRegisteredAt(const QString &path) const
|
---|
| 105 | { return connection.objectRegisteredAt(path); }
|
---|
| 106 |
|
---|
| 107 | #if 0
|
---|
| 108 | bool callWithCallback(const QDBusMessage &message, QObject *receiver,
|
---|
| 109 | const char *slot, int timeout = -1) const;
|
---|
| 110 |
|
---|
| 111 | bool connect(const QString &service, const QString &path, const QString &interface,
|
---|
| 112 | const QString &name, QObject *receiver, const char *slot);
|
---|
| 113 | bool disconnect(const QString &service, const QString &path, const QString &interface,
|
---|
| 114 | const QString &name, QObject *receiver, const char *slot);
|
---|
| 115 |
|
---|
| 116 | bool connect(const QString &service, const QString &path, const QString &interface,
|
---|
| 117 | const QString &name, const QString& signature,
|
---|
| 118 | QObject *receiver, const char *slot);
|
---|
| 119 | bool disconnect(const QString &service, const QString &path, const QString &interface,
|
---|
| 120 | const QString &name, const QString& signature,
|
---|
| 121 | QObject *receiver, const char *slot);
|
---|
| 122 |
|
---|
| 123 | bool registerObject(const QString &path, QObject *object,
|
---|
| 124 | RegisterOptions options = ExportAdaptors);
|
---|
| 125 |
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 | private:
|
---|
| 129 | QDBusConnection connection;
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | Q_DECLARE_METATYPE(QScriptDBusConnection*)
|
---|
| 133 |
|
---|
| 134 | class QScriptDBusInterfaceConstructor : public QObject,
|
---|
| 135 | public QScriptable
|
---|
| 136 | {
|
---|
| 137 | Q_OBJECT
|
---|
| 138 | public:
|
---|
| 139 | QScriptDBusInterfaceConstructor(QScriptEngine *engine, QScriptValue extensionObject);
|
---|
| 140 |
|
---|
| 141 | public Q_SLOTS:
|
---|
| 142 | QScriptValue qscript_call(const QString &service, const QString &path, const QString &interface = QString(),
|
---|
| 143 | const QScriptValue &conn = QScriptValue());
|
---|
| 144 | };
|
---|
| 145 |
|
---|
| 146 | Q_DECLARE_METATYPE(QDBusMessage)
|
---|
| 147 |
|
---|
| 148 | class QScriptDBusMessageConstructor : public QObject, public QScriptable
|
---|
| 149 | {
|
---|
| 150 | Q_OBJECT
|
---|
| 151 | Q_ENUMS(MessageType)
|
---|
| 152 | public:
|
---|
| 153 | enum MessageType {
|
---|
| 154 | InvalidMessage = QDBusMessage::InvalidMessage,
|
---|
| 155 | MethodCallMessage = QDBusMessage::MethodCallMessage,
|
---|
| 156 | ReplyMessage = QDBusMessage::ReplyMessage,
|
---|
| 157 | ErrorMessage = QDBusMessage::ErrorMessage,
|
---|
| 158 | SignalMessage = QDBusMessage::SignalMessage
|
---|
| 159 | };
|
---|
| 160 |
|
---|
| 161 | QScriptDBusMessageConstructor(QScriptEngine *engine, QScriptValue extensionObject);
|
---|
| 162 |
|
---|
| 163 | QScriptValue protoType() const { return proto; }
|
---|
| 164 |
|
---|
| 165 | public Q_SLOTS:
|
---|
| 166 | QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name);
|
---|
| 167 | QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method);
|
---|
| 168 | QDBusMessage createError(const QString &name, const QString &msg);
|
---|
| 169 |
|
---|
| 170 | public:
|
---|
| 171 | static QScriptValue createReply(QScriptContext *context, QScriptEngine *engine);
|
---|
| 172 | static QScriptValue createErrorReply(QScriptContext *context, QScriptEngine *engine);
|
---|
| 173 |
|
---|
| 174 | private:
|
---|
| 175 | QScriptValue proto;
|
---|
| 176 | };
|
---|
| 177 |
|
---|
[846] | 178 | #endif // QT_NO_DBUS
|
---|
[2] | 179 | #endif // QDBUSBINDING_H
|
---|