aboutsummaryrefslogtreecommitdiff
path: root/src/mm-base-sms.c
diff options
context:
space:
mode:
authorDan Williams <dan@ioncontrol.co>2025-05-08 20:10:48 -0500
committerDan Williams <dan@ioncontrol.co>2025-05-08 20:10:48 -0500
commitefcc960b130356e6b05d05a915ff0f9646b00d5f (patch)
treecf209fc07098e68c65dca219fee38a826dbcbf1a /src/mm-base-sms.c
parent02942a04f95f64cda36360c72961fe0e20459ad4 (diff)
parent1fa21fcc48b271a8dc2191104e35bf4e95fa2331 (diff)
Merge request !1344 from 'cbm-remove-modem'
Begin removing usage of MMBaseModem from leaf classes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/1344
Diffstat (limited to 'src/mm-base-sms.c')
-rw-r--r--src/mm-base-sms.c88
1 files changed, 53 insertions, 35 deletions
diff --git a/src/mm-base-sms.c b/src/mm-base-sms.c
index 202b178f..0e7c7527 100644
--- a/src/mm-base-sms.c
+++ b/src/mm-base-sms.c
@@ -36,16 +36,21 @@
#include "mm-log-object.h"
#include "mm-modem-helpers.h"
#include "mm-error-helpers.h"
+#include "mm-auth-provider.h"
+#include "mm-bind.h"
static void log_object_iface_init (MMLogObjectInterface *iface);
+static void bind_iface_init (MMBindInterface *iface);
G_DEFINE_TYPE_EXTENDED (MMBaseSms, mm_base_sms, MM_GDBUS_TYPE_SMS_SKELETON, 0,
- G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init))
+ G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_BIND, bind_iface_init))
enum {
PROP_0,
PROP_PATH,
PROP_CONNECTION,
+ PROP_BIND_TO,
PROP_MODEM,
PROP_IS_MULTIPART,
PROP_MAX_PARTS,
@@ -60,6 +65,13 @@ struct _MMBaseSmsPrivate {
GDBusConnection *connection;
guint dbus_id;
+ /* The authorization provider */
+ MMAuthProvider *authp;
+ GCancellable *authp_cancellable;
+
+ /* The object this SMS is bound to */
+ GObject *bind_to;
+
/* The modem which owns this SMS */
MMBaseModem *modem;
/* The path where the SMS object is exported */
@@ -324,7 +336,6 @@ generate_submit_pdus (MMBaseSms *self,
typedef struct {
MMBaseSms *self;
- MMBaseModem *modem;
GDBusMethodInvocation *invocation;
MMSmsStorage storage;
} HandleStoreContext;
@@ -333,7 +344,6 @@ static void
handle_store_context_free (HandleStoreContext *ctx)
{
g_object_unref (ctx->invocation);
- g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_slice_free (HandleStoreContext, ctx);
}
@@ -406,13 +416,13 @@ prepare_sms_to_be_stored (MMBaseSms *self,
}
static void
-handle_store_auth_ready (MMBaseModem *modem,
+handle_store_auth_ready (MMAuthProvider *authp,
GAsyncResult *res,
HandleStoreContext *ctx)
{
GError *error = NULL;
- if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ if (!mm_auth_provider_authorize_finish (authp, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_store_context_free (ctx);
return;
@@ -442,7 +452,7 @@ handle_store_auth_ready (MMBaseModem *modem,
}
/* Check if the requested storage is allowed for storing */
- if (!mm_iface_modem_messaging_is_storage_supported_for_storing (MM_IFACE_MODEM_MESSAGING (ctx->modem),
+ if (!mm_iface_modem_messaging_is_storage_supported_for_storing (MM_IFACE_MODEM_MESSAGING (ctx->self->priv->modem),
ctx->storage,
&error)) {
mm_obj_warn (ctx->self, "failed storing SMS message: %s", error->message);
@@ -485,9 +495,6 @@ handle_store (MMBaseSms *self,
ctx = g_slice_new0 (HandleStoreContext);
ctx->self = g_object_ref (self);
ctx->invocation = g_object_ref (invocation);
- g_object_get (self,
- MM_BASE_SMS_MODEM, &ctx->modem,
- NULL);
ctx->storage = (MMSmsStorage)storage;
if (ctx->storage == MM_SMS_STORAGE_UNKNOWN) {
@@ -498,11 +505,12 @@ handle_store (MMBaseSms *self,
g_assert (ctx->storage != MM_SMS_STORAGE_UNKNOWN);
}
- mm_base_modem_authorize (ctx->modem,
- invocation,
- MM_AUTHORIZATION_MESSAGING,
- (GAsyncReadyCallback)handle_store_auth_ready,
- ctx);
+ mm_auth_provider_authorize (self->priv->authp,
+ invocation,
+ MM_AUTHORIZATION_MESSAGING,
+ self->priv->authp_cancellable,
+ (GAsyncReadyCallback)handle_store_auth_ready,
+ ctx);
return TRUE;
}
@@ -511,7 +519,6 @@ handle_store (MMBaseSms *self,
typedef struct {
MMBaseSms *self;
- MMBaseModem *modem;
GDBusMethodInvocation *invocation;
} HandleSendContext;
@@ -519,7 +526,6 @@ static void
handle_send_context_free (HandleSendContext *ctx)
{
g_object_unref (ctx->invocation);
- g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_slice_free (HandleSendContext, ctx);
}
@@ -586,14 +592,14 @@ prepare_sms_to_be_sent (MMBaseSms *self,
}
static void
-handle_send_auth_ready (MMBaseModem *modem,
+handle_send_auth_ready (MMAuthProvider *authp,
GAsyncResult *res,
HandleSendContext *ctx)
{
MMSmsState state;
GError *error = NULL;
- if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ if (!mm_auth_provider_authorize_finish (authp, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_send_context_free (ctx);
return;
@@ -650,15 +656,13 @@ handle_send (MMBaseSms *self,
ctx = g_slice_new0 (HandleSendContext);
ctx->self = g_object_ref (self);
ctx->invocation = g_object_ref (invocation);
- g_object_get (self,
- MM_BASE_SMS_MODEM, &ctx->modem,
- NULL);
- mm_base_modem_authorize (ctx->modem,
- invocation,
- MM_AUTHORIZATION_MESSAGING,
- (GAsyncReadyCallback)handle_send_auth_ready,
- ctx);
+ mm_auth_provider_authorize (self->priv->authp,
+ invocation,
+ MM_AUTHORIZATION_MESSAGING,
+ self->priv->authp_cancellable,
+ (GAsyncReadyCallback)handle_send_auth_ready,
+ ctx);
return TRUE;
}
@@ -1801,6 +1805,7 @@ mm_base_sms_new (MMBaseModem *modem)
{
return MM_BASE_SMS (g_object_new (MM_TYPE_BASE_SMS,
MM_BASE_SMS_MODEM, modem,
+ MM_BIND_TO, modem,
NULL));
}
@@ -1998,18 +2003,14 @@ set_property (GObject *object,
else if (self->priv->path)
sms_dbus_export (self);
break;
+ case PROP_BIND_TO:
+ g_clear_object (&self->priv->bind_to);
+ self->priv->bind_to = g_value_dup_object (value);
+ mm_bind_to (MM_BIND (self), MM_BASE_SMS_CONNECTION, self->priv->bind_to);
+ break;
case PROP_MODEM:
g_clear_object (&self->priv->modem);
self->priv->modem = g_value_dup_object (value);
- if (self->priv->modem) {
- /* Set owner ID */
- mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem)));
- /* Bind the modem's connection (which is set when it is exported,
- * and unset when unexported) to the SMS's connection */
- g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION,
- self, MM_BASE_SMS_CONNECTION,
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- }
break;
case PROP_IS_MULTIPART:
self->priv->is_multipart = g_value_get_boolean (value);
@@ -2041,6 +2042,9 @@ get_property (GObject *object,
case PROP_CONNECTION:
g_value_set_object (value, self->priv->connection);
break;
+ case PROP_BIND_TO:
+ g_value_set_object (value, self->priv->bind_to);
+ break;
case PROP_MODEM:
g_value_set_object (value, self->priv->modem);
break;
@@ -2071,6 +2075,10 @@ mm_base_sms_init (MMBaseSms *self)
/* Each SMS is given a unique id to build its own DBus path */
self->priv->dbus_id = id++;
+
+ /* Setup authorization provider */
+ self->priv->authp = mm_auth_provider_get ();
+ self->priv->authp_cancellable = g_cancellable_new ();
}
static void
@@ -2097,6 +2105,9 @@ dispose (GObject *object)
}
g_clear_object (&self->priv->modem);
+ g_clear_object (&self->priv->bind_to);
+ g_cancellable_cancel (self->priv->authp_cancellable);
+ g_clear_object (&self->priv->authp_cancellable);
G_OBJECT_CLASS (mm_base_sms_parent_class)->dispose (object);
}
@@ -2108,6 +2119,11 @@ log_object_iface_init (MMLogObjectInterface *iface)
}
static void
+bind_iface_init (MMBindInterface *iface)
+{
+}
+
+static void
mm_base_sms_class_init (MMBaseSmsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -2143,6 +2159,8 @@ mm_base_sms_class_init (MMBaseSmsClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PATH, properties[PROP_PATH]);
+ g_object_class_override_property (object_class, PROP_BIND_TO, MM_BIND_TO);
+
properties[PROP_MODEM] =
g_param_spec_object (MM_BASE_SMS_MODEM,
"Modem",