api,core,mmcli: Add new 'API' support to set-default-storage for SMS
API support has been added to set default storage for SMS. Changes were made to get, set the deafult storage value.
This commit is contained in:
@@ -53,6 +53,7 @@ static gchar *create_str;
|
|||||||
static gchar *create_with_data_str;
|
static gchar *create_with_data_str;
|
||||||
static gchar *create_with_text_str;
|
static gchar *create_with_text_str;
|
||||||
static gchar *delete_str;
|
static gchar *delete_str;
|
||||||
|
static gchar *set_default_storage_str;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "messaging-status", 0, 0, G_OPTION_ARG_NONE, &status_flag,
|
{ "messaging-status", 0, 0, G_OPTION_ARG_NONE, &status_flag,
|
||||||
@@ -79,6 +80,10 @@ static GOptionEntry entries[] = {
|
|||||||
"Delete a SMS from a given modem",
|
"Delete a SMS from a given modem",
|
||||||
"[PATH|INDEX]"
|
"[PATH|INDEX]"
|
||||||
},
|
},
|
||||||
|
{ "set-default-storage", 0, 0, G_OPTION_ARG_STRING, &set_default_storage_str,
|
||||||
|
"Set Default storage for storing SMS",
|
||||||
|
"[Storage]"
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,7 +114,8 @@ mmcli_modem_messaging_options_enabled (void)
|
|||||||
n_actions = (status_flag +
|
n_actions = (status_flag +
|
||||||
list_flag +
|
list_flag +
|
||||||
!!create_str +
|
!!create_str +
|
||||||
!!delete_str);
|
!!delete_str +
|
||||||
|
!!set_default_storage_str);
|
||||||
|
|
||||||
if (n_actions > 1) {
|
if (n_actions > 1) {
|
||||||
g_printerr ("error: too many Messaging actions requested\n");
|
g_printerr ("error: too many Messaging actions requested\n");
|
||||||
@@ -400,6 +406,33 @@ get_sms_to_delete_ready (GDBusConnection *connection,
|
|||||||
g_object_unref (obj);
|
g_object_unref (obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_default_storage_process_reply (gboolean result,
|
||||||
|
const GError *error)
|
||||||
|
{
|
||||||
|
if (!result) {
|
||||||
|
g_printerr ("error: couldn't set default storage: '%s'\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print ("successfully set the default storage\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_default_storage_ready (MMModemMessaging *modem,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer nothing)
|
||||||
|
{
|
||||||
|
gboolean operation_result;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
operation_result = mm_modem_messaging_set_default_storage_finish (modem, result, &error);
|
||||||
|
set_default_storage_process_reply (operation_result, error);
|
||||||
|
|
||||||
|
mmcli_async_operation_done ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_modem_ready (GObject *source,
|
get_modem_ready (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
@@ -454,6 +487,26 @@ get_modem_ready (GObject *source,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Request to set default storage */
|
||||||
|
if (set_default_storage_str) {
|
||||||
|
MMSmsStorage storage;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
storage = mm_common_get_sms_storage_from_string (set_default_storage_str, &error);
|
||||||
|
if (error) {
|
||||||
|
g_printerr ("error: couldn't set default storage: %s\n",
|
||||||
|
error->message);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_modem_messaging_set_default_storage (ctx->modem_messaging,
|
||||||
|
storage,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)set_default_storage_ready,
|
||||||
|
NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,5 +610,25 @@ mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Request to set default storage for storing SMS */
|
||||||
|
if (set_default_storage_str) {
|
||||||
|
gboolean operation_result;
|
||||||
|
MMSmsStorage storage;
|
||||||
|
|
||||||
|
storage = mm_common_get_sms_storage_from_string (set_default_storage_str, &error);
|
||||||
|
if (error) {
|
||||||
|
g_printerr ("error: couldn't set default storage: %s\n",
|
||||||
|
error->message);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
operation_result = mm_modem_messaging_set_default_storage_sync (ctx->modem_messaging,
|
||||||
|
storage,
|
||||||
|
NULL,
|
||||||
|
&error);
|
||||||
|
set_default_storage_process_reply (operation_result, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -894,6 +894,9 @@ mm_modem_messaging_create_sync
|
|||||||
mm_modem_messaging_delete
|
mm_modem_messaging_delete
|
||||||
mm_modem_messaging_delete_finish
|
mm_modem_messaging_delete_finish
|
||||||
mm_modem_messaging_delete_sync
|
mm_modem_messaging_delete_sync
|
||||||
|
mm_modem_messaging_set_default_storage
|
||||||
|
mm_modem_messaging_set_default_storage_finish
|
||||||
|
mm_modem_messaging_set_default_storage_sync
|
||||||
mm_modem_messaging_list
|
mm_modem_messaging_list
|
||||||
mm_modem_messaging_list_finish
|
mm_modem_messaging_list_finish
|
||||||
mm_modem_messaging_list_sync
|
mm_modem_messaging_list_sync
|
||||||
|
|||||||
@@ -42,6 +42,14 @@
|
|||||||
<arg name="result" type="ao" direction="out" />
|
<arg name="result" type="ao" direction="out" />
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
SetDefaultStorage
|
||||||
|
@storage: set the default storage to storage
|
||||||
|
-->
|
||||||
|
<method name="SetDefaultStorage">
|
||||||
|
<arg name="storage" type="u" direction="in" />
|
||||||
|
</method>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Delete:
|
Delete:
|
||||||
@path: The object path of the SMS to delete.
|
@path: The object path of the SMS to delete.
|
||||||
|
|||||||
@@ -642,6 +642,100 @@ mm_modem_messaging_delete_sync (MMModemMessaging *self,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mm_modem_messaging_set_default_storage_finish
|
||||||
|
* @self: A #MMModemMessaging.
|
||||||
|
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to
|
||||||
|
* mm_modem_messaging_set_default_storage()
|
||||||
|
* @error: Return location for error or %NULL.
|
||||||
|
*
|
||||||
|
* Finishes an operation started with mm_modem_messaging_set_default_storage().
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if set default storage is sucess, %FALSE if @error is set.
|
||||||
|
*
|
||||||
|
* Since: 1.24
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
mm_modem_messaging_set_default_storage_finish (MMModemMessaging *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
|
||||||
|
|
||||||
|
return mm_gdbus_modem_messaging_call_set_default_storage_finish (MM_GDBUS_MODEM_MESSAGING (self),
|
||||||
|
res,
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mm_modem_messaging_set_default_storage
|
||||||
|
* @self: A #MMModemMessaging.
|
||||||
|
* @storage: A #MMSmsStorage to set default storage.
|
||||||
|
* @cancellable: (allow-none): A #GCancellable or %NULL.
|
||||||
|
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or
|
||||||
|
* %NULL
|
||||||
|
* @user_data: User data to pass to @callback.
|
||||||
|
*
|
||||||
|
* Asynchronously set deafult #MMSmsStorage in the modem.
|
||||||
|
*
|
||||||
|
* When the operation is finished, @callback will be invoked in the
|
||||||
|
* <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
|
||||||
|
* of the thread you are calling this method from. You can then call
|
||||||
|
* mm_modem_messaging_set_default_storage_finish() to get the result of the operation.
|
||||||
|
*
|
||||||
|
* See mm_modem_messaging_set_default_storage_sync() for the synchronous, blocking version
|
||||||
|
* of this method.
|
||||||
|
*
|
||||||
|
* Since: 1.24
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
mm_modem_messaging_set_default_storage (MMModemMessaging *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (MM_IS_MODEM_MESSAGING (self));
|
||||||
|
|
||||||
|
mm_gdbus_modem_messaging_call_set_default_storage (MM_GDBUS_MODEM_MESSAGING (self),
|
||||||
|
storage,
|
||||||
|
cancellable,
|
||||||
|
callback,
|
||||||
|
user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mm_modem_messaging_set_default_storage_sync
|
||||||
|
* @self: A #MMModemMessaging.
|
||||||
|
* @storage: A #MMSmsStorage to set default storage.
|
||||||
|
* @cancellable: (allow-none): A #GCancellable or %NULL.
|
||||||
|
* @error: Return location for error or %NULL.
|
||||||
|
*
|
||||||
|
* Synchronously set deafult #MMSmsStorage in the modem.
|
||||||
|
*
|
||||||
|
* The calling thread is blocked until a reply is received. See
|
||||||
|
* mm_modem_messaging_set_default_storage() for the asynchronous version of this method.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if set default storage is sucess, %FALSE if @error is set.
|
||||||
|
*
|
||||||
|
* Since: 1.24
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
mm_modem_messaging_set_default_storage_sync (MMModemMessaging *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
|
||||||
|
|
||||||
|
return mm_gdbus_modem_messaging_call_set_default_storage_sync (MM_GDBUS_MODEM_MESSAGING (self),
|
||||||
|
storage,
|
||||||
|
cancellable,
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mm_modem_messaging_init (MMModemMessaging *self)
|
mm_modem_messaging_init (MMModemMessaging *self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,6 +116,19 @@ gboolean mm_modem_messaging_delete_sync (MMModemMessaging *self,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
void mm_modem_messaging_set_default_storage (MMModemMessaging *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
gboolean mm_modem_messaging_set_default_storage_finish (MMModemMessaging *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GError **error);
|
||||||
|
gboolean mm_modem_messaging_set_default_storage_sync (MMModemMessaging *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* _MM_MODEM_MESSAGING_H_ */
|
#endif /* _MM_MODEM_MESSAGING_H_ */
|
||||||
|
|||||||
@@ -377,6 +377,109 @@ handle_list (MmGdbusModemMessaging *skeleton,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MmGdbusModemMessaging *skeleton;
|
||||||
|
GDBusMethodInvocation *invocation;
|
||||||
|
MMIfaceModemMessaging *self;
|
||||||
|
MMSmsStorage storage;
|
||||||
|
} HandleSetDefaultStorageContext;
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_set_default_storage_context_free (HandleSetDefaultStorageContext *ctx)
|
||||||
|
{
|
||||||
|
g_object_unref (ctx->skeleton);
|
||||||
|
g_object_unref (ctx->invocation);
|
||||||
|
g_object_unref (ctx->self);
|
||||||
|
g_slice_free (HandleSetDefaultStorageContext, ctx);
|
||||||
|
}
|
||||||
|
static void
|
||||||
|
handle_set_default_storage_ready (MMIfaceModemMessaging *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
HandleSetDefaultStorageContext *ctx)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->set_default_storage_finish (self, res, &error)) {
|
||||||
|
mm_obj_warn (self, "could not set default storage: %s", error->message);
|
||||||
|
mm_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
|
handle_set_default_storage_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_set (self,
|
||||||
|
MM_IFACE_MODEM_MESSAGING_SMS_DEFAULT_STORAGE, ctx->storage,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
mm_obj_info (self, "set the default storage successfully");
|
||||||
|
mm_gdbus_modem_messaging_complete_set_default_storage (ctx->skeleton, ctx->invocation);
|
||||||
|
handle_set_default_storage_context_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_set_default_storage_auth_ready (MMBaseModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
HandleSetDefaultStorageContext *ctx)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_base_modem_authorize_finish (self, res, &error)) {
|
||||||
|
mm_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
|
handle_set_default_storage_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->storage == MM_SMS_STORAGE_UNKNOWN) {
|
||||||
|
mm_dbus_method_invocation_return_error (ctx->invocation,
|
||||||
|
MM_CORE_ERROR,
|
||||||
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
|
"Cannot set default storage: Unknown storage");
|
||||||
|
handle_set_default_storage_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_obj_info (self, "procesing user request to set default storage '%s'...",
|
||||||
|
mm_sms_storage_get_string (ctx->storage));
|
||||||
|
|
||||||
|
if (!(MM_IFACE_MODEM_MESSAGING_GET_IFACE (ctx->self)->set_default_storage) ||
|
||||||
|
!(MM_IFACE_MODEM_MESSAGING_GET_IFACE (ctx->self)->set_default_storage_finish)) {
|
||||||
|
mm_dbus_method_invocation_return_error (ctx->invocation,
|
||||||
|
MM_CORE_ERROR,
|
||||||
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
|
"Cannot set default storage: not supported");
|
||||||
|
handle_set_default_storage_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MM_IFACE_MODEM_MESSAGING_GET_IFACE (ctx->self)->set_default_storage (
|
||||||
|
ctx->self,
|
||||||
|
ctx->storage,
|
||||||
|
(GAsyncReadyCallback)handle_set_default_storage_ready,
|
||||||
|
ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
handle_set_default_storage (MmGdbusModemMessaging *skeleton,
|
||||||
|
GDBusMethodInvocation *invocation,
|
||||||
|
guint32 storage,
|
||||||
|
MMIfaceModemMessaging *self)
|
||||||
|
{
|
||||||
|
HandleSetDefaultStorageContext *ctx;
|
||||||
|
|
||||||
|
ctx = g_slice_new0 (HandleSetDefaultStorageContext);
|
||||||
|
ctx->skeleton = g_object_ref (skeleton);
|
||||||
|
ctx->invocation = g_object_ref (invocation);
|
||||||
|
ctx->self = g_object_ref (self);
|
||||||
|
ctx->storage = (MMSmsStorage)storage;
|
||||||
|
|
||||||
|
mm_base_modem_authorize (MM_BASE_MODEM (self),
|
||||||
|
invocation,
|
||||||
|
MM_AUTHORIZATION_MESSAGING,
|
||||||
|
(GAsyncReadyCallback)handle_set_default_storage_auth_ready,
|
||||||
|
ctx);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_iface_modem_messaging_take_part (MMIfaceModemMessaging *self,
|
mm_iface_modem_messaging_take_part (MMIfaceModemMessaging *self,
|
||||||
MMSmsPart *sms_part,
|
MMSmsPart *sms_part,
|
||||||
@@ -1323,6 +1426,10 @@ interface_initialization_step (GTask *task)
|
|||||||
"handle-list",
|
"handle-list",
|
||||||
G_CALLBACK (handle_list),
|
G_CALLBACK (handle_list),
|
||||||
self);
|
self);
|
||||||
|
g_signal_connect (ctx->skeleton,
|
||||||
|
"handle-set-default-storage",
|
||||||
|
G_CALLBACK (handle_set_default_storage),
|
||||||
|
self);
|
||||||
|
|
||||||
/* Finally, export the new interface */
|
/* Finally, export the new interface */
|
||||||
mm_gdbus_object_skeleton_set_modem_messaging (MM_GDBUS_OBJECT_SKELETON (self),
|
mm_gdbus_object_skeleton_set_modem_messaging (MM_GDBUS_OBJECT_SKELETON (self),
|
||||||
|
|||||||
Reference in New Issue
Block a user