source: trunk/src/plugins/script/qtdbus/main.h@ 104

Last change on this file since 104 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
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**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
49class 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
56public:
57 QDBusConnectionConstructor(QScriptEngine *engine, QScriptValue extensionObject);
58
59 QScriptValue sessionBus() const;
60 QScriptValue systemBus() const;
61
62public 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
70class 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)
77public:
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
86public 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
126private:
127 QDBusConnection connection;
128};
129
130Q_DECLARE_METATYPE(QScriptDBusConnection*)
131
132class QScriptDBusInterfaceConstructor : public QObject,
133 public QScriptable
134{
135 Q_OBJECT
136public:
137 QScriptDBusInterfaceConstructor(QScriptEngine *engine, QScriptValue extensionObject);
138
139public Q_SLOTS:
140 QScriptValue qscript_call(const QString &service, const QString &path, const QString &interface = QString(),
141 const QScriptValue &conn = QScriptValue());
142};
143
144Q_DECLARE_METATYPE(QDBusMessage)
145
146class QScriptDBusMessageConstructor : public QObject, public QScriptable
147{
148 Q_OBJECT
149 Q_ENUMS(MessageType)
150public:
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
163public 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
168public:
169 static QScriptValue createReply(QScriptContext *context, QScriptEngine *engine);
170 static QScriptValue createErrorReply(QScriptContext *context, QScriptEngine *engine);
171
172private:
173 QScriptValue proto;
174};
175
176#endif // QDBUSBINDING_H
Note: See TracBrowser for help on using the repository browser.