]> git.0d.be Git - empathy.git/commitdiff
mic-monitor: add get_default function
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Wed, 17 Aug 2011 14:59:29 +0000 (15:59 +0100)
committerJonny Lamb <jonny.lamb@collabora.co.uk>
Thu, 18 Aug 2011 14:59:11 +0000 (15:59 +0100)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
src/empathy-mic-monitor.c
src/empathy-mic-monitor.h

index 5a90e17184eb803acf0e29b07e559bfab09a6893..2e1171b141526b555619fca0db131af0585e779c 100644 (file)
@@ -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);
+}
index 69106c55daa8ac59f2e0d80b72b9c3bf77d56fbf..5e2a7c504e4ae8ddd09235a33c381c83ad0670e4 100644 (file)
@@ -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__ */