Commit 08378f29 authored by Arnaud Ferraris's avatar Arnaud Ferraris
Browse files

libcallaudio: add async API

Fixes #1
parent 53cf7e0f
......@@ -75,19 +75,55 @@ void call_audio_deinit(void)
g_clear_object(&_proxy);
}
static void select_mode_done(GObject *object, GAsyncResult *result, gpointer data)
{
CallAudioDbusCallAudio *proxy = CALL_AUDIO_DBUS_CALL_AUDIO(object);
CallAudioCallback cb = data;
GError *error = NULL;
gboolean success = FALSE;
gboolean ret;
g_return_if_fail(CALL_AUDIO_DBUS_IS_CALL_AUDIO(proxy));
ret = call_audio_dbus_call_audio_call_select_mode_finish(proxy, &success,
result, &error);
if (!ret || !success) {
g_warning("SelectMode failed with code %d: %s", success, error->message);
}
g_debug("%s: D-bus call returned %d (success=%d)", __func__, ret, success);
if (cb)
cb(ret, error);
}
/**
* call_audio_select_mode:
* call_audio_select_mode_async:
* @mode: Audio mode to select
* @cb: Function to be called when operation completes
*
* Select the audio mode to use.
*/
void call_audio_select_mode_async(CallAudioMode mode, CallAudioCallback cb)
{
call_audio_dbus_call_audio_call_select_mode(_proxy, mode, NULL,
select_mode_done, cb);
}
/**
* call_audio_select_mode:
* @mode: Audio mode to select
*
* Select the audio mode to use. This function is synchronous, and will return
* only once the operation has been executed.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_select_mode(CallAudioMode mode)
{
GError *error = NULL;
gboolean success = FALSE;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_select_mode_sync(_proxy, mode, &success,
NULL, &error);
......@@ -99,19 +135,55 @@ gboolean call_audio_select_mode(CallAudioMode mode)
return (ret && success);
}
static void enable_speaker_done(GObject *object, GAsyncResult *result, gpointer data)
{
CallAudioDbusCallAudio *proxy = CALL_AUDIO_DBUS_CALL_AUDIO(object);
CallAudioCallback cb = data;
GError *error = NULL;
gboolean success = FALSE;
gboolean ret;
g_return_if_fail(CALL_AUDIO_DBUS_IS_CALL_AUDIO(proxy));
ret = call_audio_dbus_call_audio_call_enable_speaker_finish(proxy, &success,
result, &error);
if (!ret || !success) {
g_warning("EnableSpeaker failed with code %d: %s", success, error->message);
}
g_debug("%s: D-bus call returned %d (success=%d)", __func__, ret, success);
if (cb)
cb(ret, error);
}
/**
* call_audio_enable_speaker:
* call_audio_enable_speaker_async:
* @enable: Desired speaker state
* @cb: Function to be called when operation completes
*
* Enable or disable speaker output.
*/
void call_audio_enable_speaker_async(gboolean enable, CallAudioCallback cb)
{
call_audio_dbus_call_audio_call_enable_speaker(_proxy, enable, NULL,
enable_speaker_done, cb);
}
/**
* call_audio_enable_speaker:
* @enable: Desired speaker state
*
* Enable or disable speaker output. This function is synchronous, and will
* return only once the operation has been executed.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_enable_speaker(gboolean enable)
{
gboolean success;
gboolean ret;
GError *error = NULL;
gboolean success = FALSE;
gboolean ret;
ret = call_audio_dbus_call_audio_call_enable_speaker_sync(_proxy, enable, &success,
NULL, &error);
......@@ -121,22 +193,56 @@ gboolean call_audio_enable_speaker(gboolean enable)
g_debug("EnableSpeaker %s: success=%d", ret ? "succeeded" : "failed", success);
return (ret && success);
}
static void mute_mic_done(GObject *object, GAsyncResult *result, gpointer data)
{
CallAudioDbusCallAudio *proxy = CALL_AUDIO_DBUS_CALL_AUDIO(object);
CallAudioCallback cb = data;
GError *error = NULL;
gboolean success = 0;
gboolean ret;
g_return_if_fail(CALL_AUDIO_DBUS_IS_CALL_AUDIO(proxy));
ret = call_audio_dbus_call_audio_call_mute_mic_finish(proxy, &success,
result, &error);
if (!ret || !success)
g_warning("MuteMic failed with code %d: %s", success, error->message);
g_debug("%s: D-bus call returned %d (success=%d)", __func__, ret, success);
if (cb)
cb(success, error);
}
/**
* call_audio_mute_mic:
* call_audio_mute_mic_async:
* @mute: %TRUE to mute the microphone, or %FALSE to unmute it
* @cb: Function to be called when operation completes
*
* Mute or unmute microphone.
*/
void call_audio_mute_mic_async(gboolean mute, CallAudioCallback cb)
{
call_audio_dbus_call_audio_call_mute_mic(_proxy, mute, NULL,
mute_mic_done, cb);
}
/**
* call_audio_mute_mic:
* @mute: %TRUE to mute the microphone, or %FALSE to unmute it
*
* Mute or unmute microphone. This function is synchronous, and will return
* only once the operation has been executed.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_mute_mic(gboolean mute)
{
GError *error = NULL;
gboolean success = FALSE;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_mute_mic_sync(_proxy, mute, &success,
NULL, &error);
......
......@@ -24,11 +24,21 @@ typedef enum _CallAudioMode {
CALL_AUDIO_MODE_CALL,
} CallAudioMode;
gboolean call_audio_init(GError **error);
void call_audio_deinit(void);
typedef void (*CallAudioCallback)(gboolean success, GError *error);
gboolean call_audio_select_mode(CallAudioMode mode);
gboolean call_audio_enable_speaker(gboolean enable);
gboolean call_audio_mute_mic(gboolean mute);
gboolean call_audio_init(GError **error);
void call_audio_deinit(void);
gboolean call_audio_select_mode(CallAudioMode mode);
void call_audio_select_mode_async(CallAudioMode mode,
CallAudioCallback cb);
gboolean call_audio_enable_speaker(gboolean enable);
void call_audio_enable_speaker_async(gboolean enable,
CallAudioCallback cb);
gboolean call_audio_mute_mic(gboolean mute);
void call_audio_mute_mic_async(gboolean mute,
CallAudioCallback cb);
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