| 1 | /* |
| 2 | * This file is part of OnlineAccountsDaemon |
| 3 | * |
| 4 | * Copyright (C) 2015 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #ifndef ONLINE_ACCOUNTS_DAEMON_MANAGER_ADAPTOR_H |
| 22 | #define ONLINE_ACCOUNTS_DAEMON_MANAGER_ADAPTOR_H |
| 23 | |
| 24 | #include <QDBusAbstractAdaptor> |
| 25 | #include <QDBusConnection> |
| 26 | #include <QDBusContext> |
| 27 | #include <QDBusMessage> |
| 28 | #include <QString> |
| 29 | #include <QVariantMap> |
| 30 | #include <sys/types.h> |
| 31 | #include "account_info.h" |
| 32 | #include "manager.h" |
| 33 | |
| 34 | namespace OnlineAccountsDaemon { |
| 35 | |
| 36 | class CallContext { |
| 37 | public: |
| 38 | explicit CallContext(QDBusContext *dbusContext); |
| 39 | CallContext(const CallContext &other); |
| 40 | virtual ~CallContext(); |
| 41 | |
| 42 | void setDelayedReply(bool delayed); |
| 43 | void sendReply(const QList<QVariant> &args) const; |
| 44 | void sendError(const QString &name, const QString &message) const; |
| 45 | |
| 46 | QString securityContext() const; |
| 47 | pid_t clientPid() const; |
| 48 | QString clientName() const; |
| 49 | |
| 50 | private: |
| 51 | QDBusConnection m_connection; |
| 52 | QDBusMessage m_message; |
| 53 | }; |
| 54 | |
| 55 | class CallContextCounter: public QObject |
| 56 | { |
| 57 | Q_OBJECT |
| 58 | |
| 59 | public: |
| 60 | static CallContextCounter *instance(); |
| 61 | |
| 62 | int activeContexts() const { return m_contexts; } |
| 63 | |
| 64 | Q_SIGNALS: |
| 65 | void activeContextsChanged(); |
| 66 | |
| 67 | protected: |
| 68 | void addContext(const CallContext &context); |
| 69 | void removeContext(const CallContext &context); |
| 70 | |
| 71 | private: |
| 72 | friend class CallContext; |
| 73 | CallContextCounter(); |
| 74 | |
| 75 | int m_contexts; |
| 76 | }; |
| 77 | |
| 78 | class ManagerAdaptorPrivate; |
| 79 | class ManagerAdaptor: public QDBusAbstractAdaptor |
| 80 | { |
| 81 | Q_OBJECT |
| 82 | Q_CLASSINFO("D-Bus Interface", "com.lomiri.OnlineAccounts.Manager") |
| 83 | Q_CLASSINFO("D-Bus Introspection", "" |
| 84 | " <interface name=\"com.lomiri.OnlineAccounts.Manager\">\n" |
| 85 | " <method name=\"GetAccounts\">\n" |
| 86 | " <arg direction=\"in\" type=\"a{sv}\" name=\"filters\"/>\n" |
| 87 | " <arg direction=\"out\" type=\"a(ua{sv})\" name=\"accounts\"/>\n" |
| 88 | " <arg direction=\"out\" type=\"aa{sv}\" name=\"services\"/>\n" |
| 89 | " </method>\n" |
| 90 | " <method name=\"Authenticate\">\n" |
| 91 | " <arg direction=\"in\" type=\"u\" name=\"accountId\"/>\n" |
| 92 | " <arg direction=\"in\" type=\"s\" name=\"serviceId\"/>\n" |
| 93 | " <arg direction=\"in\" type=\"b\" name=\"interactive\"/>\n" |
| 94 | " <arg direction=\"in\" type=\"b\" name=\"invalidate\"/>\n" |
| 95 | " <arg direction=\"in\" type=\"a{sv}\" name=\"parameters\"/>\n" |
| 96 | " <arg direction=\"out\" type=\"a{sv}\" name=\"credentials\"/>\n" |
| 97 | " </method>\n" |
| 98 | " <method name=\"RequestAccess\">\n" |
| 99 | " <arg direction=\"in\" type=\"s\" name=\"serviceId\"/>\n" |
| 100 | " <arg direction=\"in\" type=\"a{sv}\" name=\"parameters\"/>\n" |
| 101 | " <arg direction=\"out\" type=\"(ua{sv})\" name=\"account\"/>\n" |
| 102 | " <arg direction=\"out\" type=\"a{sv}\" name=\"credentials\"/>\n" |
| 103 | " </method>\n" |
| 104 | " <signal name=\"AccountChanged\">\n" |
| 105 | " <arg type=\"s\" name=\"serviceId\"/>\n" |
| 106 | " <arg type=\"(ua{sv})\" name=\"account\"/>\n" |
| 107 | " </signal>\n" |
| 108 | " </interface>\n" |
| 109 | "") |
| 110 | |
| 111 | public: |
| 112 | explicit ManagerAdaptor(Manager *parent); |
| 113 | ~ManagerAdaptor(); |
| 114 | |
| 115 | inline Manager *parent() const |
| 116 | { return static_cast<Manager *>(QObject::parent()); } |
| 117 | |
| 118 | inline QDBusContext *dbusContext() const |
| 119 | { return static_cast<QDBusContext *>(parent()); } |
| 120 | |
| 121 | void notifyAccountChange(const AccountInfo &info, uint changeType); |
| 122 | |
| 123 | public Q_SLOTS: |
| 124 | QVariantMap Authenticate(uint accountId, const QString &serviceId, |
| 125 | bool interactive, bool invalidate, |
| 126 | const QVariantMap ¶meters); |
| 127 | void GetAccounts(const QVariantMap &filters, |
| 128 | QList<AccountInfo> &accounts, |
| 129 | QList<QVariantMap> &services); |
| 130 | AccountInfo RequestAccess(const QString &serviceId, |
| 131 | const QVariantMap ¶meters, |
| 132 | QVariantMap &credentials); |
| 133 | |
| 134 | Q_SIGNALS: |
| 135 | void AccountChanged(const QString &serviceId, AccountInfo account); |
| 136 | |
| 137 | private: |
| 138 | Q_DECLARE_PRIVATE(ManagerAdaptor) |
| 139 | ManagerAdaptorPrivate *d_ptr; |
| 140 | }; |
| 141 | |
| 142 | } // namespace |
| 143 | |
| 144 | #endif // ONLINE_ACCOUNTS_DAEMON_MANAGER_ADAPTOR_H |