Commit 85b297a7 authored by Iain Holmes's avatar Iain Holmes

Add the backend object

parent fff2ce33
/*
* Geoclue
* gc-backend.c - A backend object that handles the basic D-Bus required for
* a backend.
*
* Author: Iain Holmes <iain@openedhand.com>
*/
#include <config.h>
#include <glib-object.h>
#include <dbus/dbus-glib-bindings.h>
#include <dbus/dbus.h>
#include <geoclue/gc-backend.h>
G_DEFINE_ABSTRACT_TYPE (GcBackend, gc_backend, G_TYPE_OBJECT)
static void
finalize (GObject *object)
{
((GObjectClass *) gc_backend_parent_class)->finalize (object);
}
static void
dispose (GObject *object)
{
((GObjectClass *) gc_backend_parent_class)->dispose (object);
}
static void
gc_backend_class_init (GcBackendClass *klass)
{
GObjectClass *o_class = (GObjectClass *) klass;
o_class->finalize = finalize;
o_class->dispose = dispose;
}
static void
gc_backend_init (GcBackend *backend)
{
GError *error = NULL;
backend->connection = dbus_g_bus_get (GEOCLUE_DBUS_BUS, &error);
if (backend->connection == NULL) {
g_warning ("%s was unable to create a connection to D-Bus: %s",
G_OBJECT_TYPE_NAME (backend), error->message);
g_error_free (error);
}
}
/**
* gc_backend_set_details:
* @backend: A #GcBackend object
* @service: The service that the object implements
* @path: The path that the object should be registered at
*
* Requests ownership of the @service name, and if that succeeds registers
* @backend at @path.
*/
void
gc_backend_set_details (GcBackend *backend,
const char *service,
const char *path)
{
GError *error = NULL;
DBusGProxy *driver;
guint request_ret;
g_return_if_fail (GC_IS_BACKEND (backend));
g_return_if_fail (backend->connection != NULL);
g_return_if_fail (service != NULL);
g_return_if_fail (path != NULL);
driver = dbus_g_proxy_new_for_name (backend->connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
if (!org_freedesktop_DBus_request_name (driver, service, 0,
&request_ret, &error)) {
g_warning ("%s was unable to register service %s: %s",
G_OBJECT_TYPE_NAME (backend), service,
error->message);
g_error_free (error);
return;
}
dbus_g_connection_register_g_object (backend->connection,
path, G_OBJECT (backend));
}
/*
* Geoclue
* gc-backend.h - A backend object that handles the basic D-Bus required for
* a backend.
*
* Author: Iain Holmes <iain@openedhand.com>
*/
#ifndef _GC_BACKEND
#define _GC_BACKEND
G_BEGIN_DECLS
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#define GC_TYPE_BACKEND (gc_backend_get_type ())
#define GC_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GC_TYPE_BACKEND, GcBackend))
#define GC_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GC_TYPE_BACKEND, GcBackendClass))
#define GC_IS_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GC_TYPE_BACKEND))
#define GC_IS_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GC_TYPE_BACKEND))
typedef struct _GcBackend {
GObject parent_class;
DBusGConnection *connection;
} GcBackend;
typedef struct _GcBackendClass {
GObjectClass parent_class;
} GcBackendClass;
GType gc_backend_get_type (void);
void gc_backend_set_details (GcBackend *backend,
const char *service,
const char *path);
G_END_DECLS
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment