xref: /glogg/src/dbusexternalcom.h (revision 09aff35d9e83cfd6fe816dd78526ed49c54a5f9e)
1557fb9d8SNicolas Bonnefon /*
2557fb9d8SNicolas Bonnefon  * Copyright (C) 2014 Nicolas Bonnefon and other contributors
3557fb9d8SNicolas Bonnefon  *
4557fb9d8SNicolas Bonnefon  * This file is part of glogg.
5557fb9d8SNicolas Bonnefon  *
6557fb9d8SNicolas Bonnefon  * glogg is free software: you can redistribute it and/or modify
7557fb9d8SNicolas Bonnefon  * it under the terms of the GNU General Public License as published by
8557fb9d8SNicolas Bonnefon  * the Free Software Foundation, either version 3 of the License, or
9557fb9d8SNicolas Bonnefon  * (at your option) any later version.
10557fb9d8SNicolas Bonnefon  *
11557fb9d8SNicolas Bonnefon  * glogg is distributed in the hope that it will be useful,
12557fb9d8SNicolas Bonnefon  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13557fb9d8SNicolas Bonnefon  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14557fb9d8SNicolas Bonnefon  * GNU General Public License for more details.
15557fb9d8SNicolas Bonnefon  *
16557fb9d8SNicolas Bonnefon  * You should have received a copy of the GNU General Public License
17557fb9d8SNicolas Bonnefon  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18557fb9d8SNicolas Bonnefon  */
19557fb9d8SNicolas Bonnefon 
20557fb9d8SNicolas Bonnefon #ifndef DBUSEXTERNALCOM_H
21557fb9d8SNicolas Bonnefon #define DBUSEXTERNALCOM_H
22557fb9d8SNicolas Bonnefon 
23557fb9d8SNicolas Bonnefon #include "externalcom.h"
24557fb9d8SNicolas Bonnefon 
25557fb9d8SNicolas Bonnefon #include <memory>
260dadbfafSNicolas Bonnefon #include <QObject>
27557fb9d8SNicolas Bonnefon #include <QtDBus/QtDBus>
28557fb9d8SNicolas Bonnefon 
29557fb9d8SNicolas Bonnefon // An implementation of ExternalInstance using D-Bus via Qt
30557fb9d8SNicolas Bonnefon class DBusExternalInstance : public ExternalInstance {
31557fb9d8SNicolas Bonnefon   public:
32557fb9d8SNicolas Bonnefon     DBusExternalInstance();
~DBusExternalInstance()33557fb9d8SNicolas Bonnefon     ~DBusExternalInstance() {}
34557fb9d8SNicolas Bonnefon 
35*09aff35dSNicolas Bonnefon     virtual void loadFile( const QString& file_name ) const;
36e07da50aSNicolas Bonnefon     virtual uint32_t getVersion() const;
37557fb9d8SNicolas Bonnefon 
38557fb9d8SNicolas Bonnefon   private:
39557fb9d8SNicolas Bonnefon     std::shared_ptr<QDBusInterface> dbusInterface_;
40557fb9d8SNicolas Bonnefon };
41557fb9d8SNicolas Bonnefon 
420dadbfafSNicolas Bonnefon class DBusInterfaceExternalCommunicator : public QObject
430dadbfafSNicolas Bonnefon {
440dadbfafSNicolas Bonnefon   Q_OBJECT
450dadbfafSNicolas Bonnefon 
460dadbfafSNicolas Bonnefon   public:
DBusInterfaceExternalCommunicator()470dadbfafSNicolas Bonnefon     DBusInterfaceExternalCommunicator() : QObject() {}
~DBusInterfaceExternalCommunicator()480dadbfafSNicolas Bonnefon     ~DBusInterfaceExternalCommunicator() {}
490dadbfafSNicolas Bonnefon 
500dadbfafSNicolas Bonnefon   public slots:
510dadbfafSNicolas Bonnefon     void loadFile( const QString& file_name );
520dadbfafSNicolas Bonnefon     qint32 version() const;
530dadbfafSNicolas Bonnefon 
540dadbfafSNicolas Bonnefon   signals:
550dadbfafSNicolas Bonnefon     void signalLoadFile( const QString& file_name );
560dadbfafSNicolas Bonnefon };
570dadbfafSNicolas Bonnefon 
58557fb9d8SNicolas Bonnefon // An implementation of ExternalCommunicator using D-Bus via Qt
59557fb9d8SNicolas Bonnefon class DBusExternalCommunicator : public ExternalCommunicator
60557fb9d8SNicolas Bonnefon {
610dadbfafSNicolas Bonnefon   Q_OBJECT
620dadbfafSNicolas Bonnefon 
63557fb9d8SNicolas Bonnefon   public:
64557fb9d8SNicolas Bonnefon     // Constructor: initialise the D-Bus connection,
65557fb9d8SNicolas Bonnefon     // can throw if D-Bus is not available
66557fb9d8SNicolas Bonnefon     DBusExternalCommunicator();
~DBusExternalCommunicator()67557fb9d8SNicolas Bonnefon     ~DBusExternalCommunicator() {}
68557fb9d8SNicolas Bonnefon 
69e07da50aSNicolas Bonnefon     virtual void startListening();
70e07da50aSNicolas Bonnefon 
71557fb9d8SNicolas Bonnefon     virtual ExternalInstance* otherInstance() const;
72557fb9d8SNicolas Bonnefon 
73557fb9d8SNicolas Bonnefon   public slots:
740dadbfafSNicolas Bonnefon     qint32 version() const;
75557fb9d8SNicolas Bonnefon 
76557fb9d8SNicolas Bonnefon   private:
770dadbfafSNicolas Bonnefon     std::shared_ptr<DBusInterfaceExternalCommunicator> dbus_iface_object_;
78557fb9d8SNicolas Bonnefon };
79557fb9d8SNicolas Bonnefon 
80557fb9d8SNicolas Bonnefon #endif
81