~3v1n0/unity/neko-reloaded

« back to all changes in this revision

Viewing changes to UnityCore/GLibDBusProxy.cpp

GnomeSessionManager: add gcancellable to instance and use it for calls with temporary proxies

This fixes various crashes when the session manager is destroyed while a temporary proxy
call is still in progress, and the callback is called afterwards.

Approved by: Eleni Maria Stea

Show diffs side-by-side

added added

removed removed

Lines of Context:
609
609
  return nullptr;
610
610
}
611
611
 
612
 
void DBusProxy::GetProperty(std::string const& name, ReplyCallback const& callback)
 
612
void DBusProxy::GetProperty(std::string const& name, ReplyCallback const& callback, GCancellable *cancellable)
613
613
{
614
614
  if (!callback)
615
615
    return;
620
620
                           pimpl->name_.c_str(), pimpl->object_path_.c_str(),
621
621
                           "org.freedesktop.DBus.Properties",
622
622
                           "Get", g_variant_new ("(ss)", pimpl->interface_name_.c_str(), name.c_str()),
623
 
                            G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1, pimpl->cancellable_,
 
623
                            G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1,
 
624
                            cancellable ? cancellable : pimpl->cancellable_,
624
625
                           [] (GObject *source, GAsyncResult *res, gpointer user_data) {
625
626
      glib::Error err;
626
627
      std::unique_ptr<ReplyCallback> callback(static_cast<ReplyCallback*>(user_data));
641
642
  else
642
643
  {
643
644
    // This will get the property as soon as we have a connection
 
645
    glib::Object<GCancellable> canc(cancellable, AddRef());
644
646
    auto conn = std::make_shared<sigc::connection>();
645
 
    *conn = connected.connect([this, conn, name, callback] {
646
 
      GetProperty(name, callback);
 
647
    *conn = connected.connect([this, conn, name, callback, canc] {
 
648
      GetProperty(name, callback, canc);
647
649
      conn->disconnect();
648
650
    });
649
651
  }
650
652
}
651
653
 
652
 
void DBusProxy::SetProperty(std::string const& name, GVariant* value)
 
654
void DBusProxy::SetProperty(std::string const& name, GVariant* value, GCancellable *cancellable)
653
655
{
654
656
  if (IsConnected())
655
657
  {
657
659
                           pimpl->name_.c_str(), pimpl->object_path_.c_str(),
658
660
                           "org.freedesktop.DBus.Properties",
659
661
                           "Set", g_variant_new ("(ssv)", pimpl->interface_name_.c_str(), name.c_str(), value),
660
 
                           nullptr, G_DBUS_CALL_FLAGS_NONE, -1, pimpl->cancellable_,
 
662
                           nullptr, G_DBUS_CALL_FLAGS_NONE, -1,
 
663
                           cancellable ? cancellable : pimpl->cancellable_,
661
664
                           [] (GObject *source, GAsyncResult *res, gpointer user_data) {
662
665
      glib::Error err;
663
666
      Variant result(g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &err), StealRef());
670
673
  else
671
674
  {
672
675
    // This will set the property as soon as we have a connection
 
676
    glib::Object<GCancellable> canc(cancellable, AddRef());
673
677
    auto conn = std::make_shared<sigc::connection>();
674
 
    *conn = connected.connect([this, conn, name, value] {
675
 
      SetProperty(name, value);
 
678
    *conn = connected.connect([this, conn, name, value, canc] {
 
679
      SetProperty(name, value, canc);
676
680
      conn->disconnect();
677
681
    });
678
682
  }