diff options
Diffstat (limited to 'UnityCore')
| -rw-r--r-- | UnityCore/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | UnityCore/DBusIndicators.cpp | 15 | ||||
| -rw-r--r-- | UnityCore/GLibDBusNameWatcher.cpp | 44 | ||||
| -rw-r--r-- | UnityCore/GLibDBusNameWatcher.h | 54 | ||||
| -rw-r--r-- | UnityCore/GLibDBusProxy.cpp | 10 | ||||
| -rw-r--r-- | UnityCore/GLibDBusServer.cpp | 43 | ||||
| -rw-r--r-- | UnityCore/GLibDBusServer.h | 12 | ||||
| -rw-r--r-- | UnityCore/GTKWrapper.h | 73 | ||||
| -rw-r--r-- | UnityCore/Indicators.cpp | 5 |
9 files changed, 142 insertions, 116 deletions
diff --git a/UnityCore/CMakeLists.txt b/UnityCore/CMakeLists.txt index 92191c0d5..f055790d3 100644 --- a/UnityCore/CMakeLists.txt +++ b/UnityCore/CMakeLists.txt @@ -25,6 +25,7 @@ set (CORE_HEADERS Filter.h Filters.h GenericPreview.h + GLibDBusNameWatcher.h GLibDBusProxy.h GLibDBusServer.h GLibSignal.h @@ -80,6 +81,7 @@ set (CORE_SOURCES Filter.cpp Filters.cpp GenericPreview.cpp + GLibDBusNameWatcher.cpp GLibDBusProxy.cpp GLibDBusServer.cpp GLibSignal.cpp diff --git a/UnityCore/DBusIndicators.cpp b/UnityCore/DBusIndicators.cpp index d19a4aec7..b890124c3 100644 --- a/UnityCore/DBusIndicators.cpp +++ b/UnityCore/DBusIndicators.cpp @@ -74,7 +74,6 @@ struct DBusIndicators::Impl void OnIconsPathChanged(GVariant* parameters); void OnEntryActivated(GVariant* parameters); void OnEntryActivatedRequest(GVariant* parameters); - void OnEntryShowNowChanged(GVariant* parameters); void OnEntryScroll(std::string const& entry_id, int delta); void OnEntryShowMenu(std::string const& entry_id, unsigned int xid, int x, int y, unsigned int button); @@ -102,7 +101,6 @@ DBusIndicators::Impl::Impl(std::string const& dbus_name, DBusIndicators* owner) gproxy_.Connect("IconPathsChanged", sigc::mem_fun(this, &DBusIndicators::Impl::OnIconsPathChanged)); gproxy_.Connect("EntryActivated", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryActivated)); gproxy_.Connect("EntryActivateRequest", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryActivatedRequest)); - gproxy_.Connect("EntryShowNowChanged", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryShowNowChanged)); gproxy_.connected.connect(sigc::mem_fun(this, &DBusIndicators::Impl::OnConnected)); gproxy_.disconnected.connect(sigc::mem_fun(this, &DBusIndicators::Impl::OnDisconnected)); @@ -242,19 +240,6 @@ void DBusIndicators::Impl::OnEntryActivatedRequest(GVariant* parameters) owner_->on_entry_activate_request.emit(entry_name); } -void DBusIndicators::Impl::OnEntryShowNowChanged(GVariant* parameters) -{ - if (!verify_variant_type(parameters, "(sb)")) - return; - - glib::String entry_name; - gboolean show_now; - g_variant_get(parameters, "(sb)", &entry_name, &show_now); - - if (entry_name) - owner_->SetEntryShowNow(entry_name, show_now); -} - void DBusIndicators::Impl::RequestSyncAll() { gproxy_.CallBegin("Sync", nullptr, sigc::mem_fun(this, &DBusIndicators::Impl::Sync)); diff --git a/UnityCore/GLibDBusNameWatcher.cpp b/UnityCore/GLibDBusNameWatcher.cpp new file mode 100644 index 000000000..92f311210 --- /dev/null +++ b/UnityCore/GLibDBusNameWatcher.cpp @@ -0,0 +1,44 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2015 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com> + */ + +#include "GLibDBusNameWatcher.h" +#include "GLibWrapper.h" + +namespace unity +{ +namespace glib +{ + +DBusNameWatcher::DBusNameWatcher(std::string const& name, GBusType bus_type, GBusNameWatcherFlags flags) + : watcher_id_(g_bus_watch_name(bus_type, name.c_str(), flags, + [] (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer self) { + static_cast<DBusNameWatcher*>(self)->appeared.emit(gchar_to_string(name), gchar_to_string(name_owner)); + }, + [] (GDBusConnection *connection, const gchar *name, gpointer self) { + static_cast<DBusNameWatcher*>(self)->vanished.emit(gchar_to_string(name)); + }, this, nullptr)) +{} + +DBusNameWatcher::~DBusNameWatcher() +{ + g_bus_unwatch_name(watcher_id_); +} + +} // namespace glib +} // namespace unity diff --git a/UnityCore/GLibDBusNameWatcher.h b/UnityCore/GLibDBusNameWatcher.h new file mode 100644 index 000000000..b5901d3d4 --- /dev/null +++ b/UnityCore/GLibDBusNameWatcher.h @@ -0,0 +1,54 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2015 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com> + */ + +#ifndef UNITY_GLIB_DBUS_NAME_WATCHER_H +#define UNITY_GLIB_DBUS_NAME_WATCHER_H + +#include <gio/gio.h> +#include <memory> +#include <sigc++/signal.h> + +namespace unity +{ +namespace glib +{ + +class DBusNameWatcher +{ +public: + typedef std::shared_ptr<DBusNameWatcher> Ptr; + + DBusNameWatcher(std::string const& name, GBusType bus_type = G_BUS_TYPE_SESSION, GBusNameWatcherFlags flags = G_BUS_NAME_WATCHER_FLAGS_NONE); + virtual ~DBusNameWatcher(); + + sigc::signal<void, std::string const& /* name*/, std::string const& /* name owner*/> appeared; + sigc::signal<void, std::string const& /* name */> vanished; + +private: + // not copyable class + DBusNameWatcher(DBusNameWatcher const&) = delete; + DBusNameWatcher& operator=(DBusNameWatcher const&) = delete; + + uint32_t watcher_id_; +}; + +} // namespace glib +} // namespace unity + +#endif //UNITY_GLIB_DBUS_NAME_WATCHER_H diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index fabef7d48..1cd6f4d3d 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -344,7 +344,8 @@ void DBusProxy::Impl::WaitForProxy(GCancellable* cancellable, // wait for the signal *con = proxy_acquired.connect([con, canc, timeout, callback] () { - if (!g_cancellable_is_cancelled(canc)) callback(glib::Error()); + if (!g_cancellable_is_cancelled(canc)) + callback(glib::Error()); timeout->Remove(); con->disconnect(); @@ -390,12 +391,15 @@ void DBusProxy::Impl::Call(string const& method_name, if (!proxy_) { glib::Variant sinked_parameters(parameters); - glib::Object<GCancellable>canc(target_canc, glib::AddRef()); + glib::Object<GCancellable> canc(target_canc, glib::AddRef()); + WaitForProxy(canc, timeout_msec, [this, method_name, sinked_parameters, callback, canc, flags, timeout_msec] (glib::Error const& err) { if (err) { - callback(glib::Variant(), err); + if (callback) + callback(glib::Variant(), err); + LOG_WARNING(logger) << "Cannot call method " << method_name << ": " << err; } diff --git a/UnityCore/GLibDBusServer.cpp b/UnityCore/GLibDBusServer.cpp index 6d01f5994..49b70d7c0 100644 --- a/UnityCore/GLibDBusServer.cpp +++ b/UnityCore/GLibDBusServer.cpp @@ -87,7 +87,7 @@ struct DBusObject::Impl if (self->method_cb_) { - ret = self->method_cb_(method_name ? method_name : "", parameters); + ret = self->method_cb_(gchar_to_string(method_name), parameters, gchar_to_string(sender), gchar_to_string(object_path)); LOG_INFO(logger_o) << "Called method: '" << method_name << " " << parameters << "' on object '" << object_path << "' with interface '" @@ -295,13 +295,14 @@ struct DBusObject::Impl void EmitGenericSignal(glib::Object<GDBusConnection> const& conn, std::string const& path, std::string const& interface, std::string const& signal, - GVariant* parameters = nullptr) + GVariant* parameters = nullptr, std::string const& dest = "") { LOG_INFO(logger_o) << "Emitting signal '" << signal << "'" << " for the interface " << "'" << interface << "' on object path '" << path << "'"; glib::Error error; - g_dbus_connection_emit_signal(conn, nullptr, path.c_str(), interface.c_str(), + g_dbus_connection_emit_signal(conn, dest.empty() ? nullptr : dest.c_str(), + path.c_str(), interface.c_str(), signal.c_str(), parameters, &error); if (error) @@ -312,7 +313,7 @@ struct DBusObject::Impl } } - void EmitSignal(std::string const& signal, GVariant* parameters, std::string const& path) + void EmitSignal(std::string const& signal, GVariant* parameters, std::string const& dest, std::string const& path) { glib::Variant reffed_params(parameters); @@ -333,7 +334,7 @@ struct DBusObject::Impl return; } - EmitGenericSignal(conn_it->second, path, InterfaceName(), signal, parameters); + EmitGenericSignal(conn_it->second, path, InterfaceName(), signal, parameters, dest); } else { @@ -343,7 +344,7 @@ struct DBusObject::Impl auto const& obj_path = pair.first; auto const& conn = pair.second; - EmitGenericSignal(conn, obj_path, InterfaceName(), signal, params); + EmitGenericSignal(conn, obj_path, InterfaceName(), signal, params, dest); } } } @@ -401,7 +402,7 @@ struct DBusObject::Impl } DBusObject* object_; - MethodCallback method_cb_; + MethodCallbackFull method_cb_; PropertyGetterCallback property_get_cb_; PropertySetterCallback property_set_cb_; @@ -420,6 +421,18 @@ DBusObject::~DBusObject() void DBusObject::SetMethodsCallsHandler(MethodCallback const& func) { + impl_->method_cb_ = nullptr; + + if (func) + { + impl_->method_cb_ = [func] (std::string const& method, GVariant* parameters, std::string const&, std::string const&) { + return func(method, parameters); + }; + } +} + +void DBusObject::SetMethodsCallsHandlerFull(MethodCallbackFull const& func) +{ impl_->method_cb_ = func; } @@ -448,9 +461,9 @@ void DBusObject::UnRegister(std::string const& path) impl_->UnRegister(path); } -void DBusObject::EmitSignal(std::string const& signal, GVariant* parameters, std::string const& path) +void DBusObject::EmitSignal(std::string const& signal, GVariant* parameters, std::string const& dest, std::string const& path) { - impl_->EmitSignal(signal, parameters, path); + impl_->EmitSignal(signal, parameters, dest, path); } void DBusObject::EmitPropertyChanged(std::string const& property, std::string const& path) @@ -648,12 +661,10 @@ struct DBusServer::Impl return DBusObject::Ptr(); } - void EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters) + void EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters, std::string const& dest) { - auto const& obj = GetObject(interface); - - if (obj) - obj->EmitSignal(signal, parameters); + if (DBusObject::Ptr const& obj = GetObject(interface)) + obj->EmitSignal(signal, parameters, dest); } DBusServer* server_; @@ -735,9 +746,9 @@ DBusObject::Ptr DBusServer::GetObject(std::string const& interface) const return impl_->GetObject(interface); } -void DBusServer::EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters) +void DBusServer::EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters, std::string const& dest) { - impl_->EmitSignal(interface, signal, parameters); + impl_->EmitSignal(interface, signal, parameters, dest); } } // namespace glib diff --git a/UnityCore/GLibDBusServer.h b/UnityCore/GLibDBusServer.h index 8957861be..b064c4360 100644 --- a/UnityCore/GLibDBusServer.h +++ b/UnityCore/GLibDBusServer.h @@ -40,11 +40,13 @@ public: DBusObject(std::string const& introspection_xml, std::string const& interface_name); virtual ~DBusObject(); - typedef std::function<GVariant*(std::string const&, GVariant*)> MethodCallback; - typedef std::function<GVariant*(std::string const&)> PropertyGetterCallback; - typedef std::function<bool(std::string const&, GVariant*)> PropertySetterCallback; + typedef std::function<GVariant*(std::string const& /*method*/, GVariant* /*parameters*/)> MethodCallback; + typedef std::function<GVariant*(std::string const& /*method*/, GVariant* /*parameters*/, std::string const& /*sender*/, std::string const& /*object_path*/)> MethodCallbackFull; + typedef std::function<GVariant*(std::string const& /*name*/)> PropertyGetterCallback; + typedef std::function<bool(std::string const& /*name*/, GVariant* /*value*/)> PropertySetterCallback; void SetMethodsCallsHandler(MethodCallback const&); + void SetMethodsCallsHandlerFull(MethodCallbackFull const&); void SetPropertyGetter(PropertyGetterCallback const&); void SetPropertySetter(PropertySetterCallback const&); @@ -53,7 +55,7 @@ public: bool Register(glib::Object<GDBusConnection> const&, std::string const& path); void UnRegister(std::string const& path = ""); - void EmitSignal(std::string const& signal, GVariant* parameters = nullptr, std::string const& path = ""); + void EmitSignal(std::string const& signal, GVariant* parameters = nullptr, std::string const& dest = "", std::string const& path = ""); void EmitPropertyChanged(std::string const& property, std::string const& path = ""); sigc::signal<void, std::string const&> registered; @@ -91,7 +93,7 @@ public: std::list<DBusObject::Ptr> GetObjects() const; DBusObject::Ptr GetObject(std::string const& interface) const; - void EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters = nullptr); + void EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters = nullptr, std::string const& dest = ""); bool IsConnected() const; std::string const& Name() const; diff --git a/UnityCore/GTKWrapper.h b/UnityCore/GTKWrapper.h deleted file mode 100644 index fe1eb0884..000000000 --- a/UnityCore/GTKWrapper.h +++ /dev/null @@ -1,73 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright (C) 2013 Canonical Ltd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authored by: Marco Trevisan <marco.trevisan@canonical.com> - */ - -#ifndef GTK_WRAPPER - -#include <gtk/gtk.h> -#include <GLibWrapper.h> - -namespace unity -{ -namespace gtk -{ - -#if GTK_CHECK_VERSION(3, 8, 0) - -typedef glib::Object<GtkIconInfo> IconInfo; - -#else - -class IconInfo : boost::noncopyable -{ -public: - IconInfo(GtkIconInfo *info = nullptr) - : icon_info_(info) - {} - - ~IconInfo() - { - if (icon_info_) - gtk_icon_info_free(icon_info_); - } - - IconInfo& operator=(GtkIconInfo* val) - { - if (icon_info_ == val) - return *this; - - if (icon_info_) - gtk_icon_info_free(icon_info_); - - icon_info_ = val; - return *this; - } - - operator GtkIconInfo*() const { return icon_info_; } - operator bool() const { return icon_info_; } - GtkIconInfo* RawPtr() const { return icon_info_; } - -private: - GtkIconInfo *icon_info_; -}; -#endif - -} -} - -#endif // GTK_WRAPPER diff --git a/UnityCore/Indicators.cpp b/UnityCore/Indicators.cpp index 6b929dcbf..08c88c1c9 100644 --- a/UnityCore/Indicators.cpp +++ b/UnityCore/Indicators.cpp @@ -121,11 +121,8 @@ void Indicators::Impl::ActivateEntry(std::string const& panel, std::string const void Indicators::Impl::SetEntryShowNow(std::string const& entry_id, bool show_now) { - Entry::Ptr entry = GetEntry(entry_id); - if (entry) - { + if (Entry::Ptr const& entry = GetEntry(entry_id)) entry->set_show_now(show_now); - } } Indicators::IndicatorsList Indicators::Impl::GetIndicators() const |
