2 * Copyright (C) 2013 Intel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef INCL_LOCALED_LISTENER
21 #define INCL_LOCALED_LISTENER
23 #include <gdbus-cxx-bridge.h>
24 #include <boost/signals2.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/weak_ptr.hpp>
28 #include <syncevo/declarations.h>
32 * The D-Bus binding for http://www.freedesktop.org/wiki/Software/systemd/localed/
34 class LocaledListener : public GDBusCXX::DBusRemoteObject
38 * Singleton - at most one instance of LocaledListener will exist.
39 * It lives as long as one of the create() callers keeps the reference.
41 static boost::shared_ptr<LocaledListener> create();
44 * array of var=value, for example LANG, LC_NUMERIC, etc.
46 typedef std::vector<std::string> LocaleEnv;
49 * Emitted for each new set of env variables from localed.
50 * May or may not be different from what we have already.
52 boost::signals2::signal<void (const LocaleEnv &env)> m_localeValues;
55 * The result callback is guaranteed to be invoked once,
56 * either with the current settings from localed or, if
57 * retrieving those fails, with the current environment.
59 void check(const boost::function<void (const LocaleEnv &env)> &result);
62 * Updates current environment to match the one in the parameter.
63 * Emits m_localeChanged if and only if something really changed.
65 * Not called by default. To ensure that the current environment
66 * matches localed, do:
67 * - use current settings
68 * - m_localeValues -> setLocale
69 * - check -> setLocale
71 * Alternatively, one could wait until check() completes and only
72 * then use the current settings.
74 void setLocale(const LocaleEnv &locale);
76 typedef boost::signals2::signal<void ()> LocaleChangedSignal;
78 * Emitted by setLocale() only if something really changed in the
81 LocaleChangedSignal m_localeChanged;
84 boost::weak_ptr<LocaledListener> m_self;
85 typedef boost::variant<LocaleEnv> LocaleVariant;
86 typedef std::map<std::string, LocaleVariant> Properties;
87 typedef std::vector<std::string> Invalidated;
88 GDBusCXX::SignalWatch3<std::string, Properties, Invalidated> m_propertiesChanged;
89 GDBusCXX::DBusClientCall1<LocaleVariant> m_propertiesGet;
92 void onPropertiesChange(const std::string &interface,
93 const Properties &properties,
94 const Invalidated &invalidated);
95 typedef boost::function<void (const LocaleEnv &env)> ProcessLocalePropCB_t;
96 void processLocaleProperty(const LocaleVariant &locale,
97 const std::string &error,
99 const ProcessLocalePropCB_t &result);
100 void emitLocaleEnv(const LocaleEnv &env);
105 #endif // INCL_LOCALED_LISTENER