tdebluez
libtdeobex/interfaces/dbusbaseNode.cpp
Go to the documentation of this file.
1 // File autogenerated
2 
3 // declaration include
4 #include "dbusbaseNode.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
17 #include "dbusbaseNode.h"
19 
20 
22 {
23 public:
24  virtual ~Private();
25 
26 public:
28  TQString introspectionData;
29 
30  TQT_DBusConnection connection;
31  TQString objectPath;
32  TQStringList childrenNodes;
33 
34 protected:
35  virtual bool Introspect(TQString& data, TQT_DBusError& error);
36 
37  virtual void handleMethodReply(const TQT_DBusMessage& reply);
38 private:
40 };
41 
42 DBusBaseNode::DBusBaseNode() : TQT_DBusObjectBase(),
43  m_private(new Private())
44 {
45 }
46 
48 {
50 
51  delete m_private;
52 }
53 
54 bool DBusBaseNode::registerObject(const TQT_DBusConnection& connection, const TQString& path)
55 {
56  if (path.isEmpty()) return false;
57 
58  if (!m_private->objectPath.isEmpty()) unregisterObject();
59 
60  m_private->connection = connection;
61  m_private->objectPath = path;
62 
63  if (!m_private->connection.registerObject(path, this))
64  {
65  m_private->connection = TQT_DBusConnection();
66  m_private->objectPath = TQString();
67 
68  return false;
69  }
70 
71  if (m_private->interfaces.isEmpty())
72  {
73  TQString name = "org.freedesktop.DBus.Introspectable";
74  TQT_DBusObjectBase* interface = m_private;
75  m_private->interfaces.insert(name, interface);
76  }
77 
78  return true;
79 }
80 
81 void DBusBaseNode::addChildNode(const TQString& child)
82 {
83  m_private->childrenNodes.append(child);
84 }
85 
87 {
88  if (m_private->objectPath.isEmpty()) return;
89 
90  m_private->connection.unregisterObject(m_private->objectPath);
91 
92  m_private->connection = TQT_DBusConnection();
93  m_private->objectPath = TQString();
94 }
95 
96 bool DBusBaseNode::handleMethodCall(const TQT_DBusMessage& message)
97 {
98  TQMap<TQString, TQT_DBusObjectBase*>::iterator findIt = m_private->interfaces.find(message.interface());
99  if (findIt == m_private->interfaces.end()) return false;
100 
101  return delegateMethodCall(message, findIt.data());
102 }
103 
105 {
108  for (; it != endIt; ++it)
109  {
110  TQT_DBusObjectBase* interface = it.data();
111  if (interface != this)
112  delete interface;
113  }
114  interfaces.clear();
115 }
116 
117 bool DBusBaseNode::Private::Introspect(TQString& data, TQT_DBusError& error)
118 {
119  Q_UNUSED(error);
120  if (introspectionData.isEmpty()) cacheIntrospectionData();
121 
122  data = introspectionData;
123 
124  return true;
125 }
126 
127 void DBusBaseNode::Private::handleMethodReply(const TQT_DBusMessage& reply)
128 {
129  connection.send(reply);
130 }
131 
133 {
134  TQDomDocument doc;
135  TQDomElement interfaceElement;
136  TQDomElement nodeElement = doc.createElement("node");
137  if (!objectPath.isEmpty() && objectPath.compare("/") != 0)
138  {
139  nodeElement.setAttribute ( "name", objectPath );
140  }
141  // Introspectable is added by default. Show it only if there is interface
142  if (interfaces.count()>1) {
143  interfaceElement = doc.createElement("interface");
145  nodeElement.appendChild(interfaceElement);
146  }
147 
148  if (!childrenNodes.isEmpty()) {
149  for (TQStringList::Iterator it = childrenNodes.begin(); it != childrenNodes.end(); ++it ) {
150  TQDomElement nodeElement1 = doc.createElement("node");
151  nodeElement1.setAttribute ( "name", *it );
152  nodeElement.appendChild(nodeElement1);
153  }
154  }
155 
156  doc.appendChild(nodeElement);
157 
158  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";
159  introspectionData += doc.toString();
160 }
161 
162 // End of File
163 
virtual bool Introspect(TQString &data, TQT_DBusError &error)
virtual void handleMethodReply(const TQT_DBusMessage &reply)
virtual void handleMethodReply(const TQT_DBusMessage &reply)
virtual bool Introspect(TQString &data, TQT_DBusError &error)
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)