How to create a QDbus Object with multiple interfaces?



  • 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?



  • 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();
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.