Blame gio/gdbusobject.c

Packit ae235b
/* GDBus - GLib D-Bus Library
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2008-2010 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: David Zeuthen <davidz@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "gdbusobject.h"
Packit ae235b
#include "gdbusinterface.h"
Packit ae235b
#include "gdbusutils.h"
Packit ae235b
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdbusobject
Packit ae235b
 * @short_description: Base type for D-Bus objects
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * The #GDBusObject type is the base type for D-Bus objects on both
Packit ae235b
 * the service side (see #GDBusObjectSkeleton) and the client side
Packit ae235b
 * (see #GDBusObjectProxy). It is essentially just a container of
Packit ae235b
 * interfaces.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GDBusObject:
Packit ae235b
 *
Packit ae235b
 * #GDBusObject is an opaque data structure and can only be accessed
Packit ae235b
 * using the following functions.
Packit ae235b
 */
Packit ae235b
Packit ae235b
typedef GDBusObjectIface GDBusObjectInterface;
Packit ae235b
G_DEFINE_INTERFACE (GDBusObject, g_dbus_object, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_object_default_init (GDBusObjectIface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GDBusObject::interface-added:
Packit ae235b
   * @object: The #GDBusObject emitting the signal.
Packit ae235b
   * @interface: The #GDBusInterface that was added.
Packit ae235b
   *
Packit ae235b
   * Emitted when @interface is added to @object.
Packit ae235b
   *
Packit ae235b
   * Since: 2.30
Packit ae235b
   */
Packit ae235b
  g_signal_new (I_("interface-added"),
Packit ae235b
                G_TYPE_FROM_INTERFACE (iface),
Packit ae235b
                G_SIGNAL_RUN_LAST,
Packit ae235b
                G_STRUCT_OFFSET (GDBusObjectIface, interface_added),
Packit ae235b
                NULL,
Packit ae235b
                NULL,
Packit ae235b
                g_cclosure_marshal_VOID__OBJECT,
Packit ae235b
                G_TYPE_NONE,
Packit ae235b
                1,
Packit ae235b
                G_TYPE_DBUS_INTERFACE);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusObject::interface-removed:
Packit ae235b
   * @object: The #GDBusObject emitting the signal.
Packit ae235b
   * @interface: The #GDBusInterface that was removed.
Packit ae235b
   *
Packit ae235b
   * Emitted when @interface is removed from @object.
Packit ae235b
   *
Packit ae235b
   * Since: 2.30
Packit ae235b
   */
Packit ae235b
  g_signal_new (I_("interface-removed"),
Packit ae235b
                G_TYPE_FROM_INTERFACE (iface),
Packit ae235b
                G_SIGNAL_RUN_LAST,
Packit ae235b
                G_STRUCT_OFFSET (GDBusObjectIface, interface_removed),
Packit ae235b
                NULL,
Packit ae235b
                NULL,
Packit ae235b
                g_cclosure_marshal_VOID__OBJECT,
Packit ae235b
                G_TYPE_NONE,
Packit ae235b
                1,
Packit ae235b
                G_TYPE_DBUS_INTERFACE);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_object_get_object_path:
Packit ae235b
 * @object: A #GDBusObject.
Packit ae235b
 *
Packit ae235b
 * Gets the object path for @object.
Packit ae235b
 *
Packit ae235b
 * Returns: A string owned by @object. Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_object_get_object_path (GDBusObject *object)
Packit ae235b
{
Packit ae235b
  GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
Packit ae235b
  return iface->get_object_path (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_object_get_interfaces:
Packit ae235b
 * @object: A #GDBusObject.
Packit ae235b
 *
Packit ae235b
 * Gets the D-Bus interfaces associated with @object.
Packit ae235b
 *
Packit ae235b
 * Returns: (element-type GDBusInterface) (transfer full): A list of #GDBusInterface instances.
Packit ae235b
 *   The returned list must be freed by g_list_free() after each element has been freed
Packit ae235b
 *   with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GList *
Packit ae235b
g_dbus_object_get_interfaces (GDBusObject *object)
Packit ae235b
{
Packit ae235b
  GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
Packit ae235b
  return iface->get_interfaces (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_object_get_interface:
Packit ae235b
 * @object: A #GDBusObject.
Packit ae235b
 * @interface_name: A D-Bus interface name.
Packit ae235b
 *
Packit ae235b
 * Gets the D-Bus interface with name @interface_name associated with
Packit ae235b
 * @object, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): %NULL if not found, otherwise a
Packit ae235b
 *   #GDBusInterface that must be freed with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GDBusInterface *
Packit ae235b
g_dbus_object_get_interface (GDBusObject *object,
Packit ae235b
                             const gchar *interface_name)
Packit ae235b
{
Packit ae235b
  GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
Packit ae235b
  g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
Packit ae235b
  return iface->get_interface (object, interface_name);
Packit ae235b
}