Commit 53cf7e0f authored by Arnaud Ferraris's avatar Arnaud Ferraris
Browse files

d-bus: return operation status using a boolean

Using a uint doesn't make sense here, while a boolean named `success` 
will be much more intuitive
parent b57fa326
......@@ -6,7 +6,7 @@
<!--
SelectMode:
@mode: 0 = default audio mode, 1 = voice call mode
@result: 0 = failure, 1 = success
@success: operation status
Sets the audio routing configuration according to the @mode
parameter.
......@@ -16,17 +16,17 @@
-->
<method name="SelectMode">
<arg direction="in" name="mode" type="u"/>
<arg direction="out" name="result" type="u"/>
<arg direction="out" name="success" type="b"/>
</method>
<method name="EnableSpeaker">
<arg direction="in" name="enable" type="b"/>
<arg direction="out" name="result" type="u"/>
<arg direction="out" name="success" type="b"/>
</method>
<method name="MuteMic">
<arg direction="in" name="mute" type="b"/>
<arg direction="out" name="result" type="u"/>
<arg direction="out" name="success" type="b"/>
</method>
</interface>
</node>
......@@ -85,18 +85,18 @@ void call_audio_deinit(void)
*/
gboolean call_audio_select_mode(CallAudioMode mode)
{
guint result;
gboolean success = FALSE;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_select_mode_sync(_proxy, mode, &result,
ret = call_audio_dbus_call_audio_call_select_mode_sync(_proxy, mode, &success,
NULL, &error);
if (error)
g_critical("Couldn't set mode: %s", error->message);
g_critical("Couldn't set mode %u: %s", mode, error->message);
g_debug("SelectMode %s: return %u", ret ? "succeeded" : "failed", result);
g_debug("SelectMode %s: success=%d", ret ? "succeeded" : "failed", success);
return ret;
return (ret && success);
}
/**
......@@ -109,18 +109,19 @@ gboolean call_audio_select_mode(CallAudioMode mode)
*/
gboolean call_audio_enable_speaker(gboolean enable)
{
guint result;
gboolean success;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_enable_speaker_sync(_proxy, enable, &result,
ret = call_audio_dbus_call_audio_call_enable_speaker_sync(_proxy, enable, &success,
NULL, &error);
if (error)
g_critical("Couldn't enable speaker: %s", error->message);
g_debug("EnableSpeaker %s: return %u", ret ? "succeeded" : "failed", result);
g_debug("EnableSpeaker %s: success=%d", ret ? "succeeded" : "failed", success);
return (ret && success);
return ret;
}
/**
......@@ -133,16 +134,16 @@ gboolean call_audio_enable_speaker(gboolean enable)
*/
gboolean call_audio_mute_mic(gboolean mute)
{
guint result;
gboolean success = FALSE;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_mute_mic_sync(_proxy, mute, &result,
ret = call_audio_dbus_call_audio_call_mute_mic_sync(_proxy, mute, &success,
NULL, &error);
if (error)
g_critical("Couldn't mute mic: %s", error->message);
g_debug("MuteMic %s: return %u", ret ? "succeeded" : "failed", result);
g_debug("MuteMic %s: success=%d", ret ? "succeeded" : "failed", success);
return ret;
return (ret && success);
}
......@@ -29,19 +29,25 @@ static void complete_command_cb(CadOperation *op)
if (!op)
return;
switch (op->type) {
case CAD_OPERATION_SELECT_MODE:
call_audio_dbus_call_audio_complete_select_mode(op->object, op->invocation, op->result);
break;
case CAD_OPERATION_ENABLE_SPEAKER:
call_audio_dbus_call_audio_complete_enable_speaker(op->object, op->invocation, op->result);
break;
case CAD_OPERATION_MUTE_MIC:
call_audio_dbus_call_audio_complete_mute_mic(op->object, op->invocation, op->result);
break;
default:
g_critical("unknown operation %d", op->type);
break;
if (op->success) {
switch (op->type) {
case CAD_OPERATION_SELECT_MODE:
call_audio_dbus_call_audio_complete_select_mode(op->object, op->invocation, op->success);
break;
case CAD_OPERATION_ENABLE_SPEAKER:
call_audio_dbus_call_audio_complete_enable_speaker(op->object, op->invocation, op->success);
break;
case CAD_OPERATION_MUTE_MIC:
call_audio_dbus_call_audio_complete_mute_mic(op->object, op->invocation, op->success);
break;
default:
g_critical("unknown operation %d", op->type);
break;
}
} else {
g_dbus_method_invocation_return_error(op->invocation, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED,
"Operation failed");
}
free(op);
......
......@@ -24,5 +24,5 @@ struct _CadOperation {
CallAudioDbusCallAudio *object;
GDBusMethodInvocation *invocation;
CadOperationCallback callback;
guint result;
gboolean success;
};
......@@ -357,7 +357,7 @@ static void operation_complete_cb(pa_context *ctx, int success, void *data)
CadPulseOperation *operation = data;
g_debug("operation returned %d", success);
operation->op->result = success;
operation->op->success = (gboolean)!!success;
operation->op->callback(operation->op);
free(operation);
......@@ -517,7 +517,7 @@ void cad_pulse_select_mode(guint mode, CadOperation *cad_op)
error:
if (cad_op) {
cad_op->result = 0;
cad_op->success = FALSE;
cad_op->callback(cad_op);
}
if (operation)
......@@ -557,7 +557,7 @@ void cad_pulse_enable_speaker(gboolean enable, CadOperation *cad_op)
error:
if (cad_op) {
cad_op->result = 0;
cad_op->success = FALSE;
cad_op->callback(cad_op);
}
if (operation)
......@@ -597,7 +597,7 @@ void cad_pulse_mute_mic(gboolean mute, CadOperation *cad_op)
error:
if (cad_op) {
cad_op->result = 0;
cad_op->success = FALSE;
cad_op->callback(cad_op);
}
if (operation)
......
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