|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the plugins of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 |
|
49 class QDBusConnectionConstructor : public QObject, |
|
50 public QScriptable |
|
51 { |
|
52 Q_OBJECT |
|
53 Q_PROPERTY(QScriptValue sessionBus READ sessionBus) |
|
54 Q_PROPERTY(QScriptValue systemBus READ systemBus) |
|
55 |
|
56 public: |
|
57 QDBusConnectionConstructor(QScriptEngine *engine, QScriptValue extensionObject); |
|
58 |
|
59 QScriptValue sessionBus() const; |
|
60 QScriptValue systemBus() const; |
|
61 |
|
62 public Q_SLOTS: |
|
63 QObject *qscript_call(const QString &name); |
|
64 |
|
65 void disconnectFromBus(const QString &name); |
|
66 QDBusConnection connectToBus(const QString &address, const QString &name); |
|
67 QDBusConnection connectToBus(QDBusConnection::BusType type, const QString &name); |
|
68 }; |
|
69 |
|
70 class QScriptDBusConnection : public QObject, |
|
71 public QScriptable |
|
72 { |
|
73 Q_OBJECT |
|
74 Q_PROPERTY(QString baseService READ baseService) |
|
75 Q_PROPERTY(bool isConnected READ isConnected) |
|
76 Q_PROPERTY(QScriptValue dbusInterface READ dbusInterface) |
|
77 public: |
|
78 QScriptDBusConnection(const QDBusConnection &conn, QObject *parent); |
|
79 |
|
80 inline QString baseService() const { return connection.baseService(); } |
|
81 inline bool isConnected() const { return connection.isConnected(); } |
|
82 QScriptValue dbusInterface() const; |
|
83 |
|
84 inline QDBusConnection dbusConnection() const { return connection; } |
|
85 |
|
86 public Q_SLOTS: |
|
87 inline bool send(const QDBusMessage &message) const |
|
88 { return connection.send(message); } |
|
89 inline QDBusMessage call(const QDBusMessage &message, int callMode = QDBus::Block, int timeout = -1) const |
|
90 { return connection.call(message, QDBus::CallMode(callMode), timeout); } |
|
91 |
|
92 inline bool registerService(const QString &serviceName) |
|
93 { return connection.registerService(serviceName); } |
|
94 inline bool unregisterService(const QString &serviceName) |
|
95 { return connection.unregisterService(serviceName); } |
|
96 |
|
97 inline QDBusError lastError() const |
|
98 { return connection.lastError(); } |
|
99 |
|
100 inline void unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode = QDBusConnection::UnregisterNode) |
|
101 { return connection.unregisterObject(path, mode); } |
|
102 inline QObject *objectRegisteredAt(const QString &path) const |
|
103 { return connection.objectRegisteredAt(path); } |
|
104 |
|
105 #if 0 |
|
106 bool callWithCallback(const QDBusMessage &message, QObject *receiver, |
|
107 const char *slot, int timeout = -1) const; |
|
108 |
|
109 bool connect(const QString &service, const QString &path, const QString &interface, |
|
110 const QString &name, QObject *receiver, const char *slot); |
|
111 bool disconnect(const QString &service, const QString &path, const QString &interface, |
|
112 const QString &name, QObject *receiver, const char *slot); |
|
113 |
|
114 bool connect(const QString &service, const QString &path, const QString &interface, |
|
115 const QString &name, const QString& signature, |
|
116 QObject *receiver, const char *slot); |
|
117 bool disconnect(const QString &service, const QString &path, const QString &interface, |
|
118 const QString &name, const QString& signature, |
|
119 QObject *receiver, const char *slot); |
|
120 |
|
121 bool registerObject(const QString &path, QObject *object, |
|
122 RegisterOptions options = ExportAdaptors); |
|
123 |
|
124 #endif |
|
125 |
|
126 private: |
|
127 QDBusConnection connection; |
|
128 }; |
|
129 |
|
130 Q_DECLARE_METATYPE(QScriptDBusConnection*) |
|
131 |
|
132 class QScriptDBusInterfaceConstructor : public QObject, |
|
133 public QScriptable |
|
134 { |
|
135 Q_OBJECT |
|
136 public: |
|
137 QScriptDBusInterfaceConstructor(QScriptEngine *engine, QScriptValue extensionObject); |
|
138 |
|
139 public Q_SLOTS: |
|
140 QScriptValue qscript_call(const QString &service, const QString &path, const QString &interface = QString(), |
|
141 const QScriptValue &conn = QScriptValue()); |
|
142 }; |
|
143 |
|
144 Q_DECLARE_METATYPE(QDBusMessage) |
|
145 |
|
146 class QScriptDBusMessageConstructor : public QObject, public QScriptable |
|
147 { |
|
148 Q_OBJECT |
|
149 Q_ENUMS(MessageType) |
|
150 public: |
|
151 enum MessageType { |
|
152 InvalidMessage = QDBusMessage::InvalidMessage, |
|
153 MethodCallMessage = QDBusMessage::MethodCallMessage, |
|
154 ReplyMessage = QDBusMessage::ReplyMessage, |
|
155 ErrorMessage = QDBusMessage::ErrorMessage, |
|
156 SignalMessage = QDBusMessage::SignalMessage |
|
157 }; |
|
158 |
|
159 QScriptDBusMessageConstructor(QScriptEngine *engine, QScriptValue extensionObject); |
|
160 |
|
161 QScriptValue protoType() const { return proto; } |
|
162 |
|
163 public Q_SLOTS: |
|
164 QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name); |
|
165 QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method); |
|
166 QDBusMessage createError(const QString &name, const QString &msg); |
|
167 |
|
168 public: |
|
169 static QScriptValue createReply(QScriptContext *context, QScriptEngine *engine); |
|
170 static QScriptValue createErrorReply(QScriptContext *context, QScriptEngine *engine); |
|
171 |
|
172 private: |
|
173 QScriptValue proto; |
|
174 }; |
|
175 |
|
176 #endif // QDBUSBINDING_H |