diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-07-01 15:21:18 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2019-07-11 23:20:59 +0200 |
commit | 222874299eb16cba8e71ff2b4152d364615f2235 (patch) | |
tree | 123c38497e8da4187d1b90a2a0afd67bbb930967 /cli/mmcli-call.c | |
parent | 81f1483eecb26ff16576e28a7058b37f095584c1 (diff) |
api,call: new Deflect() method
This method allows deflecting an incoming or waiting call to a
different number.
Diffstat (limited to 'cli/mmcli-call.c')
-rw-r--r-- | cli/mmcli-call.c | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/cli/mmcli-call.c b/cli/mmcli-call.c index a871dbc0..83a0c017 100644 --- a/cli/mmcli-call.c +++ b/cli/mmcli-call.c @@ -46,11 +46,12 @@ typedef struct { static Context *ctx; /* Options */ -static gboolean info_flag; /* set when no action found */ -static gboolean start_flag; -static gboolean accept_flag; -static gboolean hangup_flag; -static gchar *dtmf_request; +static gboolean info_flag; /* set when no action found */ +static gboolean start_flag; +static gboolean accept_flag; +static gchar *deflect_str; +static gboolean hangup_flag; +static gchar *dtmf_request; static GOptionEntry entries[] = { { "start", 0, 0, G_OPTION_ARG_NONE, &start_flag, @@ -61,6 +62,10 @@ static GOptionEntry entries[] = { "Accept the incoming call", NULL, }, + { "deflect", 0, 0, G_OPTION_ARG_STRING, &deflect_str, + "Deflect the incoming call", + "[NUMBER]", + }, { "hangup", 0, 0, G_OPTION_ARG_NONE, &hangup_flag, "Hang up the call", NULL, @@ -99,6 +104,7 @@ mmcli_call_options_enabled (void) n_actions = (start_flag + accept_flag + + !!deflect_str + hangup_flag + !!dtmf_request); @@ -228,6 +234,33 @@ accept_ready (MMCall *call, } static void +deflect_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't deflect the call: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully deflected the call\n"); +} + +static void +deflect_ready (MMCall *call, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_call_deflect_finish (call, result, &error); + deflect_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + +static void hangup_process_reply (gboolean result, const GError *error) { @@ -313,6 +346,16 @@ get_call_ready (GObject *source, return; } + /* Requesting to deflect the call? */ + if (deflect_str) { + mm_call_deflect (ctx->call, + deflect_str, + ctx->cancellable, + (GAsyncReadyCallback)deflect_ready, + NULL); + return; + } + /* Requesting to hangup the call? */ if (hangup_flag) { mm_call_hangup (ctx->call, @@ -398,6 +441,18 @@ mmcli_call_run_synchronous (GDBusConnection *connection) return; } + /* Requesting to deflect the call? */ + if (deflect_str) { + gboolean operation_result; + + operation_result = mm_call_deflect_sync (ctx->call, + deflect_str, + NULL, + &error); + deflect_process_reply (operation_result, error); + return; + } + /* Requesting to hangup the call? */ if (hangup_flag) { gboolean operation_result; |