Back to index

unity  6.0.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
unity::glib::DBusProxy::Impl Class Reference
Collaboration diagram for unity::glib::DBusProxy::Impl:
Collaboration graph
[legend]

List of all members.

Classes

struct  CallData

Public Types

typedef std::map< string,
Callbacks
SignalHandlers

Public Member Functions

 Impl (DBusProxy *owner, string const &name, string const &object_path, string const &interface_name, GBusType bus_type, GDBusProxyFlags flags)
 ~Impl ()
void StartReconnectionTimeout ()
void Connect ()
void Call (string const &method_name, GVariant *parameters, ReplyCallback callback, GCancellable *cancellable, GDBusCallFlags flags, int timeout_msec)
void Connect (string const &signal_name, ReplyCallback callback)
bool IsConnected ()
void OnProxyNameOwnerChanged (GDBusProxy *, GParamSpec *)
void OnProxySignal (GDBusProxy *proxy, char *sender_name, char *signal_name, GVariant *parameters)

Static Public Member Functions

typedef std::vector
< ReplyCallback
Callbacks
static void OnProxyConnectCallback (GObject *source, GAsyncResult *res, gpointer impl)
static void OnCallCallback (GObject *source, GAsyncResult *res, gpointer call_data)

Public Attributes

DBusProxyowner_
string name_
string object_path_
string interface_name_
GBusType bus_type_
GDBusProxyFlags flags_
glib::Object< GDBusProxy > proxy_
glib::Object< GCancellable > cancellable_
guint watcher_id_
bool connected_
glib::Signal< void, GDBusProxy
*, char *, char *, GVariant * > 
g_signal_connection_
glib::Signal< void, GDBusProxy
*, GParamSpec * > 
name_owner_signal_
glib::Source::UniquePtr reconnect_timeout_
SignalHandlers handlers_

Detailed Description

Definition at line 43 of file GLibDBusProxy.cpp.


Class Documentation

struct unity::glib::DBusProxy::Impl::CallData

Definition at line 77 of file GLibDBusProxy.cpp.

Collaboration diagram for unity::glib::DBusProxy::Impl::CallData:
Class Members
ReplyCallback callback
Impl * impl
string method_name

Member Typedef Documentation

Definition at line 46 of file GLibDBusProxy.cpp.

Definition at line 47 of file GLibDBusProxy.cpp.


Constructor & Destructor Documentation

unity::glib::DBusProxy::Impl::Impl ( DBusProxy owner,
string const &  name,
string const &  object_path,
string const &  interface_name,
GBusType  bus_type,
GDBusProxyFlags  flags 
)

Definition at line 103 of file GLibDBusProxy.cpp.

  : owner_(owner)
  , name_(name)
  , object_path_(object_path)
  , interface_name_(interface_name)
  , bus_type_(bus_type)
  , flags_(flags)
  , cancellable_(g_cancellable_new())
  , watcher_id_(0)
  , connected_(false)
{
  StartReconnectionTimeout();
}

Here is the call graph for this function:

Definition at line 122 of file GLibDBusProxy.cpp.

{
  g_cancellable_cancel(cancellable_);
  if (watcher_id_)
    g_bus_unwatch_name(watcher_id_);
}

Member Function Documentation

void unity::glib::DBusProxy::Impl::Call ( string const &  method_name,
GVariant *  parameters,
ReplyCallback  callback,
GCancellable *  cancellable,
GDBusCallFlags  flags,
int  timeout_msec 
)

Definition at line 234 of file GLibDBusProxy.cpp.

{
  if (proxy_)
  {
    CallData* data = new CallData();
    data->callback = callback;
    data->impl = this;
    data->method_name = method_name;

    g_dbus_proxy_call(proxy_,
                      method_name.c_str(),
                      parameters,
                      flags,
                      timeout_msec,
                      cancellable != NULL ? cancellable : cancellable_,
                      DBusProxy::Impl::OnCallCallback,
                      data);
  }
  else
  {
    LOG_WARNING(logger) << "Cannot call method " << method_name
                        << " proxy " << object_path_ << " does not exist";
  }
}

Here is the call graph for this function:

Definition at line 144 of file GLibDBusProxy.cpp.

{
  LOG_DEBUG(logger) << "Attempting to connect to " << name_;
  g_dbus_proxy_new_for_bus(bus_type_,
                           flags_,
                           NULL,
                           name_.c_str(),
                           object_path_.c_str(),
                           interface_name_.c_str(),
                           cancellable_,
                           DBusProxy::Impl::OnProxyConnectCallback,
                           this);
}

Here is the call graph for this function:

void unity::glib::DBusProxy::Impl::Connect ( std::string const &  signal_name,
ReplyCallback  callback 
)

Definition at line 289 of file GLibDBusProxy.cpp.

{
  handlers_[signal_name].push_back(callback);
}

Definition at line 158 of file GLibDBusProxy.cpp.

{
  return connected_;
}
void unity::glib::DBusProxy::Impl::OnCallCallback ( GObject *  source,
GAsyncResult *  res,
gpointer  call_data 
) [static]

Definition at line 264 of file GLibDBusProxy.cpp.

{
  glib::Error error;
  std::unique_ptr<CallData> data (static_cast<CallData*>(call_data));
  GVariant* result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error);

  if (error && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  {
    // silently ignore
  }
  else if (error)
  {
    // Do not touch the impl pointer as the operation may have been cancelled
    LOG_WARNING(logger) << "Calling method \"" << data->method_name
      << "\" on object path: \""
      << g_dbus_proxy_get_object_path (G_DBUS_PROXY (source))
      << "\" failed: " << error;
  }
  else
  {
    data->callback(result);
    g_variant_unref(result);
  }
}

Here is the caller graph for this function:

void unity::glib::DBusProxy::Impl::OnProxyConnectCallback ( GObject *  source,
GAsyncResult *  res,
gpointer  impl 
) [static]

Definition at line 163 of file GLibDBusProxy.cpp.

{
  DBusProxy::Impl* self = static_cast<DBusProxy::Impl*>(impl);

  glib::Error error;
  glib::Object<GDBusProxy> proxy(g_dbus_proxy_new_for_bus_finish(res, &error));

  // If the async operation was cancelled, this callback will still be called and
  // therefore we should deal with the error before touching the impl pointer
  if (!proxy || error)
  {
    LOG_WARNING(logger) << "Unable to connect to proxy: " << error;
    return;
  }

  LOG_DEBUG(logger) << "Sucessfully created proxy: " << self->object_path_;

  self->proxy_ = proxy;
  self->g_signal_connection_.Connect(self->proxy_, "g-signal",
                                     sigc::mem_fun(self, &Impl::OnProxySignal));
  self->name_owner_signal_.Connect(self->proxy_, "notify::g-name-owner",
                                   sigc::mem_fun(self, &Impl::OnProxyNameOwnerChanged));

  // If a proxy cannot autostart a service, it doesn't throw an error, but
  // sets name_owner to NULL
  if (glib::String(g_dbus_proxy_get_name_owner(proxy)))
  {
    self->connected_ = true;
    self->owner_->connected.emit();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::glib::DBusProxy::Impl::OnProxyNameOwnerChanged ( GDBusProxy *  proxy,
GParamSpec *  param 
)

Definition at line 197 of file GLibDBusProxy.cpp.

{
  glib::String name_owner(g_dbus_proxy_get_name_owner(proxy));

  if (name_owner)
  {
    if (!connected_)
    {
      LOG_DEBUG(logger) << name_ << " appeared";

      connected_ = true;
      owner_->connected.emit();
    }
  }
  else if (connected_)
  {
    LOG_DEBUG(logger) << name_ << " vanished";

    connected_ = false;
    owner_->disconnected.emit();
  }
}

Here is the caller graph for this function:

void unity::glib::DBusProxy::Impl::OnProxySignal ( GDBusProxy *  proxy,
char *  sender_name,
char *  signal_name,
GVariant *  parameters 
)

Definition at line 220 of file GLibDBusProxy.cpp.

{
  LOG_DEBUG(logger) << "Signal Received for proxy (" << object_path_ << ") "
                    << "SenderName: " << sender_name << " "
                    << "SignalName: " << signal_name << " "
                    << "ParameterType: " << g_variant_get_type_string(parameters);

  for (ReplyCallback callback: handlers_[signal_name])
    callback(parameters);
}

Here is the caller graph for this function:

Definition at line 129 of file GLibDBusProxy.cpp.

{
  LOG_DEBUG(logger) << "Starting reconnection timeout for " << name_;

  auto callback = [&]
  {
    if (!proxy_)
      Connect();

    return false;
  };

  reconnect_timeout_.reset(new glib::TimeoutSeconds(1, callback));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 88 of file GLibDBusProxy.cpp.

Definition at line 92 of file GLibDBusProxy.cpp.

Definition at line 94 of file GLibDBusProxy.cpp.

Definition at line 89 of file GLibDBusProxy.cpp.

glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> unity::glib::DBusProxy::Impl::g_signal_connection_

Definition at line 96 of file GLibDBusProxy.cpp.

Definition at line 100 of file GLibDBusProxy.cpp.

Definition at line 87 of file GLibDBusProxy.cpp.

Definition at line 85 of file GLibDBusProxy.cpp.

Definition at line 97 of file GLibDBusProxy.cpp.

Definition at line 86 of file GLibDBusProxy.cpp.

Definition at line 84 of file GLibDBusProxy.cpp.

Definition at line 91 of file GLibDBusProxy.cpp.

Definition at line 98 of file GLibDBusProxy.cpp.

Definition at line 93 of file GLibDBusProxy.cpp.


The documentation for this class was generated from the following file: