[empathy] mic-monitor: add get_default function



commit e5cd9e64870fbca5bc57d205ba4fe9aadb726614
Author: Jonny Lamb <jonny lamb collabora co uk>
Date:   Wed Aug 17 15:59:29 2011 +0100

    mic-monitor: add get_default function
    
    Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>

 src/empathy-mic-monitor.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
 src/empathy-mic-monitor.h |    5 ++++
 2 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/empathy-mic-monitor.c b/src/empathy-mic-monitor.c
index 5a90e17..2e1171b 100644
--- a/src/empathy-mic-monitor.c
+++ b/src/empathy-mic-monitor.c
@@ -564,3 +564,61 @@ empathy_mic_monitor_get_current_mic_finish (EmpathyMicMonitor *self,
   return GPOINTER_TO_UINT (
       g_simple_async_result_get_op_res_gpointer (simple));
 }
+
+/* operation: get default */
+static void
+empathy_mic_monitor_get_default_cb (pa_context *context,
+    const pa_server_info *info,
+    void *userdata)
+{
+  GSimpleAsyncResult *result = userdata;
+
+  /* TODO: it would be nice in future, for consistency, if this gave
+   * the source idx instead of the name. */
+  g_simple_async_result_set_op_res_gpointer (result,
+      g_strdup (info->default_source_name), g_free);
+  g_simple_async_result_complete (result);
+  g_object_unref (result);
+}
+
+static void
+operation_get_default (EmpathyMicMonitor *self,
+    GSimpleAsyncResult *result)
+{
+  EmpathyMicMonitorPrivate *priv = self->priv;
+
+  g_assert_cmpuint (pa_context_get_state (priv->context), ==, PA_CONTEXT_READY);
+
+  /* unset this so we can use it in the cb */
+  g_simple_async_result_set_op_res_gpointer (result, NULL, NULL);
+
+  pa_context_get_server_info (priv->context, empathy_mic_monitor_get_default_cb,
+      result);
+}
+
+void
+empathy_mic_monitor_get_default_async (EmpathyMicMonitor *self,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  EmpathyMicMonitorPrivate *priv = self->priv;
+  Operation *operation;
+  GSimpleAsyncResult *simple;
+
+  simple = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+      empathy_mic_monitor_get_default_async);
+
+  operation = operation_new (operation_get_default, simple);
+  g_queue_push_tail (priv->operations, operation);
+
+  operations_run (self);
+}
+
+const gchar *
+empathy_mic_monitor_get_default_finish (EmpathyMicMonitor *self,
+    GAsyncResult *result,
+    GError **error)
+{
+  empathy_implement_finish_return_pointer (self,
+      empathy_mic_monitor_get_default_async);
+}
diff --git a/src/empathy-mic-monitor.h b/src/empathy-mic-monitor.h
index 69106c5..5e2a7c5 100644
--- a/src/empathy-mic-monitor.h
+++ b/src/empathy-mic-monitor.h
@@ -75,6 +75,11 @@ void empathy_mic_monitor_get_current_mic_async (EmpathyMicMonitor *self,
 guint empathy_mic_monitor_get_current_mic_finish (EmpathyMicMonitor *self,
     GAsyncResult *result, GError **error);
 
+void empathy_mic_monitor_get_default_async (EmpathyMicMonitor *self,
+    GAsyncReadyCallback callback, gpointer user_data);
+const gchar * empathy_mic_monitor_get_default_finish (EmpathyMicMonitor *self,
+    GAsyncResult *result, GError **error);
+
 G_END_DECLS
 
 #endif /* __EMPATHY_MIC_MONITOR_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]