Commit dbf8e818 authored by Martyn Russell's avatar Martyn Russell

Make the dbus functions use a _dbus_ prefix

This is so we can internally use pause/resume and other APIs without
needing the dbus machinery.
parent a1d48eee
......@@ -2,6 +2,7 @@
<node name="/">
<interface name="org.freedesktop.Tracker.Miner">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="tracker_miner_dbus"/>
<method name="GetName">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="name" direction="out" />
......@@ -23,7 +24,7 @@
<arg type="b" name="is_paused" direction="out" />
</method>
<method name="Pause">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="application" direction="in" />
<arg type="s" name="reason" direction="in" />
<arg type="i" name="cookie" direction="out" />
......
......@@ -29,9 +29,9 @@ libtracker_miner_la_SOURCES = \
tracker-crawler.h \
tracker-marshal.c \
tracker-marshal.h \
tracker-miner-dbus.h \
tracker-miner.c \
tracker-miner.h \
tracker-miner-dbus.h \
tracker-miner-discover.c \
tracker-miner-discover.h \
tracker-miner-fs.c \
......@@ -43,6 +43,7 @@ libtracker_miner_la_SOURCES = \
libtracker_minerinclude_HEADERS = \
tracker-miner.h \
tracker-miner-dbus.h \
tracker-miner-fs.h
libtracker_miner_la_LDFLAGS = \
......
......@@ -27,30 +27,30 @@
G_BEGIN_DECLS
void tracker_miner_get_name (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_get_description (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_get_status (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_get_progress (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_get_is_paused (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_pause (TrackerMiner *miner,
const gchar *application,
const gchar *name,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_resume (TrackerMiner *miner,
gint cookie,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_get_name (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_get_description (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_get_status (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_get_progress (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_get_is_paused (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_pause (TrackerMiner *miner,
const gchar *application,
const gchar *name,
DBusGMethodInvocation *context,
GError **error);
void tracker_miner_dbus_resume (TrackerMiner *miner,
gint cookie,
DBusGMethodInvocation *context,
GError **error);
G_END_DECLS
......
......@@ -329,6 +329,12 @@ miner_constructed (GObject *object)
dbus_data_destroy);
}
GQuark
tracker_miner_error_quark (void)
{
return g_quark_from_static_string (TRACKER_MINER_ERROR_DOMAIN);
}
static gboolean
terminate_miner_cb (TrackerMiner *miner)
{
......@@ -554,11 +560,60 @@ tracker_miner_execute_sparql (TrackerMiner *miner,
return FALSE;
}
gint
tracker_miner_pause (TrackerMiner *miner,
const gchar *application,
const gchar *reason,
GError **error)
{
PauseData *pd;
g_return_val_if_fail (TRACKER_IS_MINER (miner), -1);
g_return_val_if_fail (application != NULL, -1);
g_return_val_if_fail (reason != NULL, -1);
pd = pause_data_new (application, reason);
g_hash_table_insert (miner->private->pauses,
GINT_TO_POINTER (pd->cookie),
pd);
if (g_hash_table_size (miner->private->pauses) == 1) {
/* Pause */
g_message ("Miner is pausing");
}
return pd->cookie;
}
gboolean
tracker_miner_resume (TrackerMiner *miner,
gint cookie,
GError **error)
{
g_return_val_if_fail (TRACKER_IS_MINER (miner), FALSE);
if (!g_hash_table_remove (miner->private->pauses, GINT_TO_POINTER (cookie))) {
g_set_error (error, TRACKER_MINER_ERROR, 0,
"%s",
_("Cookie not recognised to resume paused miner"));
return FALSE;
}
if (g_hash_table_size (miner->private->pauses) == 0) {
/* Resume */
g_message ("Miner is resuming");
}
return TRUE;
}
/* DBus methods */
void
tracker_miner_get_name (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_get_name (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
{
guint request_id;
......@@ -574,9 +629,9 @@ tracker_miner_get_name (TrackerMiner *miner,
}
void
tracker_miner_get_description (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_get_description (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
{
guint request_id;
......@@ -592,9 +647,9 @@ tracker_miner_get_description (TrackerMiner *miner,
}
void
tracker_miner_get_status (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_get_status (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
{
guint request_id;
......@@ -610,9 +665,9 @@ tracker_miner_get_status (TrackerMiner *miner,
}
void
tracker_miner_get_progress (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_get_progress (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
{
guint request_id;
......@@ -628,9 +683,9 @@ tracker_miner_get_progress (TrackerMiner *miner,
}
void
tracker_miner_get_is_paused (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_get_is_paused (TrackerMiner *miner,
DBusGMethodInvocation *context,
GError **error)
{
guint request_id;
gboolean is_paused;
......@@ -648,14 +703,15 @@ tracker_miner_get_is_paused (TrackerMiner *miner,
}
void
tracker_miner_pause (TrackerMiner *miner,
const gchar *application,
const gchar *reason,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_pause (TrackerMiner *miner,
const gchar *application,
const gchar *reason,
DBusGMethodInvocation *context,
GError **error)
{
GError *local_error = NULL;
guint request_id;
PauseData *pd;
gint cookie;
request_id = tracker_dbus_get_next_request_id ();
......@@ -668,28 +724,32 @@ tracker_miner_pause (TrackerMiner *miner,
application,
reason);
pd = pause_data_new (application, reason);
cookie = tracker_miner_pause (miner, application, reason, &local_error);
if (cookie == -1) {
GError *actual_error = NULL;
g_hash_table_insert (miner->private->pauses,
GINT_TO_POINTER (pd->cookie),
pd);
tracker_dbus_request_failed (request_id,
&actual_error,
local_error ? local_error->message : NULL);
dbus_g_method_return_error (context, actual_error);
g_error_free (actual_error);
g_error_free (local_error);
if (g_hash_table_size (miner->private->pauses) == 1) {
/* Pause */
g_message ("Miner is pausing");
return;
}
dbus_g_method_return (context, pd->cookie);
dbus_g_method_return (context, cookie);
tracker_dbus_request_success (request_id);
}
void
tracker_miner_resume (TrackerMiner *miner,
gint cookie,
DBusGMethodInvocation *context,
GError **error)
tracker_miner_dbus_resume (TrackerMiner *miner,
gint cookie,
DBusGMethodInvocation *context,
GError **error)
{
GError *local_error = NULL;
guint request_id;
request_id = tracker_dbus_get_next_request_id ();
......@@ -700,21 +760,20 @@ tracker_miner_resume (TrackerMiner *miner,
__PRETTY_FUNCTION__,
cookie);
if (!g_hash_table_remove (miner->private->pauses, GINT_TO_POINTER (cookie))) {
if (!tracker_miner_resume (miner, cookie, &local_error)) {
GError *actual_error = NULL;
tracker_dbus_request_failed (request_id,
&actual_error,
"Cookie not recognised to resume paused miner");
local_error ? local_error->message : NULL);
dbus_g_method_return_error (context, actual_error);
g_error_free (actual_error);
} else {
if (g_hash_table_size (miner->private->pauses) == 0) {
/* Resume */
g_message ("Miner is resuming");
}
g_error_free (local_error);
dbus_g_method_return (context);
tracker_dbus_request_success (request_id);
return;
}
dbus_g_method_return (context);
tracker_dbus_request_success (request_id);
}
......@@ -37,6 +37,9 @@ G_BEGIN_DECLS
#define TRACKER_MINER_DBUS_NAME_PREFIX "org.freedesktop.Tracker.Miner."
#define TRACKER_MINER_DBUS_PATH_PREFIX "/org/freedesktop/Tracker/Miner/"
#define TRACKER_MINER_ERROR_DOMAIN "TrackerMiner"
#define TRACKER_MINER_ERROR tracker_miner_error_quark()
typedef struct TrackerMiner TrackerMiner;
typedef struct TrackerMinerClass TrackerMinerClass;
typedef struct TrackerMinerPrivate TrackerMinerPrivate;
......@@ -66,7 +69,8 @@ struct TrackerMinerClass {
GError *error);
};
GType tracker_miner_get_type (void) G_GNUC_CONST;
GType tracker_miner_get_type (void) G_GNUC_CONST;
GQuark tracker_miner_error_quark (void);
void tracker_miner_start (TrackerMiner *miner);
void tracker_miner_stop (TrackerMiner *miner);
......@@ -75,6 +79,14 @@ TrackerClient *tracker_miner_get_client (TrackerMiner *miner);
gboolean tracker_miner_execute_sparql (TrackerMiner *miner,
const gchar *sparql,
GError **error);
gint tracker_miner_pause (TrackerMiner *miner,
const gchar *application,
const gchar *reason,
GError **error);
gboolean tracker_miner_resume (TrackerMiner *miner,
gint cookie,
GError **error);
G_END_DECLS
......
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