Commit 67e64ad5 authored by Martyn Russell's avatar Martyn Russell

Removed tracker-dbus from libtracker-miner

The code has been added internally to tracker-miner.c
parent c951045a
......@@ -2,11 +2,28 @@
<node name="/">
<interface name="org.freedesktop.Tracker.Miner">
<!--
<method name="GetName">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="name" direction="out" />
</method>
<method name="GetStatus">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="status" direction="out" />
</method>
<method name="GetProgress">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="d" name="progress" direction="out" />
</method>
-->
<method name="Pause">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
</method>
<method name="Resume">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
</method>
<signal name="Error">
<arg type="s" name="reason"/>
</signal>
</interface>
</node>
......@@ -26,8 +26,6 @@ libtracker_miner_LTLIBRARIES = libtracker-miner.la
libtracker_miner_la_SOURCES = \
tracker-crawler.c \
tracker-crawler.h \
tracker-dbus.c \
tracker-dbus.h \
tracker-marshal.c \
tracker-marshal.h \
tracker-miner-dbus.h \
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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 library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <string.h>
#include "tracker-dbus.h"
#include "tracker-miner-dbus.h"
#include "tracker-miner-glue.h"
typedef struct {
DBusGConnection *connection;
DBusGProxy *gproxy;
GHashTable *name_monitors;
} TrackerDBusData;
static GQuark dbus_data = 0;
static gboolean
dbus_register_service (DBusGProxy *proxy,
const gchar *name)
{
GError *error = NULL;
guint result;
g_message ("Registering DBus service...\n"
" Name:'%s'",
name);
if (!org_freedesktop_DBus_request_name (proxy,
name,
DBUS_NAME_FLAG_DO_NOT_QUEUE,
&result, &error)) {
g_critical ("Could not acquire name:'%s', %s",
name,
error ? error->message : "no error given");
g_error_free (error);
return FALSE;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_critical ("DBus service name:'%s' is already taken, "
"perhaps the application is already running?",
name);
return FALSE;
}
return TRUE;
}
static gboolean
dbus_register_object (GObject *object,
DBusGConnection *connection,
DBusGProxy *proxy,
const DBusGObjectInfo *info,
const gchar *path)
{
g_message ("Registering DBus object...");
g_message (" Path:'%s'", path);
g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (object));
dbus_g_object_type_install_info (G_OBJECT_TYPE (object), info);
dbus_g_connection_register_g_object (connection, path, object);
return TRUE;
}
static void
dbus_data_destroy (gpointer data)
{
TrackerDBusData *dd;
dd = data;
if (dd->gproxy) {
g_object_unref (dd->gproxy);
}
if (dd->connection) {
dbus_g_connection_unref (dd->connection);
}
if (dd->name_monitors) {
g_hash_table_destroy (dd->name_monitors);
}
g_slice_free (TrackerDBusData, dd);
}
static TrackerDBusData *
dbus_data_create (TrackerMiner *miner,
const gchar *name)
{
TrackerDBusData *data;
DBusGConnection *connection;
DBusGProxy *gproxy;
GError *error = NULL;
gchar *full_name, *full_path;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!connection) {
g_critical ("Could not connect to the DBus session bus, %s",
error ? error->message : "no error given.");
g_error_free (error);
return NULL;
}
gproxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
/* Register the service name for the miner */
full_name = g_strconcat ("org.freedesktop.Tracker.Miner.", name, NULL);
if (!dbus_register_service (gproxy, full_name)) {
g_object_unref (gproxy);
g_free (full_name);
return NULL;
}
g_free (full_name);
full_path = g_strconcat ("/org/freedesktop/Tracker/Miner/", name, NULL);
if (!dbus_register_object (G_OBJECT (miner),
connection, gproxy,
&dbus_glib_tracker_miner_object_info,
full_path)) {
g_object_unref (gproxy);
g_free (full_path);
return NULL;
}
g_free (full_path);
/* Now we're successfully connected and registered, create the data */
data = g_slice_new0 (TrackerDBusData);
data->connection = dbus_g_connection_ref (connection);
data->gproxy = g_object_ref (gproxy);
return data;
}
gboolean
tracker_dbus_init (TrackerMiner *miner)
{
TrackerDBusData *data;
g_return_val_if_fail (TRACKER_IS_MINER (miner), FALSE);
if (G_UNLIKELY (dbus_data == 0)) {
dbus_data = g_quark_from_static_string ("tracker-miner-dbus-data");
}
data = g_object_get_qdata (G_OBJECT (miner), dbus_data);
if (G_LIKELY (!data)) {
const gchar *name;
name = tracker_miner_get_name (miner);
data = dbus_data_create (miner, name);
}
if (G_UNLIKELY (!data)) {
return FALSE;
}
g_object_set_qdata_full (G_OBJECT (miner),
dbus_data,
data,
dbus_data_destroy);
return TRUE;
}
void
tracker_dbus_shutdown (TrackerMiner *miner)
{
if (dbus_data == 0) {
return;
}
g_object_set_qdata (G_OBJECT (miner), dbus_data, NULL);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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 library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __TRACKER_DBUS_H__
#define __TRACKER_DBUS_H__
#include <glib.h>
#include <dbus/dbus-glib-bindings.h>
#include "tracker-miner.h"
G_BEGIN_DECLS
gboolean tracker_dbus_init (TrackerMiner *miner);
void tracker_dbus_shutdown (TrackerMiner *miner);
G_END_DECLS
#endif /* __TRACKER_DBUS_H__ */
......@@ -23,7 +23,6 @@
#include <glib-object.h>
#include "tracker-dbus.h"
#include "tracker-miner.h"
G_BEGIN_DECLS
......
......@@ -338,7 +338,7 @@ process_finalize (GObject *object)
static gboolean
process_defaults (TrackerMinerProcess *process,
GFile *file)
GFile *file)
{
return TRUE;
}
......
......@@ -25,6 +25,7 @@
#include "tracker-marshal.h"
#include "tracker-miner.h"
#include "tracker-miner-dbus.h"
#include "tracker-miner-glue.h"
#define TRACKER_MINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER, TrackerMinerPrivate))
......@@ -36,6 +37,12 @@ struct TrackerMinerPrivate {
gdouble progress;
};
typedef struct {
DBusGConnection *connection;
DBusGProxy *gproxy;
GHashTable *name_monitors;
} DBusData;
enum {
PROP_0,
PROP_NAME,
......@@ -50,9 +57,12 @@ enum {
RESUMED,
TERMINATED,
PROGRESS,
ERROR,
LAST_SIGNAL
};
static GQuark dbus_data = 0;
static guint signals[LAST_SIGNAL] = { 0 };
......@@ -66,6 +76,9 @@ static void miner_get_property (GObject *object,
GParamSpec *pspec);
static void miner_finalize (GObject *object);
static void miner_constructed (GObject *object);
static gboolean terminate_miner_cb (TrackerMiner *miner);
static gboolean dbus_init (TrackerMiner *miner);
static void dbus_shutdown (TrackerMiner *miner);
G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
......@@ -123,12 +136,21 @@ tracker_miner_class_init (TrackerMinerClass *klass)
g_signal_new ("progress",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TrackerMinerClass, terminated),
G_STRUCT_OFFSET (TrackerMinerClass, progress),
NULL, NULL,
tracker_marshal_VOID__STRING_DOUBLE,
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_DOUBLE);
signals[ERROR] =
g_signal_new ("error",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TrackerMinerClass, error),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
g_object_class_install_property (object_class,
PROP_NAME,
......@@ -227,9 +249,27 @@ miner_finalize (GObject *object)
tracker_disconnect (miner->private->client);
}
dbus_shutdown (miner);
G_OBJECT_CLASS (tracker_miner_parent_class)->finalize (object);
}
static void
miner_constructed (GObject *object)
{
TrackerMiner *miner = TRACKER_MINER (object);
if (!miner->private->name) {
g_critical ("Miner should have been given a name, bailing out");
g_assert_not_reached ();
}
if (!dbus_init (miner)) {
g_critical ("Could not register object to DBus");
g_idle_add ((GSourceFunc) terminate_miner_cb, miner);
}
}
static gboolean
terminate_miner_cb (TrackerMiner *miner)
{
......@@ -238,20 +278,174 @@ terminate_miner_cb (TrackerMiner *miner)
return TRUE;
}
static gboolean
dbus_register_service (DBusGProxy *proxy,
const gchar *name)
{
GError *error = NULL;
guint result;
g_message ("Registering DBus service...\n"
" Name:'%s'",
name);
if (!org_freedesktop_DBus_request_name (proxy,
name,
DBUS_NAME_FLAG_DO_NOT_QUEUE,
&result, &error)) {
g_critical ("Could not acquire name:'%s', %s",
name,
error ? error->message : "no error given");
g_error_free (error);
return FALSE;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_critical ("DBus service name:'%s' is already taken, "
"perhaps the application is already running?",
name);
return FALSE;
}
return TRUE;
}
static gboolean
dbus_register_object (GObject *object,
DBusGConnection *connection,
DBusGProxy *proxy,
const DBusGObjectInfo *info,
const gchar *path)
{
g_message ("Registering DBus object...");
g_message (" Path:'%s'", path);
g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (object));
dbus_g_object_type_install_info (G_OBJECT_TYPE (object), info);
dbus_g_connection_register_g_object (connection, path, object);
return TRUE;
}
static void
miner_constructed (GObject *object)
dbus_data_destroy (gpointer data)
{
TrackerMiner *miner = TRACKER_MINER (object);
DBusData *dd;
if (!miner->private->name) {
g_critical ("Miner should have been given a name, bailing out");
g_assert_not_reached ();
dd = data;
if (dd->gproxy) {
g_object_unref (dd->gproxy);
}
if (!tracker_dbus_init (miner)) {
g_critical ("Could not register object to DBus");
g_idle_add ((GSourceFunc) terminate_miner_cb, miner);
if (dd->connection) {
dbus_g_connection_unref (dd->connection);
}
if (dd->name_monitors) {
g_hash_table_destroy (dd->name_monitors);
}
g_slice_free (DBusData, dd);
}
static DBusData *
dbus_data_create (TrackerMiner *miner,
const gchar *name)
{
DBusData *data;
DBusGConnection *connection;
DBusGProxy *gproxy;
GError *error = NULL;
gchar *full_name, *full_path;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!connection) {
g_critical ("Could not connect to the DBus session bus, %s",
error ? error->message : "no error given.");
g_error_free (error);
return NULL;
}
gproxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
/* Register the service name for the miner */
full_name = g_strconcat ("org.freedesktop.Tracker.Miner.", name, NULL);
if (!dbus_register_service (gproxy, full_name)) {
g_object_unref (gproxy);
g_free (full_name);
return NULL;
}
g_free (full_name);
full_path = g_strconcat ("/org/freedesktop/Tracker/Miner/", name, NULL);
if (!dbus_register_object (G_OBJECT (miner),
connection, gproxy,
&dbus_glib_tracker_miner_object_info,
full_path)) {
g_object_unref (gproxy);
g_free (full_path);
return NULL;
}
g_free (full_path);
/* Now we're successfully connected and registered, create the data */
data = g_slice_new0 (DBusData);
data->connection = dbus_g_connection_ref (connection);
data->gproxy = g_object_ref (gproxy);
return data;
}
static gboolean
dbus_init (TrackerMiner *miner)
{
DBusData *data;
g_return_val_if_fail (TRACKER_IS_MINER (miner), FALSE);
if (G_UNLIKELY (dbus_data == 0)) {
dbus_data = g_quark_from_static_string ("tracker-miner-dbus-data");
}
data = g_object_get_qdata (G_OBJECT (miner), dbus_data);
if (G_LIKELY (!data)) {
const gchar *name;
name = tracker_miner_get_name (miner);
data = dbus_data_create (miner, name);
}
if (G_UNLIKELY (!data)) {
return FALSE;
}
g_object_set_qdata_full (G_OBJECT (miner),
dbus_data,
data,
dbus_data_destroy);
return TRUE;
}
static void
dbus_shutdown (TrackerMiner *miner)
{
if (dbus_data == 0) {
return;
}
g_object_set_qdata (G_OBJECT (miner), dbus_data, NULL);
}
G_CONST_RETURN gchar *
......@@ -275,7 +469,7 @@ tracker_miner_get_status (TrackerMiner *miner)
{
g_return_val_if_fail (TRACKER_IS_MINER (miner), NULL);
return g_strdup ("Idle");
return g_strdup (miner->private->status);
}
gdouble
......@@ -283,7 +477,7 @@ tracker_miner_get_progress (TrackerMiner *miner)
{
g_return_val_if_fail (TRACKER_IS_MINER (miner), 0.0);
return 0.0;
return miner->private->progress;
}
/* DBus methods */
......
......@@ -56,6 +56,9 @@ struct TrackerMinerClass {
void (* progress) (TrackerMiner *miner,
const gchar *status,
gdouble progress);
void (* error) (TrackerMiner *miner,
GError *error);
};
......
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