Commit 4ba2889b authored by Martin Bürgmann's avatar Martin Bürgmann Committed by Martin Bürgmann
Browse files

implement fbd_dev_sound_stop

tracks the FdbFeedbackSounds in a GHashTable in the FdbDevSound
parent aac3306a
Pipeline #64131 passed with stages
in 8 minutes and 53 seconds
......@@ -29,6 +29,8 @@
typedef struct _FbdAsyncData {
FbdDevSoundPlayedCallback callback;
FbdFeedbackSound *feedback;
FbdDevSound *dev;
GCancellable *playback;
} FbdAsyncData;
typedef struct _FbdDevSound {
......@@ -36,6 +38,7 @@ typedef struct _FbdDevSound {
GSoundContext *ctx;
GSettings *sound_settings;
GHashTable *playbacks;
} FbdDevSound;
static void initable_iface_init (GInitableIface *iface);
......@@ -69,6 +72,29 @@ on_sound_theme_name_changed (FbdDevSound *self,
g_warning ("Failed to set sound theme name to %s: %s", key, error->message);
}
static FbdAsyncData*
fbd_async_data_new (FbdDevSound *dev, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback)
{
FbdAsyncData* data;
data = g_new0 (FbdAsyncData, 1);
data->callback = callback;
data->feedback = g_object_ref (feedback);
data->dev = g_object_ref (dev);
data->playback = g_cancellable_new ();
return data;
}
static void
fbd_async_data_dispose (FbdAsyncData *object)
{
g_object_unref (object->feedback);
g_object_unref (object->dev);
g_object_unref (object->playback);
g_free (object);
}
static void
fbd_dev_sound_dispose (GObject *object)
{
......@@ -76,6 +102,7 @@ fbd_dev_sound_dispose (GObject *object)
g_clear_object (&self->ctx);
g_clear_object (&self->sound_settings);
g_clear_object (&self->playbacks);
G_OBJECT_CLASS (fbd_dev_sound_parent_class)->dispose (object);
}
......@@ -88,6 +115,7 @@ initable_init (GInitable *initable,
FbdDevSound *self = FBD_DEV_SOUND (initable);
const char *desktop;
self->playbacks = g_hash_table_new (g_direct_hash, g_direct_equal);
self->ctx = gsound_context_new(NULL, error);
if (!self->ctx)
return FALSE;
......@@ -152,8 +180,9 @@ on_sound_play_finished_callback (GSoundContext *ctx,
}
(*data->callback)(data->feedback);
g_object_unref (data->feedback);
g_free (data);
g_hash_table_remove (data->dev->playbacks, data->feedback);
fbd_async_data_dispose (data);
}
......@@ -165,11 +194,11 @@ fbd_dev_sound_play (FbdDevSound *self, FbdFeedbackSound *feedback, FbdDevSoundPl
g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE);
g_return_val_if_fail (GSOUND_IS_CONTEXT (self->ctx), FALSE);
data = g_new0 (FbdAsyncData, 1);
data->callback = callback;
data->feedback = g_object_ref (feedback);
data = fbd_async_data_new (self, feedback, callback);
gsound_context_play_full (self->ctx, NULL,
g_hash_table_insert (self->playbacks, feedback, data);
gsound_context_play_full (self->ctx, data->playback,
(GAsyncReadyCallback)on_sound_play_finished_callback,
data,
GSOUND_ATTR_EVENT_ID, fbd_feedback_sound_get_effect (feedback),
......@@ -178,3 +207,20 @@ fbd_dev_sound_play (FbdDevSound *self, FbdFeedbackSound *feedback, FbdDevSoundPl
NULL);
return TRUE;
}
gboolean
fbd_dev_sound_stop(FbdDevSound *self, FbdFeedbackSound *feedback)
{
FbdAsyncData *data;
g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE);
data = g_hash_table_lookup (self->playbacks, feedback);
if (data == NULL)
return FALSE;
g_cancellable_cancel (data->playback);
return TRUE;
}
......@@ -154,10 +154,3 @@ const char *fbd_feedback_sound_get_effect (FbdFeedbackSound *self)
{
return self->effect;
}
gboolean
fbd_dev_sound_stop(FbdDevSound *self, FbdFeedbackSound *feedback)
{
/* TODO: can we use cancellable to actually end playback? */
return TRUE;
}
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