| 1 | /* |
| 2 | * Copyright (C) 2013 Canonical Ltd. |
| 3 | * |
| 4 | * Contact: Alberto Mardegan <[email protected]> |
| 5 | * |
| 6 | * This file is part of lomiri-online-accounts-service |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 3, as published |
| 10 | * 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 General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <online-accounts-common/debug.h> |
| 22 | #include <online-accounts-common/globals.h> |
| 23 | #include "inactivity-timer.h" |
| 24 | #include "indicator-service.h" |
| 25 | #include "libaccounts-service.h" |
| 26 | #include "request-manager.h" |
| 27 | #include "service.h" |
| 28 | #include "signonui-service.h" |
| 29 | |
| 30 | #include <LomiriOnlineAccountsDaemon/Manager> |
| 31 | #include <LomiriOnlineAccountsDaemon/dbus_constants.h> |
| 32 | |
| 33 | #include <QCoreApplication> |
| 34 | #include <QDBusConnection> |
| 35 | #include <QDBusMetaType> |
| 36 | #include <QProcessEnvironment> |
| 37 | #include <QSettings> |
| 38 | |
| 39 | using namespace OnlineAccountsUi; |
| 40 | |
| 41 | int main(int argc, char **argv) |
| 42 | { |
| 43 | QCoreApplication app(argc, argv); |
| 44 | |
| 45 | QSettings settings("lomiri-online-accounts-service"); |
| 46 | |
| 47 | /* read environment variables */ |
| 48 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); |
| 49 | if (environment.contains(QLatin1String("OAU_LOGGING_LEVEL"))) { |
| 50 | bool isOk; |
| 51 | int value = environment.value( |
| 52 | QLatin1String("OAU_LOGGING_LEVEL")).toInt(&isOk); |
| 53 | if (isOk) |
| 54 | setLoggingLevel(value); |
| 55 | } else { |
| 56 | setLoggingLevel(settings.value("LoggingLevel", 1).toInt()); |
| 57 | } |
| 58 | |
| 59 | /* default daemonTimeout to 5 seconds */ |
| 60 | int daemonTimeout = 5; |
| 61 | |
| 62 | /* override daemonTimeout if OAU_DAEMON_TIMEOUT is set */ |
| 63 | if (environment.contains(QLatin1String("OAU_DAEMON_TIMEOUT"))) { |
| 64 | bool isOk; |
| 65 | int value = environment.value( |
| 66 | QLatin1String("OAU_DAEMON_TIMEOUT")).toInt(&isOk); |
| 67 | if (isOk) |
| 68 | daemonTimeout = value; |
| 69 | } else { |
| 70 | daemonTimeout = settings.value("DaemonTimeout", 5).toInt(); |
| 71 | } |
| 72 | |
| 73 | RequestManager *requestManager = new RequestManager(); |
| 74 | |
| 75 | qDBusRegisterMetaType<SignOnUi::RawCookies>(); |
| 76 | |
| 77 | Service *service = new Service(); |
| 78 | QDBusConnection connection = QDBusConnection::sessionBus(); |
| 79 | connection.registerObject(OAU_OBJECT_PATH, service); |
| 80 | connection.registerService(OAU_SERVICE_NAME); |
| 81 | |
| 82 | SignOnUi::Service *signonuiService = new SignOnUi::Service(); |
| 83 | connection.registerObject(SIGNONUI_OBJECT_PATH, signonuiService, |
| 84 | QDBusConnection::ExportAllContents); |
| 85 | connection.registerService(SIGNONUI_SERVICE_NAME); |
| 86 | |
| 87 | SignOnUi::IndicatorService *indicatorService = |
| 88 | new SignOnUi::IndicatorService(); |
| 89 | connection.registerObject(WEBCREDENTIALS_OBJECT_PATH, |
| 90 | indicatorService->serviceObject()); |
| 91 | connection.registerService(WEBCREDENTIALS_BUS_NAME); |
| 92 | |
| 93 | LibaccountsService *libaccountsService = new LibaccountsService(); |
| 94 | connection.registerObject(LIBACCOUNTS_OBJECT_PATH, libaccountsService, |
| 95 | QDBusConnection::ExportAllContents); |
| 96 | connection.registerService(LIBACCOUNTS_BUS_NAME); |
| 97 | |
| 98 | // V2 API |
| 99 | OnlineAccountsDaemon::Manager *v2api = |
| 100 | new OnlineAccountsDaemon::Manager(); |
| 101 | connection.registerObject(ONLINE_ACCOUNTS_MANAGER_PATH, v2api); |
| 102 | connection.registerService(ONLINE_ACCOUNTS_MANAGER_SERVICE_NAME); |
| 103 | connection.connect(QString(), |
| 104 | QStringLiteral("/org/freedesktop/DBus/Local"), |
| 105 | QStringLiteral("org.freedesktop.DBus.Local"), |
| 106 | QStringLiteral("Disconnected"), |
| 107 | v2api, SLOT(onDisconnected())); |
| 108 | |
| 109 | InactivityTimer *inactivityTimer = 0; |
| 110 | if (daemonTimeout > 0) { |
| 111 | inactivityTimer = new InactivityTimer(daemonTimeout * 1000); |
| 112 | inactivityTimer->watchObject(v2api); |
| 113 | inactivityTimer->watchObject(requestManager); |
| 114 | inactivityTimer->watchObject(indicatorService); |
| 115 | QObject::connect(inactivityTimer, SIGNAL(timeout()), |
| 116 | &app, SLOT(quit())); |
| 117 | } |
| 118 | |
| 119 | int ret = app.exec(); |
| 120 | |
| 121 | connection.unregisterService(ONLINE_ACCOUNTS_MANAGER_SERVICE_NAME); |
| 122 | connection.unregisterObject(ONLINE_ACCOUNTS_MANAGER_PATH); |
| 123 | delete v2api; |
| 124 | |
| 125 | connection.unregisterService(LIBACCOUNTS_BUS_NAME); |
| 126 | connection.unregisterObject(LIBACCOUNTS_OBJECT_PATH); |
| 127 | delete libaccountsService; |
| 128 | |
| 129 | connection.unregisterService(WEBCREDENTIALS_BUS_NAME); |
| 130 | connection.unregisterObject(WEBCREDENTIALS_OBJECT_PATH); |
| 131 | delete indicatorService; |
| 132 | |
| 133 | connection.unregisterService(SIGNONUI_SERVICE_NAME); |
| 134 | connection.unregisterObject(SIGNONUI_OBJECT_PATH); |
| 135 | delete signonuiService; |
| 136 | |
| 137 | connection.unregisterService(OAU_SERVICE_NAME); |
| 138 | connection.unregisterObject(OAU_OBJECT_PATH); |
| 139 | delete service; |
| 140 | |
| 141 | delete requestManager; |
| 142 | |
| 143 | delete inactivityTimer; |
| 144 | |
| 145 | return ret; |
| 146 | } |
| 147 |