[PATCH] cli: Add --dms-activate-manual

Aleksander Morgado aleksander at lanedo.com
Wed Mar 20 01:41:45 PDT 2013


On 03/20/2013 03:35 AM, armansito at chromium.org wrote:
> From: Arman Uguray <armansito at chromium.org>
> 
> Added the --dms-activate-manual option to the client, which triggers
> manual activation.
> 

Comments below.

> ---
>  cli/qmicli-dms.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 77 insertions(+)
> 
> diff --git a/cli/qmicli-dms.c b/cli/qmicli-dms.c
> index 86e1ff5..186612c 100644
> --- a/cli/qmicli-dms.c
> +++ b/cli/qmicli-dms.c
> @@ -67,6 +67,7 @@ static gboolean get_time_flag;
>  static gboolean get_prl_version_flag;
>  static gboolean get_activation_state_flag;
>  static gchar *activate_automatic_str;
> +static gchar *activate_manual_str;
>  static gboolean get_user_lock_state_flag;
>  static gchar *set_user_lock_state_str;
>  static gchar *set_user_lock_code_str;
> @@ -184,6 +185,10 @@ static GOptionEntry entries[] = {
>        "Request automatic service activation",
>        "[Activation Code]"
>      },
> +    { "dms-activate-manual", 0, 0, G_OPTION_ARG_STRING, &activate_manual_str,
> +      "Request manual service activation",
> +      "[SPC,SID,MDN,MIN]"
> +    },
>      { "dms-get-user-lock-state", 0, 0, G_OPTION_ARG_NONE, &get_user_lock_state_flag,
>        "Get the state of the user lock",
>        NULL,
> @@ -296,6 +301,7 @@ qmicli_dms_options_enabled (void)
>                   get_prl_version_flag +
>                   get_activation_state_flag +
>                   !!activate_automatic_str +
> +                 !!activate_manual_str +
>                   get_user_lock_state_flag +
>                   !!set_user_lock_state_str +
>                   !!set_user_lock_code_str +
> @@ -1704,6 +1710,57 @@ get_activation_state_ready (QmiClientDms *client,
>      shutdown (TRUE);
>  }
>  
> +static QmiMessageDmsActivateManualInput *
> +activate_manual_input_create (const gchar *str)
> +{
> +    QmiMessageDmsActivateManualInput *input;
> +    gchar **split;
> +    GError *error = NULL;
> +
> +    split = g_strsplit (str, ",", 4);


You'll need to make sure that the string was split in 4 chunks, not just
assume it. Just print an error if you didn't get the 4 chunks.


> +    input = qmi_message_dms_activate_manual_input_new ();
> +    if (!qmi_message_dms_activate_manual_input_set_info (
> +            input,
> +            split[0],
> +            split[1],
> +            split[2],
> +            split[3],
> +            &error)) {
> +        g_printerr ("error: couldn't create input data bundle: '%s'\n",
> +                    error->message);
> +        g_error_free (error);
> +        qmi_message_dms_activate_manual_input_unref (input);
> +        input = NULL;
> +    }
> +    return input;
> +}
> +
> +static void
> +activate_manual_ready (QmiClientDms *client,
> +                       GAsyncResult *res)
> +{
> +    QmiMessageDmsActivateManualOutput *output;
> +    GError *error = NULL;

Add a whiteline here.

> +    output = qmi_client_dms_activate_manual_finish (client, res, &error);
> +    if (!output) {
> +        g_printerr ("error: operation failed: %s\n", error->message);
> +        g_error_free (error);
> +        shutdown (FALSE);
> +        return;
> +    }
> +
> +    if (!qmi_message_dms_activate_manual_output_get_result (output, &error)) {
> +        g_printerr ("error: couldn't request automatic service activation: %s\n", error->message);

"error: couldn't request *manual* service activation"

> +        g_error_free (error);
> +        qmi_message_dms_activate_manual_output_unref (output);
> +        shutdown (FALSE);
> +        return;
> +    }
> +
> +    qmi_message_dms_activate_manual_output_unref (output);
> +    shutdown (TRUE);
> +}
> +
>  static QmiMessageDmsActivateAutomaticInput *
>  activate_automatic_input_create (const gchar *str)
>  {
> @@ -3211,6 +3268,26 @@ qmicli_dms_run (QmiDevice *device,
>          return;
>      }
>  
> +    /* Request to activate manually? */
> +    if (activate_manual_str) {
> +        QmiMessageDmsActivateManualInput *input;
> +
> +        g_debug ("Asynchronously requesting manual activation...");
> +        input = activate_manual_input_create (activate_manual_str);
> +        if (!input) {
> +            shutdown (FALSE);
> +            return;
> +        }
> +        qmi_client_dms_activate_manual (ctx->client,
> +                                        input,
> +                                        10,
> +                                        ctx->cancellable,
> +                                        (GAsyncReadyCallback)activate_manual_ready,
> +                                        NULL);
> +        qmi_message_dms_activate_manual_input_unref (input);
> +        return;
> +    }
> +
>      /* Request to get the activation state? */
>      if (get_user_lock_state_flag) {
>          g_debug ("Asynchronously getting user lock state...");
> 


-- 
Aleksander


More information about the libqmi-devel mailing list