tdebluez
tdebluezNode.cpp
Go to the documentation of this file.
1// File autogenerated
2
3// declaration include
4#include "tdebluezNode.h"
5
6// TQt includes
7#include <tqdom.h>
8#include <tqmap.h>
9#include <tqstringlist.h>
10
11// TQt D-Bus includes
12#include <tqdbusconnection.h>
13#include <tqdbusmessage.h>
14
15
16// interface classes includes
18#include "agent1Interface.h"
19
20namespace org
21{
22namespace trinitydesktop
23{
24
26{
27public:
28 virtual ~Private();
29
30public:
33
34 TQT_DBusConnection connection;
35 TQString objectPath;
36 TQStringList childrenNodes;
37
38protected:
39 virtual bool Introspect(TQString& data, TQT_DBusError& error);
40
41 virtual void handleMethodReply(const TQT_DBusMessage& reply);
42private:
44};
45
46tdebluezNode::tdebluezNode() : TQT_DBusObjectBase(),
47 m_private(new Private())
48{
49}
50
52{
54
55 delete m_private;
56}
57
58bool tdebluezNode::registerObject(const TQT_DBusConnection& connection, const TQString& path)
59{
60 if (path.isEmpty()) return false;
61
62 if (!m_private->objectPath.isEmpty()) unregisterObject();
63
64 m_private->connection = connection;
65 m_private->objectPath = path;
66
67 if (!m_private->connection.registerObject(path, this))
68 {
69 m_private->connection = TQT_DBusConnection();
70 m_private->objectPath = TQString();
71
72 return false;
73 }
74
75 if (m_private->interfaces.isEmpty())
76 {
77 TQString name = "org.freedesktop.DBus.Introspectable";
78 TQT_DBusObjectBase* interface = m_private;
79 m_private->interfaces.insert(name, interface);
80
81 name = "org.bluez.Agent1";
82 interface = createInterface(name);
83 Q_ASSERT(interface != 0);
84 m_private->interfaces.insert(name, interface);
85 }
86
87 return true;
88}
89
90void tdebluezNode::addChildNode(const TQString& child)
91{
92 m_private->childrenNodes.append(child);
93}
94
96{
97 if (m_private->objectPath.isEmpty()) return;
98
99 m_private->connection.unregisterObject(m_private->objectPath);
100
101 m_private->connection = TQT_DBusConnection();
102 m_private->objectPath = TQString();
103}
104
105bool tdebluezNode::handleMethodCall(const TQT_DBusMessage& message)
106{
107 TQMap<TQString, TQT_DBusObjectBase*>::iterator findIt = m_private->interfaces.find(message.interface());
108 if (findIt == m_private->interfaces.end()) return false;
109
110 return delegateMethodCall(message, findIt.data());
111}
112
114{
117 for (; it != endIt; ++it)
118 {
119 TQT_DBusObjectBase* interface = it.data();
120 if (interface != this)
121 delete interface;
122 }
123 interfaces.clear();
124}
125
126bool tdebluezNode::Private::Introspect(TQString& data, TQT_DBusError& error)
127{
128 Q_UNUSED(error);
129 if (introspectionData.isEmpty()) cacheIntrospectionData();
130
131 data = introspectionData;
132
133 return true;
134}
135
136void tdebluezNode::Private::handleMethodReply(const TQT_DBusMessage& reply)
137{
138 connection.send(reply);
139}
140
142{
143 TQDomDocument doc;
144 TQDomElement interfaceElement;
145 TQDomElement nodeElement = doc.createElement("node");
146 if (!objectPath.isEmpty() && objectPath.compare("/") != 0)
147 {
148 nodeElement.setAttribute ( "name", objectPath );
149 }
150 // Introspectable is added by default. Show it only if there is interface
151 if (interfaces.count()>1) {
152 interfaceElement = doc.createElement("interface");
154 nodeElement.appendChild(interfaceElement);
155 }
156
157 interfaceElement = doc.createElement("interface");
159 nodeElement.appendChild(interfaceElement);
160
161 if (!childrenNodes.isEmpty()) {
162 for (TQStringList::Iterator it = childrenNodes.begin(); it != childrenNodes.end(); ++it ) {
163 TQDomElement nodeElement1 = doc.createElement("node");
164 nodeElement1.setAttribute ( "name", *it );
165 nodeElement.appendChild(nodeElement1);
166 }
167 }
168
169 doc.appendChild(nodeElement);
170
171 introspectionData = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n";
172 introspectionData += doc.toString();
173}
174
175}; // namespace trinitydesktop
176
177}; // namespace org
178
179// End of File
180
static void buildIntrospectionData(TQDomElement &interfaceElement)
virtual bool Introspect(TQString &data, TQT_DBusError &error)
virtual void handleMethodReply(const TQT_DBusMessage &reply)
TQMap< TQString, TQT_DBusObjectBase * > interfaces
virtual bool handleMethodCall(const TQT_DBusMessage &message)
bool registerObject(const TQT_DBusConnection &connection, const TQString &path)
void addChildNode(const TQString &child)