From b1f7f4eabb958878df7e8e66e7c06e4ffb6231b5 Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Thu, 13 Jul 2023 20:37:43 +0000 Subject: [PATCH] Example for using properties in Proxy and Interface fashion Signed-off-by: Emanoil Kotsev --- 60/dbusbaseNode.cpp | 163 +++++++++++++++++++++ 60/dbusbaseNode.h | 45 ++++++ 60/exampleclient.cpp | 94 ++++++++++++ 60/exampleclient.h | 37 +++++ 60/introspectableInterface.cpp | 88 +++++++++++ 60/introspectableInterface.h | 51 +++++++ 60/main.cpp | 30 ++++ 60/propertiesInterface.cpp | 258 +++++++++++++++++++++++++++++++++ 60/propertiesInterface.h | 70 +++++++++ 60/propertiesProxy.cpp | 129 +++++++++++++++++ 60/propertiesProxy.h | 71 +++++++++ 60/serviceInterface.cpp | 83 +++++++++++ 60/serviceInterface.h | 46 ++++++ 60/serviceNode.cpp | 190 ++++++++++++++++++++++++ 60/serviceNode.h | 53 +++++++ 60/serviceProxy.cpp | 113 +++++++++++++++ 60/serviceProxy.h | 60 ++++++++ 60/test1.xml | 31 ++++ 60/testservice.cpp | 145 ++++++++++++++++++ 60/testservice.h | 91 ++++++++++++ build_60.sh | 30 ++++ 21 files changed, 1878 insertions(+) create mode 100644 60/dbusbaseNode.cpp create mode 100644 60/dbusbaseNode.h create mode 100644 60/exampleclient.cpp create mode 100644 60/exampleclient.h create mode 100644 60/introspectableInterface.cpp create mode 100644 60/introspectableInterface.h create mode 100644 60/main.cpp create mode 100644 60/propertiesInterface.cpp create mode 100644 60/propertiesInterface.h create mode 100644 60/propertiesProxy.cpp create mode 100644 60/propertiesProxy.h create mode 100644 60/serviceInterface.cpp create mode 100644 60/serviceInterface.h create mode 100644 60/serviceNode.cpp create mode 100644 60/serviceNode.h create mode 100644 60/serviceProxy.cpp create mode 100644 60/serviceProxy.h create mode 100644 60/test1.xml create mode 100644 60/testservice.cpp create mode 100644 60/testservice.h create mode 100644 build_60.sh diff --git a/60/dbusbaseNode.cpp b/60/dbusbaseNode.cpp new file mode 100644 index 0000000..4bae66e --- /dev/null +++ b/60/dbusbaseNode.cpp @@ -0,0 +1,163 @@ +// File autogenerated + +// declaration include +#include "dbusbaseNode.h" + +// TQt includes +#include +#include +#include + +// TQt D-Bus includes +#include +#include + + +// interface classes includes +#include "dbusbaseNode.h" +#include "introspectableInterface.h" + + +class DBusBaseNode::Private : public org::freedesktop::DBus::IntrospectableInterface +{ +public: + virtual ~Private(); + +public: + TQMap interfaces; + TQString introspectionData; + + TQT_DBusConnection connection; + TQString objectPath; + TQStringList childrenNodes; + +protected: + virtual bool Introspect(TQString& data, TQT_DBusError& error); + + virtual void handleMethodReply(const TQT_DBusMessage& reply); +private: + void cacheIntrospectionData(); +}; + +DBusBaseNode::DBusBaseNode() : TQT_DBusObjectBase(), + m_private(new Private()) +{ +} + +DBusBaseNode::~DBusBaseNode() +{ + unregisterObject(); + + delete m_private; +} + +bool DBusBaseNode::registerObject(const TQT_DBusConnection& connection, const TQString& path) +{ + if (path.isEmpty()) return false; + + if (!m_private->objectPath.isEmpty()) unregisterObject(); + + m_private->connection = connection; + m_private->objectPath = path; + + if (!m_private->connection.registerObject(path, this)) + { + m_private->connection = TQT_DBusConnection(); + m_private->objectPath = TQString(); + + return false; + } + + if (m_private->interfaces.isEmpty()) + { + TQString name = "org.freedesktop.DBus.Introspectable"; + TQT_DBusObjectBase* interface = m_private; + m_private->interfaces.insert(name, interface); + } + + return true; +} + +void DBusBaseNode::addChildNode(const TQString& child) +{ + m_private->childrenNodes.append(child); +} + +void DBusBaseNode::unregisterObject() +{ + if (m_private->objectPath.isEmpty()) return; + + m_private->connection.unregisterObject(m_private->objectPath); + + m_private->connection = TQT_DBusConnection(); + m_private->objectPath = TQString(); +} + +bool DBusBaseNode::handleMethodCall(const TQT_DBusMessage& message) +{ + TQMap::iterator findIt = m_private->interfaces.find(message.interface()); + if (findIt == m_private->interfaces.end()) return false; + + return delegateMethodCall(message, findIt.data()); +} + +DBusBaseNode::Private::~Private() +{ + TQMap::const_iterator it = interfaces.begin(); + TQMap::const_iterator endIt = interfaces.end(); + for (; it != endIt; ++it) + { + TQT_DBusObjectBase* interface = it.data(); + if (interface != this) + delete interface; + } + interfaces.clear(); +} + +bool DBusBaseNode::Private::Introspect(TQString& data, TQT_DBusError& error) +{ + Q_UNUSED(error); + if (introspectionData.isEmpty()) cacheIntrospectionData(); + + data = introspectionData; + + return true; +} + +void DBusBaseNode::Private::handleMethodReply(const TQT_DBusMessage& reply) +{ + connection.send(reply); +} + +void DBusBaseNode::Private::cacheIntrospectionData() +{ + TQDomDocument doc; + TQDomElement interfaceElement; + TQDomElement nodeElement = doc.createElement("node"); + if (!objectPath.isEmpty() && objectPath.compare("/") != 0) + { + nodeElement.setAttribute ( "name", objectPath ); + } + // Introspectable is added by default. Show it only if there is interface + if (interfaces.count()>1) { + interfaceElement = doc.createElement("interface"); + org::freedesktop::DBus::IntrospectableInterface::buildIntrospectionData(interfaceElement); + nodeElement.appendChild(interfaceElement); + } + + if (!childrenNodes.isEmpty()) { + for (TQStringList::Iterator it = childrenNodes.begin(); it != childrenNodes.end(); ++it ) { + TQDomElement nodeElement1 = doc.createElement("node"); + nodeElement1.setAttribute ( "name", *it ); + nodeElement.appendChild(nodeElement1); + } + } + + doc.appendChild(nodeElement); + + introspectionData = "\n"; + introspectionData += doc.toString(); +} + +// End of File + diff --git a/60/dbusbaseNode.h b/60/dbusbaseNode.h new file mode 100644 index 0000000..ce12665 --- /dev/null +++ b/60/dbusbaseNode.h @@ -0,0 +1,45 @@ +// File autogenerated + +#if !defined(DBUSBASENODE_H_INCLUDED) +#define DBUSBASENODE_H_INCLUDED + +// TQt D-Bus includes +#include +#include + +// forward declarations +class TQString; +class TQT_DBusConnection; + + +class DBusBaseNode : public TQT_DBusObjectBase +{ +public: + DBusBaseNode(); + + virtual ~DBusBaseNode(); + + bool registerObject(const TQT_DBusConnection& connection, const TQString& path); + void addChildNode(const TQString& child); + + void unregisterObject(); + +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString& interfaceName) = 0; + +protected: // usually no need to reimplement + virtual bool handleMethodCall(const TQT_DBusMessage& message); + +private: + class Private; + Private* m_private; + +private: // Hiding copy constructor and assignment operator + DBusBaseNode(const DBusBaseNode&); + DBusBaseNode& operator=(const DBusBaseNode&); +}; // class DBusBaseNode + +#endif //DBUSBASENODE_H_INCLUDED + +// End of File + diff --git a/60/exampleclient.cpp b/60/exampleclient.cpp new file mode 100644 index 0000000..830c3c9 --- /dev/null +++ b/60/exampleclient.cpp @@ -0,0 +1,94 @@ +/* + * + * Object Manager implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev + * + * + * This file is part of libtdebluez. + * + * libtdebluez is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libtdebluez is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include +#include +// +//#include +// +#include + +#include "exampleclient.h" +#include "serviceProxy.h" + +/** + * + dbus-send --session --print-reply \ + --dest=org.example.Service \ + /org/example/service \ + org.example.Service.GetValue + * + */ + +#define DBUS_CONNECTION "org.example.Service" + +ExampleClient::ExampleClient() : TQObject() +{ + dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SessionBus, DBUS_CONNECTION); + if (!dBusConn.isConnected()) + { + tqDebug(TQString("Failed to open connection to system message bus: %1").arg(dBusConn.lastError().message())); + exit(-1); + } + + org::example::ServiceProxy *service = new org::example::ServiceProxy("org.example.Service", "/org/example/service"); + service->setConnection(dBusConn); + + TQT_DBusError dbuserror; + TQ_UINT64 outvalue; + if (!service->GetValue(outvalue, dbuserror)) + { + if (dbuserror.isValid()) + { + tqDebug(TQString("GetValue(error) failed: %1").arg(dbuserror.message())); + } + } + + TQ_UINT64 result = service->getSize(dbuserror); + if (dbuserror.isValid()) + { + tqDebug(TQString("GetValue(error) failed: %1").arg(dbuserror.message())); + } + + tqDebug(TQString("GetValue returned: %1").arg(TQString::number(outvalue))); + delete service; +} + +ExampleClient::~ExampleClient() +{ + // close D-Bus connection + dBusConn.closeConnection(DBUS_CONNECTION); +} + +int main(int argc, char **argv) +{ + ExampleClient commandHandler; +} + +#include "exampleclient.moc" +// End of File + diff --git a/60/exampleclient.h b/60/exampleclient.h new file mode 100644 index 0000000..e2161f5 --- /dev/null +++ b/60/exampleclient.h @@ -0,0 +1,37 @@ +/* + * + * Object Manager implementation of bluez5 + * + * Copyright (C) 2018 Emanoil Kotsev + * + * + * This file is part of libtdebluez. + * + * libtdebluez is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libtdebluez is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with kbluetooth; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include +#include + +class ExampleClient : public TQObject +{ +// TQ_OBJECT + +public: + ExampleClient(); + virtual ~ExampleClient(); +private: + TQT_DBusConnection dBusConn; +}; diff --git a/60/introspectableInterface.cpp b/60/introspectableInterface.cpp new file mode 100644 index 0000000..4f2bd84 --- /dev/null +++ b/60/introspectableInterface.cpp @@ -0,0 +1,88 @@ +// File autogenerated + +// declaration include +#include "introspectableInterface.h" + +// TQt includes +#include +#include + +// TQt D-Bus includes +#include +#include + + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +void IntrospectableInterface::buildIntrospectionData(TQDomElement& interfaceElement) +{ + interfaceElement.setAttribute("name", "org.freedesktop.DBus.Introspectable"); + + TQDomDocument document = interfaceElement.ownerDocument(); + TQDomElement methodElement = document.createElement("method"); + methodElement.setAttribute("name", "Introspect"); + + TQDomElement argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "data"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); +} + +TQT_DBusMessage IntrospectableInterface::callIntrospect(const TQT_DBusMessage& message) +{ + TQT_DBusError error; + TQT_DBusMessage reply; + + TQString _data; + + if (Introspect(_data, error)) + { + reply = TQT_DBusMessage::methodReply(message); + reply << TQT_DBusData::fromString(_data); + } + else + { + if (!error.isValid()) + { + tqWarning("Call to implementation of org::freedesktop::DBus::IntrospectableInterface::Introspect returned 'false' but error object is not valid!"); + + error = TQT_DBusError::stdFailed("org.freedesktop.DBus.Introspectable.Introspect execution failed"); + } + + reply = TQT_DBusMessage::methodError(message, error); + } + + return reply; +} + +bool IntrospectableInterface::handleMethodCall(const TQT_DBusMessage& message) +{ + if (message.interface() != "org.freedesktop.DBus.Introspectable") return false; + + if (message.member() == "Introspect") + { + TQT_DBusMessage reply = callIntrospect(message); + handleMethodReply(reply); + + return true; + } + + return false; +} + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +// End of File + diff --git a/60/introspectableInterface.h b/60/introspectableInterface.h new file mode 100644 index 0000000..fc1b5c2 --- /dev/null +++ b/60/introspectableInterface.h @@ -0,0 +1,51 @@ +// File autogenerated + +#if !defined(INTROSPECTABLEINTERFACE_H_INCLUDED) +#define INTROSPECTABLEINTERFACE_H_INCLUDED + +// TQt D-Bus includes +#include +#include + +// forward declarations +class TQDomElement; +class TQString; +class TQT_DBusError; + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +class IntrospectableInterface : public TQT_DBusObjectBase +{ +public: + virtual ~IntrospectableInterface() {} + + static void buildIntrospectionData(TQDomElement& interfaceElement); + +protected: + virtual bool Introspect(TQString& data, TQT_DBusError& error) = 0; + +protected: // implement sending replies + virtual void handleMethodReply(const TQT_DBusMessage& reply) = 0; + +protected: // usually no need to reimplement + virtual bool handleMethodCall(const TQT_DBusMessage& message); + + TQT_DBusMessage callIntrospect(const TQT_DBusMessage& message); + +}; // class IntrospectableInterface + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +#endif //INTROSPECTABLEINTERFACE_H_INCLUDED + +// End of File + diff --git a/60/main.cpp b/60/main.cpp new file mode 100644 index 0000000..f31c4e9 --- /dev/null +++ b/60/main.cpp @@ -0,0 +1,30 @@ +#include "testservice.h" +#include +#include + +int main(int argc, char** argv) +{ + TQApplication app(argc, argv, false); + TQT_DBusConnection connection = TQT_DBusConnection::sessionBus(); +// TQT_DBusConnection connection = TQT_DBusConnection::systemBus(); + if (!connection.isConnected()) + tqFatal("Cannot connect to session bus"); + // try to get a specific service name + if (!connection.requestName("org.example.Service")) + { + tqWarning("Requesting name 'org.example.Service' failed. " + "Will only be addressable through unique name '%s'", + connection.uniqueName().local8Bit().data()); + } + else + { + tqDebug("Requesting name 'org.example.Service' successfull"); + } + + RootService rootService(connection); + OrgService orgService(connection); + ExampleService exampleService(connection); + MultiInterfaceService service(connection); + + return app.exec(); +} diff --git a/60/propertiesInterface.cpp b/60/propertiesInterface.cpp new file mode 100644 index 0000000..a3bc48b --- /dev/null +++ b/60/propertiesInterface.cpp @@ -0,0 +1,258 @@ +// File autogenerated + +// declaration include +#include "propertiesInterface.h" + +// TQt includes +#include +#include +#include +#include + +// TQt D-Bus includes +#include +#include +#include +#include +#include +#include + + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +void PropertiesInterface::buildIntrospectionData(TQDomElement& interfaceElement) +{ + interfaceElement.setAttribute("name", "org.freedesktop.DBus.Properties"); + + TQDomDocument document = interfaceElement.ownerDocument(); + TQDomElement methodElement = document.createElement("method"); + methodElement.setAttribute("name", "Get"); + + TQDomElement argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "interface"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "name"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "value"); + argumentElement.setAttribute("type", "v"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); + + methodElement = document.createElement("method"); + methodElement.setAttribute("name", "Set"); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "interface"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "name"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "value"); + argumentElement.setAttribute("type", "v"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); + + methodElement = document.createElement("method"); + methodElement.setAttribute("name", "GetAll"); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "interface"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "in"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "properties"); + argumentElement.setAttribute("type", "a{sv}"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); + + methodElement = document.createElement("signal"); + methodElement.setAttribute("name", "PropertiesChanged"); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "interface"); + argumentElement.setAttribute("type", "s"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "changed_properties"); + argumentElement.setAttribute("type", "a{sv}"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "invalidated_properties"); + argumentElement.setAttribute("type", "as"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); +} + +bool PropertiesInterface::emitPropertiesChanged(const TQString& interface, const TQMap< TQString, TQT_DBusVariant >& changed_properties, const TQStringList& invalidated_properties) +{ + TQString path = objectPath(); + Q_ASSERT(!path.isEmpty()); + + TQT_DBusMessage message = TQT_DBusMessage::signal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged"); + + message << TQT_DBusData::fromString(interface); + message << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap< TQString >(changed_properties)); + message << TQT_DBusData::fromList((invalidated_properties)); + + return handleSignalSend(message); +} + + +TQT_DBusMessage PropertiesInterface::callGet(const TQT_DBusMessage& message) +{ + TQT_DBusError error; + TQT_DBusMessage reply; + + TQString _interface = message[0].toString(); + TQString _name = message[1].toString(); + TQT_DBusVariant _value; + + if (Get(_interface, _name, _value, error)) + { + reply = TQT_DBusMessage::methodReply(message); + reply << TQT_DBusData::fromVariant(_value); + } + else + { + if (!error.isValid()) + { + tqWarning("Call to implementation of org::freedesktop::DBus::PropertiesInterface::Get returned 'false' but error object is not valid!"); + + error = TQT_DBusError::stdFailed("org.freedesktop.DBus.Properties.Get execution failed"); + } + + reply = TQT_DBusMessage::methodError(message, error); + } + + return reply; +} + +TQT_DBusMessage PropertiesInterface::callSet(const TQT_DBusMessage& message) +{ + TQT_DBusError error; + TQT_DBusMessage reply; + + TQString _interface = message[0].toString(); + TQString _name = message[1].toString(); + TQT_DBusVariant _value = message[2].toVariant(); + + if (Set(_interface, _name, _value, error)) + { + reply = TQT_DBusMessage::methodReply(message); + } + else + { + if (!error.isValid()) + { + tqWarning("Call to implementation of org::freedesktop::DBus::PropertiesInterface::Set returned 'false' but error object is not valid!"); + + error = TQT_DBusError::stdFailed("org.freedesktop.DBus.Properties.Set execution failed"); + } + + reply = TQT_DBusMessage::methodError(message, error); + } + + return reply; +} + +TQT_DBusMessage PropertiesInterface::callGetAll(const TQT_DBusMessage& message) +{ + TQT_DBusError error; + TQT_DBusMessage reply; + + TQString _interface = message[0].toString(); + TQMap< TQString, TQT_DBusVariant > _properties; + + if (GetAll(_interface, _properties, error)) + { + reply = TQT_DBusMessage::methodReply(message); + reply << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap< TQString >(_properties)); + } + else + { + if (!error.isValid()) + { + tqWarning("Call to implementation of org::freedesktop::DBus::PropertiesInterface::GetAll returned 'false' but error object is not valid!"); + + error = TQT_DBusError::stdFailed("org.freedesktop.DBus.Properties.GetAll execution failed"); + } + + reply = TQT_DBusMessage::methodError(message, error); + } + + return reply; +} + +bool PropertiesInterface::handleMethodCall(const TQT_DBusMessage& message) +{ + if (message.interface() != "org.freedesktop.DBus.Properties") return false; + + if (message.member() == "Get") + { + TQT_DBusMessage reply = callGet(message); + handleMethodReply(reply); + + return true; + } + + if (message.member() == "Set") + { + TQT_DBusMessage reply = callSet(message); + handleMethodReply(reply); + + return true; + } + + if (message.member() == "GetAll") + { + TQT_DBusMessage reply = callGetAll(message); + handleMethodReply(reply); + + return true; + } + + return false; +} + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +// End of File + diff --git a/60/propertiesInterface.h b/60/propertiesInterface.h new file mode 100644 index 0000000..39286eb --- /dev/null +++ b/60/propertiesInterface.h @@ -0,0 +1,70 @@ +// File autogenerated + +#if !defined(PROPERTIESINTERFACE_H_INCLUDED) +#define PROPERTIESINTERFACE_H_INCLUDED + +// TQt D-Bus includes +#include +#include + +// forward declarations +class TQDomElement; +class TQString; +class TQStringList; +class TQT_DBusError; +class TQT_DBusVariant; +template class TQMap; + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +class PropertiesInterface : public TQT_DBusObjectBase +{ +public: + virtual ~PropertiesInterface() {} + + static void buildIntrospectionData(TQDomElement& interfaceElement); + +protected: // implement sending signals + virtual bool handleSignalSend(const TQT_DBusMessage& reply) = 0; + virtual TQString objectPath() const = 0; + +protected: // for sending D-Bus signals + virtual bool emitPropertiesChanged(const TQString& interface, const TQMap< TQString, TQT_DBusVariant >& changed_properties, const TQStringList& invalidated_properties); + + +protected: + virtual bool Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error) = 0; + + virtual bool Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error) = 0; + + virtual bool GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error) = 0; + +protected: // implement sending replies + virtual void handleMethodReply(const TQT_DBusMessage& reply) = 0; + +protected: // usually no need to reimplement + virtual bool handleMethodCall(const TQT_DBusMessage& message); + + TQT_DBusMessage callGet(const TQT_DBusMessage& message); + + TQT_DBusMessage callSet(const TQT_DBusMessage& message); + + TQT_DBusMessage callGetAll(const TQT_DBusMessage& message); + +}; // class PropertiesInterface + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +#endif //PROPERTIESINTERFACE_H_INCLUDED + +// End of File + diff --git a/60/propertiesProxy.cpp b/60/propertiesProxy.cpp new file mode 100644 index 0000000..dae770d --- /dev/null +++ b/60/propertiesProxy.cpp @@ -0,0 +1,129 @@ +// File autogenerated + +// declaration include +#include "propertiesProxy.h" + +// TQt includes +#include +#include +#include + +// TQt D-Bus includes +#include +#include +#include +#include +#include +#include +#include + + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +PropertiesProxy::PropertiesProxy(const TQString& service, const TQString& path, TQObject* parent, const char* name) + : TQObject(parent, name), + m_baseProxy(new TQT_DBusProxy()) +{ + m_baseProxy->setInterface("org.freedesktop.DBus.Properties"); + m_baseProxy->setPath(path); + m_baseProxy->setService(service); + + TQObject::connect(m_baseProxy, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)), + this, TQT_SLOT(slotHandleDBusSignal(const TQT_DBusMessage&))); +} + +PropertiesProxy::~PropertiesProxy() +{ + delete m_baseProxy; +} + +void PropertiesProxy::setConnection(const TQT_DBusConnection& connection) +{ + m_baseProxy->setConnection(connection); +} + +bool PropertiesProxy::Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error) +{ + TQValueList parameters; + + parameters << TQT_DBusData::fromString(interface); + parameters << TQT_DBusData::fromString(name); + + TQT_DBusMessage reply = m_baseProxy->sendWithReply("Get", parameters, &error); + + if (reply.type() != TQT_DBusMessage::ReplyMessage) return false; + + if (reply.count() != 1) return false; + + bool ok = false; + + value = reply.front().toVariant(&ok); + if (!ok) return false; + + return true; +} + +bool PropertiesProxy::Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error) +{ + TQValueList parameters; + + parameters << TQT_DBusData::fromString(interface); + parameters << TQT_DBusData::fromString(name); + parameters << TQT_DBusData::fromVariant(value); + + TQT_DBusMessage reply = m_baseProxy->sendWithReply("Set", parameters, &error); + + if (reply.type() != TQT_DBusMessage::ReplyMessage) return false; + return true; +} + +bool PropertiesProxy::GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error) +{ + TQValueList parameters; + + parameters << TQT_DBusData::fromString(interface); + + TQT_DBusMessage reply = m_baseProxy->sendWithReply("GetAll", parameters, &error); + + if (reply.type() != TQT_DBusMessage::ReplyMessage) return false; + + if (reply.count() != 1) return false; + + bool ok = false; + + bool subOK = false; + + properties = reply.front().toStringKeyMap(&ok).toVariantMap(&subOK); + if (!subOK) return false; + if (!ok) return false; + + return true; +} + +void PropertiesProxy::slotHandleDBusSignal(const TQT_DBusMessage& message) +{ + if (message.member() == "PropertiesChanged") + { + TQString _interface = message[0].toString(); + TQMap< TQString, TQT_DBusVariant > _changed_properties = message[1].toStringKeyMap().toVariantMap(); + TQStringList _invalidated_properties = message[2].toList().toTQStringList(); + + emit PropertiesChanged(_interface, _changed_properties, _invalidated_properties); + } +} + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +#include "propertiesProxy.moc" + +// End of File + diff --git a/60/propertiesProxy.h b/60/propertiesProxy.h new file mode 100644 index 0000000..c38c68c --- /dev/null +++ b/60/propertiesProxy.h @@ -0,0 +1,71 @@ +// File autogenerated + +#if !defined(PROPERTIESPROXY_H_INCLUDED) +#define PROPERTIESPROXY_H_INCLUDED + +// TQt includes +#include + +// TQt D-Bus includes +#include + +// forward declarations +class TQString; +class TQStringList; +class TQT_DBusConnection; +class TQT_DBusError; +class TQT_DBusMessage; +class TQT_DBusProxy; +class TQT_DBusVariant; +template class TQMap; + +namespace org +{ +namespace freedesktop +{ +namespace DBus +{ + +class PropertiesProxy : public TQObject +{ + Q_OBJECT + +public: + PropertiesProxy(const TQString& service, const TQString& path, TQObject* parent = 0, const char* name = 0); + + virtual ~PropertiesProxy(); + + void setConnection(const TQT_DBusConnection& connection); + +signals: + void PropertiesChanged(const TQString& interface, const TQMap< TQString, TQT_DBusVariant >& changed_properties, const TQStringList& invalidated_properties); + + +public: + virtual bool Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error); + + virtual bool Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error); + + virtual bool GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error); + +protected slots: // usually no need to reimplement + virtual void slotHandleDBusSignal(const TQT_DBusMessage& message); + +protected: + TQT_DBusProxy* m_baseProxy; + +private: // Hiding copy constructor and assignment operator + PropertiesProxy(const PropertiesProxy&); + PropertiesProxy& operator=(const PropertiesProxy&); +}; // class PropertiesProxy + +}; // namespace DBus + +}; // namespace freedesktop + +}; // namespace org + +#endif //PROPERTIESPROXY_H_INCLUDED + +// End of File + diff --git a/60/serviceInterface.cpp b/60/serviceInterface.cpp new file mode 100644 index 0000000..21a33c1 --- /dev/null +++ b/60/serviceInterface.cpp @@ -0,0 +1,83 @@ +// File autogenerated + +// declaration include +#include "serviceInterface.h" + +// TQt includes +#include + +// TQt D-Bus includes +#include +#include + + +namespace org +{ +namespace example +{ + +void ServiceInterface::buildIntrospectionData(TQDomElement& interfaceElement) +{ + interfaceElement.setAttribute("name", "org.example.Service"); + + TQDomDocument document = interfaceElement.ownerDocument(); + TQDomElement methodElement = document.createElement("method"); + methodElement.setAttribute("name", "GetValue"); + + TQDomElement argumentElement = document.createElement("arg"); + argumentElement.setAttribute("name", "output"); + argumentElement.setAttribute("type", "t"); + argumentElement.setAttribute("direction", "out"); + methodElement.appendChild(argumentElement); + + interfaceElement.appendChild(methodElement); +} + +TQT_DBusMessage ServiceInterface::callGetValue(const TQT_DBusMessage& message) +{ + TQT_DBusError error; + TQT_DBusMessage reply; + + TQ_UINT64 _output; + + if (GetValue(_output, error)) + { + reply = TQT_DBusMessage::methodReply(message); + reply << TQT_DBusData::fromUInt64(_output); + } + else + { + if (!error.isValid()) + { + tqWarning("Call to implementation of org::example::ServiceInterface::GetValue returned 'false' but error object is not valid!"); + + error = TQT_DBusError::stdFailed("org.example.Service.GetValue execution failed"); + } + + reply = TQT_DBusMessage::methodError(message, error); + } + + return reply; +} + +bool ServiceInterface::handleMethodCall(const TQT_DBusMessage& message) +{ + if (message.interface() != "org.example.Service") return false; + + if (message.member() == "GetValue") + { + TQT_DBusMessage reply = callGetValue(message); + handleMethodReply(reply); + + return true; + } + + return false; +} + +}; // namespace example + +}; // namespace org + +// End of File + diff --git a/60/serviceInterface.h b/60/serviceInterface.h new file mode 100644 index 0000000..24a7ea3 --- /dev/null +++ b/60/serviceInterface.h @@ -0,0 +1,46 @@ +// File autogenerated + +#if !defined(SERVICEINTERFACE_H_INCLUDED) +#define SERVICEINTERFACE_H_INCLUDED + +// TQt D-Bus includes +#include +#include + +// forward declarations +class TQDomElement; +class TQT_DBusError; + +namespace org +{ +namespace example +{ + +class ServiceInterface : public TQT_DBusObjectBase +{ +public: + virtual ~ServiceInterface() {} + + static void buildIntrospectionData(TQDomElement& interfaceElement); + +protected: + virtual bool GetValue(TQ_UINT64& output, TQT_DBusError& error) = 0; + +protected: // implement sending replies + virtual void handleMethodReply(const TQT_DBusMessage& reply) = 0; + +protected: // usually no need to reimplement + virtual bool handleMethodCall(const TQT_DBusMessage& message); + + TQT_DBusMessage callGetValue(const TQT_DBusMessage& message); + +}; // class ServiceInterface + +}; // namespace example + +}; // namespace org + +#endif //SERVICEINTERFACE_H_INCLUDED + +// End of File + diff --git a/60/serviceNode.cpp b/60/serviceNode.cpp new file mode 100644 index 0000000..a1d4dd0 --- /dev/null +++ b/60/serviceNode.cpp @@ -0,0 +1,190 @@ +// File autogenerated + +// declaration include +#include "serviceNode.h" + +// TQt includes +#include +#include +#include + +// TQt D-Bus includes +#include +#include + + +// interface classes includes +#include "serviceInterface.h" +#include "propertiesInterface.h" +#include "introspectableInterface.h" + +namespace org +{ +namespace example +{ + +class serviceNode::Private : public org::freedesktop::DBus::IntrospectableInterface +{ +public: + virtual ~Private(); + +public: + TQMap interfaces; + TQString introspectionData; + + TQT_DBusConnection connection; + TQString objectPath; + TQStringList childrenNodes; + +protected: + virtual bool Introspect(TQString& data, TQT_DBusError& error); + + virtual void handleMethodReply(const TQT_DBusMessage& reply); +private: + void cacheIntrospectionData(); +}; + +serviceNode::serviceNode() : TQT_DBusObjectBase(), + m_private(new Private()) +{ +} + +serviceNode::~serviceNode() +{ + unregisterObject(); + + delete m_private; +} + +bool serviceNode::registerObject(const TQT_DBusConnection& connection, const TQString& path) +{ + if (path.isEmpty()) return false; + + if (!m_private->objectPath.isEmpty()) unregisterObject(); + + m_private->connection = connection; + m_private->objectPath = path; + + if (!m_private->connection.registerObject(path, this)) + { + m_private->connection = TQT_DBusConnection(); + m_private->objectPath = TQString(); + + return false; + } + + if (m_private->interfaces.isEmpty()) + { + TQString name = "org.freedesktop.DBus.Introspectable"; + TQT_DBusObjectBase* interface = m_private; + m_private->interfaces.insert(name, interface); + + name = "org.example.Service"; + interface = createInterface(name); + Q_ASSERT(interface != 0); + m_private->interfaces.insert(name, interface); + + name = "org.freedesktop.DBus.Properties"; + interface = createInterface(name); + Q_ASSERT(interface != 0); + m_private->interfaces.insert(name, interface); + } + + return true; +} + +void serviceNode::addChildNode(const TQString& child) +{ + m_private->childrenNodes.append(child); +} + +void serviceNode::unregisterObject() +{ + if (m_private->objectPath.isEmpty()) return; + + m_private->connection.unregisterObject(m_private->objectPath); + + m_private->connection = TQT_DBusConnection(); + m_private->objectPath = TQString(); +} + +bool serviceNode::handleMethodCall(const TQT_DBusMessage& message) +{ + TQMap::iterator findIt = m_private->interfaces.find(message.interface()); + if (findIt == m_private->interfaces.end()) return false; + + return delegateMethodCall(message, findIt.data()); +} + +serviceNode::Private::~Private() +{ + TQMap::const_iterator it = interfaces.begin(); + TQMap::const_iterator endIt = interfaces.end(); + for (; it != endIt; ++it) + { + TQT_DBusObjectBase* interface = it.data(); + if (interface != this) + delete interface; + } + interfaces.clear(); +} + +bool serviceNode::Private::Introspect(TQString& data, TQT_DBusError& error) +{ + Q_UNUSED(error); + if (introspectionData.isEmpty()) cacheIntrospectionData(); + + data = introspectionData; + + return true; +} + +void serviceNode::Private::handleMethodReply(const TQT_DBusMessage& reply) +{ + connection.send(reply); +} + +void serviceNode::Private::cacheIntrospectionData() +{ + TQDomDocument doc; + TQDomElement interfaceElement; + TQDomElement nodeElement = doc.createElement("node"); + if (!objectPath.isEmpty() && objectPath.compare("/") != 0) + { + nodeElement.setAttribute ( "name", objectPath ); + } + // Introspectable is added by default. Show it only if there is interface + if (interfaces.count()>1) { + interfaceElement = doc.createElement("interface"); + org::freedesktop::DBus::IntrospectableInterface::buildIntrospectionData(interfaceElement); + nodeElement.appendChild(interfaceElement); + } + + interfaceElement = doc.createElement("interface"); + org::example::ServiceInterface::buildIntrospectionData(interfaceElement); + nodeElement.appendChild(interfaceElement); + + interfaceElement = doc.createElement("interface"); + org::freedesktop::DBus::PropertiesInterface::buildIntrospectionData(interfaceElement); + nodeElement.appendChild(interfaceElement); + + if (!childrenNodes.isEmpty()) { + for (TQStringList::Iterator it = childrenNodes.begin(); it != childrenNodes.end(); ++it ) { + TQDomElement nodeElement1 = doc.createElement("node"); + nodeElement1.setAttribute ( "name", *it ); + nodeElement.appendChild(nodeElement1); + } + } + + doc.appendChild(nodeElement); + + introspectionData = "\n"; + introspectionData += doc.toString(); +} + +}; // namespace example + +}; // namespace org + +// End of File + diff --git a/60/serviceNode.h b/60/serviceNode.h new file mode 100644 index 0000000..21bdf02 --- /dev/null +++ b/60/serviceNode.h @@ -0,0 +1,53 @@ +// File autogenerated + +#if !defined(SERVICENODE_H_INCLUDED) +#define SERVICENODE_H_INCLUDED + +// TQt D-Bus includes +#include +#include + +// forward declarations +class TQString; +class TQT_DBusConnection; + +namespace org +{ +namespace example +{ + +class serviceNode : public TQT_DBusObjectBase +{ +public: + serviceNode(); + + virtual ~serviceNode(); + + bool registerObject(const TQT_DBusConnection& connection, const TQString& path); + void addChildNode(const TQString& child); + + void unregisterObject(); + +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString& interfaceName) = 0; + +protected: // usually no need to reimplement + virtual bool handleMethodCall(const TQT_DBusMessage& message); + +private: + class Private; + Private* m_private; + +private: // Hiding copy constructor and assignment operator + serviceNode(const serviceNode&); + serviceNode& operator=(const serviceNode&); +}; // class serviceNode + +}; // namespace example + +}; // namespace org + +#endif //SERVICENODE_H_INCLUDED + +// End of File + diff --git a/60/serviceProxy.cpp b/60/serviceProxy.cpp new file mode 100644 index 0000000..18c0ab8 --- /dev/null +++ b/60/serviceProxy.cpp @@ -0,0 +1,113 @@ +// File autogenerated + +// declaration include +#include "serviceProxy.h" + +// TQt D-Bus includes +#include +#include +#include +#include +#include + + +namespace org +{ +namespace example +{ + +ServiceProxy::ServiceProxy(const TQString& service, const TQString& path, TQObject* parent, const char* name) + : TQObject(parent, name), + m_baseProxy(new TQT_DBusProxy()) +{ + m_baseProxy->setInterface("org.example.Service"); + m_baseProxy->setPath(path); + m_baseProxy->setService(service); + +} + +ServiceProxy::~ServiceProxy() +{ + delete m_baseProxy; +} + +void ServiceProxy::setConnection(const TQT_DBusConnection& connection) +{ + m_baseProxy->setConnection(connection); +} + +bool ServiceProxy::GetValue(TQ_UINT64& output, TQT_DBusError& error) +{ + TQValueList parameters; + + + TQT_DBusMessage reply = m_baseProxy->sendWithReply("GetValue", parameters, &error); + + if (reply.type() != TQT_DBusMessage::ReplyMessage) return false; + + if (reply.count() != 1) return false; + + bool ok = false; + + output = reply.front().toUInt64(&ok); + if (!ok) return false; + + return true; +} + +void ServiceProxy::setDBusProperty(const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error) +{ + TQT_DBusConnection connection = m_baseProxy->connection(); + + TQT_DBusMessage message = TQT_DBusMessage::methodCall(m_baseProxy->service(), m_baseProxy->path(), "org.freedesktop.DBus.Properties", "Set"); + + message << TQT_DBusData::fromString(m_baseProxy->interface()); + message << TQT_DBusData::fromString(name); + message << TQT_DBusData::fromVariant(value); + + connection.sendWithReply(message, &error); +} + +TQT_DBusVariant ServiceProxy::getDBusProperty(const TQString& name, TQT_DBusError& error) const +{ + TQT_DBusConnection connection = m_baseProxy->connection(); + + TQT_DBusMessage message = TQT_DBusMessage::methodCall(m_baseProxy->service(), m_baseProxy->path(), "org.freedesktop.DBus.Properties", "Get"); + + message << TQT_DBusData::fromString(m_baseProxy->interface()); + message << TQT_DBusData::fromString(name); + + TQT_DBusMessage reply = connection.sendWithReply(message, &error); + + if (reply.type() != TQT_DBusMessage::ReplyMessage) return TQT_DBusVariant(); + if (reply.count() != 1) return TQT_DBusVariant(); + + bool ok = false; + TQT_DBusVariant value = reply.front().toVariant(&ok); + if (!ok) return TQT_DBusVariant(); + + return value; +} + +TQ_UINT64 ServiceProxy::getSize(TQT_DBusError& error) const +{ + TQT_DBusVariant variant = getDBusProperty("Size", error); + + if (error.isValid()) return TQ_UINT64(); + + bool ok = false; + + TQ_UINT64 result = variant.value.toUInt64(&ok); + if (!ok) {} + + return result; +} + +}; // namespace example + +}; // namespace org + +#include "serviceProxy.moc" + +// End of File + diff --git a/60/serviceProxy.h b/60/serviceProxy.h new file mode 100644 index 0000000..1785470 --- /dev/null +++ b/60/serviceProxy.h @@ -0,0 +1,60 @@ +// File autogenerated + +#if !defined(SERVICEPROXY_H_INCLUDED) +#define SERVICEPROXY_H_INCLUDED + +// TQt includes +#include + +// TQt D-Bus includes +#include + +// forward declarations +class TQString; +class TQT_DBusConnection; +class TQT_DBusError; +class TQT_DBusMessage; +class TQT_DBusProxy; +class TQT_DBusVariant; + +namespace org +{ +namespace example +{ + +class ServiceProxy : public TQObject +{ + Q_OBJECT + +public: + ServiceProxy(const TQString& service, const TQString& path, TQObject* parent = 0, const char* name = 0); + + virtual ~ServiceProxy(); + + void setConnection(const TQT_DBusConnection& connection); + +public: + virtual bool GetValue(TQ_UINT64& output, TQT_DBusError& error); + +public: + virtual void setDBusProperty(const TQString& name, const TQT_DBusVariant& variant, TQT_DBusError& error); + virtual TQT_DBusVariant getDBusProperty(const TQString& name, TQT_DBusError& error) const; + + virtual TQ_UINT64 getSize(TQT_DBusError& error) const; + +protected: + TQT_DBusProxy* m_baseProxy; + +private: // Hiding copy constructor and assignment operator + ServiceProxy(const ServiceProxy&); + ServiceProxy& operator=(const ServiceProxy&); +}; // class ServiceProxy + +}; // namespace example + +}; // namespace org + +#endif //SERVICEPROXY_H_INCLUDED + +// End of File + diff --git a/60/test1.xml b/60/test1.xml new file mode 100644 index 0000000..51cfb28 --- /dev/null +++ b/60/test1.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/60/testservice.cpp b/60/testservice.cpp new file mode 100644 index 0000000..8ac54f4 --- /dev/null +++ b/60/testservice.cpp @@ -0,0 +1,145 @@ +#include "testservice.h" +#include + +// TQt includes +#include +#include +#include +#include +#include +#include +#include + +Properties1::Properties1(TQT_DBusConnection &conn) + : m_connection(&conn) +{ + +} + +Properties1::~Properties1(){ +} + +void Properties1::handleMethodReply(const TQT_DBusMessage& reply) { + m_connection->send(reply); + // do something +} + +bool Properties1::Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error) { + // get interface + // get param name from interface + value.value = TQT_DBusData::fromUInt64(131719); + value.signature = value.value.buildDBusSignature(); + return true; +} + +bool Properties1::Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error) { + // get interface + // get param name from interface + // do something + return true; +} + +bool Properties1::GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error) { + // get interface + // get param name from interface + // do something + return true; +} + +bool Properties1::handleSignalSend(const TQT_DBusMessage& reply) { + // do something + return true; +} + +TQString Properties1::objectPath() const { + // do something + return TQString(); +} + +TQT_DBusObjectBase* Properties1::createInterface(const TQString& interface) { + if (interface == "org.example.Service") + return (TQT_DBusObjectBase*) new Interface1((*m_connection)); + else + return (TQT_DBusObjectBase*) this; +} + +Interface1::Interface1(TQT_DBusConnection &conn) + : m_connection(&conn) +{ + testval = 123456; +} + +Interface1::~Interface1(){ +} + +void Interface1::handleMethodReply(const TQT_DBusMessage& reply) { + // do something + m_connection->send(reply); +} + +bool Interface1::GetValue(TQ_UINT64& output, TQT_DBusError& error) { + output = testval; + return true; +} + +RootService::RootService(TQT_DBusConnection &connection ) + : DBusBaseNode(), m_connection(connection) +{ + registerObject(m_connection,"/"); + addChildNode("org"); +} + +RootService::~RootService(){ +} + +TQT_DBusObjectBase* RootService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +OrgService::OrgService(TQT_DBusConnection &connection ) + : DBusBaseNode(), m_connection(connection) +{ + registerObject(m_connection,"/org"); + addChildNode("example"); +} + +OrgService::~OrgService(){ +} + +TQT_DBusObjectBase* OrgService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +ExampleService::ExampleService(TQT_DBusConnection &connection ) + : DBusBaseNode(), m_connection(connection) +{ + registerObject(m_connection,"/org/example"); + addChildNode("service"); +} + +ExampleService::~ExampleService(){ +} + +TQT_DBusObjectBase* ExampleService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} + +MultiInterfaceService::MultiInterfaceService(TQT_DBusConnection &connection ) + : org::example::serviceNode(), m_connection(connection) +{ + m_interfaces.insert("org.freedesktop.DBus.Introspectable", this); + m_interfaces.insert("org.example.Service", new Interface1(m_connection)); + m_interfaces.insert("org.freedesktop.DBus.Properties", new Properties1(m_connection)); + registerObject(m_connection,"/org/example/service"); +} + +MultiInterfaceService::~MultiInterfaceService(){ +} + +TQT_DBusObjectBase* MultiInterfaceService::createInterface(const TQString& interfaceName) +{ + return (TQT_DBusObjectBase*) m_interfaces[interfaceName]; +} diff --git a/60/testservice.h b/60/testservice.h new file mode 100644 index 0000000..8f59660 --- /dev/null +++ b/60/testservice.h @@ -0,0 +1,91 @@ + +#include +#include +#include +#include +#include "serviceInterface.h" +#include "serviceNode.h" +#include "dbusbaseNode.h" +#include "propertiesInterface.h" + +class Properties1 : public org::freedesktop::DBus::PropertiesInterface +{ +public: + Properties1(TQT_DBusConnection&); + ~Properties1(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); + bool Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error); + bool Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error); + bool GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error); + void handleMethodReply(const TQT_DBusMessage& reply); + bool handleSignalSend(const TQT_DBusMessage& reply); + TQString objectPath() const; + +private: + TQMap m_interfaces; + TQT_DBusConnection *m_connection; +}; + + +class Interface1 : public org::example::ServiceInterface +{ +public: + Interface1(TQT_DBusConnection&); + virtual ~Interface1(); +protected: // implement methods + virtual bool GetValue(TQ_UINT64& output, TQT_DBusError& error); +protected: // implement sending replies + virtual void handleMethodReply(const TQT_DBusMessage& reply); +private: + TQT_DBusConnection *m_connection; + std::uint64_t testval; +}; + +class RootService : public DBusBaseNode +{ +public: + RootService(TQT_DBusConnection&); + ~RootService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap m_interfaces; + TQT_DBusConnection m_connection; +}; + +class OrgService : public DBusBaseNode +{ +public: + OrgService(TQT_DBusConnection&); + ~OrgService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap m_interfaces; + TQT_DBusConnection m_connection; +}; + +class ExampleService : DBusBaseNode +{ +public: + ExampleService(TQT_DBusConnection&); + ~ExampleService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap m_interfaces; + TQT_DBusConnection m_connection; +}; + +class MultiInterfaceService : public org::example::serviceNode +{ +public: + MultiInterfaceService(TQT_DBusConnection&); + ~MultiInterfaceService(); +protected: + virtual TQT_DBusObjectBase* createInterface(const TQString&); +private: + TQMap m_interfaces; + TQT_DBusConnection m_connection; +}; diff --git a/build_60.sh b/build_60.sh new file mode 100644 index 0000000..0161eef --- /dev/null +++ b/build_60.sh @@ -0,0 +1,30 @@ +/usr/bin/g++ -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time \ + -D_FORTIFY_SOURCE=2 -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT \ + -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT -include tqt.h -I/usr/include/tqt3 \ + -I/opt/trinity/include/ -I/usr/include/dbus-1-tqt -I/usr/include/tqt -I -DQT_NO_ASCII_CAST \ + -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT \ + -D_REENTRANT -include tqt.h -g -Wl,-z,relro main.cpp testservice.cpp \ + dbusbaseNode.cpp serviceNode.cpp introspectableInterface.cpp \ + propertiesInterface.cpp propertiesProxy.cpp serviceInterface.cpp \ + -o tqdbusexample -ldbus-1-tqt \ + /opt/trinity/lib/libtdeparts.so /opt/trinity/lib/libtdeio.so \ + /opt/trinity/lib/libtdecore.so -ltqt -ltqt-mt -lXrender -lX11 -lc \ + /usr/lib/x86_64-linux-gnu/libz.so -lidn -lXcomposite -lICE -lSM -lutil -lr -lacl -lattr -ltqui + +# build client example +tmoc serviceProxy.h -o serviceProxy.moc +tmoc exampleclient.h -o exampleclient.moc +tmoc propertiesProxy.h -o propertiesProxy.moc + +/usr/bin/g++ -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time \ + -D_FORTIFY_SOURCE=2 -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT \ + -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT -include tqt.h -I. -I/usr/include/tqt3 \ + -I/opt/trinity/include/ -I/usr/include/dbus-1-tqt -I/usr/include/tqt -I -DQT_NO_ASCII_CAST \ + -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT \ + -D_REENTRANT -include tqt.h -g -Wl,-z,relro testservice.cpp dbusbaseNode.cpp serviceNode.cpp \ + propertiesInterface.cpp propertiesProxy.cpp serviceProxy.cpp serviceInterface.cpp \ + introspectableInterface.cpp exampleclient.cpp \ + -o tqdbusexample_client -ldbus-1-tqt \ + /opt/trinity/lib/libtdeparts.so /opt/trinity/lib/libtdeio.so \ + /opt/trinity/lib/libtdecore.so -ltqt -ltqt-mt -lXrender -lX11 -lc \ + /usr/lib/x86_64-linux-gnu/libz.so -lidn -lXcomposite -lICE -lSM -lutil -lr -lacl -lattr -ltqui