Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a QDbus Object with multiple interfaces?

How to create a QDbus Object with multiple interfaces?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 747 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devel
    wrote on last edited by devel
    #1

    There is a Telepathy API where a 'Client' must implement at least two dbus interfaces.

    In the Empathy messenger has objects that look like this (if you inspect with D-feet):

    /org/freedesktop/Telepathy/Client/Empathy/Auth
    |-org.freedesktop.DBus.Introspectable
    |-org.freedesktop.DBus.Properties
    |-org.freedesktop.DBus.Properties
    |-org.freedesktop.Telepathy.Client.Approuver
    |-org.freedesktop.Telepathy.Client.Handler
    |-org.freedesktop.Telepathy.Client.Interface.Requests
    |-org.freedesktop.Telepathy.Client.Observer
    

    But I'm managing to only create some separate objects:

    /org/freedesktop/Telepathy/Client/MyClient/Handler
    |-org.freedesktop.DBus.Introspectable
    |-org.freedesktop.DBus.Peer
    |-org.freedesktop.DBus.Properties
    |-org.freedesktop.Telepathy.Client.Handler
    
    /org/freedesktop/Telepathy/Client/MyClient/Observer
    |-org.freedesktop.DBus.Introspectable
    |-org.freedesktop.DBus.Peer
    |-org.freedesktop.DBus.Properties
    |-org.freedesktop.Telepathy.Client.Observer
    

    I've done the generation from the Telepathy spec files:

    qdbusxml2cpp -a Client Client.xml
    qdbusxml2cpp -a ClientHandler Client_Handler.xml
    qdbusxml2cpp -a ClientObserver Client_Observer.xml

    And the code that's trying to instantiate it:

    #include "Client.h"
    #include "ClientHandler.h"
    #include "ClientObserver.h"
    
    #include <QCoreApplication>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
    	QCoreApplication app(argc, argv);
    
    	QObject client;
    
    	auto *telepathyClient = new ClientAdaptor(&client);
    
    	auto *telepathyClienHandler = new HandlerAdaptor(&client);
    	telepathyClienHandler->setObjectName("Handler");
    
    	auto *telepathyClienObserver = new ObserverAdaptor(&client);
    	telepathyClienObserver->setObjectName("Observer");
    
    	auto dbusCnx = QDBusConnection::sessionBus();
    
    	if (dbusCnx.registerObject("/org/freedesktop/Telepathy/Client/MyClient", &client, QDBusConnection::ExportAllContents | QDBusConnection::ExportChildObjects))
    		qDebug("Client creation ok.");
    
    	if (dbusCnx.registerService("org.freedesktop.Telepathy.Client.MyClient"))
    		qDebug("Service creation ok.");
    
    	return app.exec();
    }
    

    Does QDbus support creation of the objects with multiple interfaces?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      devel
      wrote on last edited by
      #2

      Actually, TelepathyQt5 wrapper exists. It creates the interfaces correctly.

      #include <TelepathyQt/AbstractClientHandler>
      
      class MyHandler: public Tp::AbstractClientHandler
      {
      public:
      	MyHandler(const Tp::ChannelClassSpecList& channelFilter);
      
      	bool bypassApproval() const;
      
      	void handleChannels(const Tp::MethodInvocationContextPtr<> &context, const Tp::AccountPtr &account, const Tp::ConnectionPtr &connection,
      			const QList<Tp::ChannelPtr> &channels, const QList<Tp::ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime,
      			const Tp::AbstractClientHandler::HandlerInfo &handlerInfo);
      };
      
      MyHandler::MyHandler(const Tp::ChannelClassSpecList &channelFilter) :
      		Tp::AbstractClientHandler(channelFilter)
      {
      }
      
      bool MyHandler::bypassApproval() const
      {
      	return false;
      }
      
      void MyHandler::handleChannels(const Tp::MethodInvocationContextPtr<> &context, const Tp::AccountPtr &account, const Tp::ConnectionPtr &connection,
      		const QList<Tp::ChannelPtr> &channels, const QList<Tp::ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime,
      		const Tp::AbstractClientHandler::HandlerInfo &handlerInfo)
      {
      	// do something
      	context->setFinished();
      }
      
      #include <QCoreApplication>
      #include <QDebug>
      
      #include <TelepathyQt/ClientRegistrar>
      #include <TelepathyQt/ChannelClassSpec>
      
      int main(int argc, char *argv[])
      {
      	QCoreApplication app(argc, argv);
      
      	Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create();
      	Tp::AbstractClientPtr handler = Tp::AbstractClientPtr::dynamicCast(Tp::SharedPtr<MyHandler>(new MyHandler(Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChat())));
      	registrar->registerClient(handler, "MyClient");
      
      	return app.exec();
      }
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved