dispatcher-connection: replace 'connected' boolean with a new enum

The next commit will introduce a new dispatcher event.
This commit should not change anything user-facing

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
This commit is contained in:
Dominique Martinet
2025-05-16 15:34:02 +09:00
parent a4421095f8
commit f3aaa113e0
3 changed files with 33 additions and 17 deletions
+4 -4
View File
@@ -472,7 +472,7 @@ dispatcher_connection_run_ready (MMDispatcherConnection *dispatcher,
static void static void
bearer_run_dispatcher_scripts (MMBaseBearer *self, bearer_run_dispatcher_scripts (MMBaseBearer *self,
gboolean connected) MMDispatcherConnectionEvent event)
{ {
MMDispatcherConnection *dispatcher; MMDispatcherConnection *dispatcher;
const gchar *interface; const gchar *interface;
@@ -486,7 +486,7 @@ bearer_run_dispatcher_scripts (MMBaseBearer *self,
g_dbus_object_get_object_path (G_DBUS_OBJECT (self->priv->modem)), g_dbus_object_get_object_path (G_DBUS_OBJECT (self->priv->modem)),
self->priv->path, self->priv->path,
interface, interface,
connected, event,
NULL, /* cancellable */ NULL, /* cancellable */
(GAsyncReadyCallback)dispatcher_connection_run_ready, (GAsyncReadyCallback)dispatcher_connection_run_ready,
g_object_ref (self)); g_object_ref (self));
@@ -531,7 +531,7 @@ bearer_update_status (MMBaseBearer *self,
g_autoptr(GString) report = NULL; g_autoptr(GString) report = NULL;
/* Report disconnection via dispatcher scripts, before resetting the interface */ /* Report disconnection via dispatcher scripts, before resetting the interface */
bearer_run_dispatcher_scripts (self, FALSE); bearer_run_dispatcher_scripts (self, MM_DISPATCHER_CONNECTION_EVENT_DISCONNECTED);
bearer_reset_interface_status (self); bearer_reset_interface_status (self);
/* Cleanup flag to ignore disconnection reports */ /* Cleanup flag to ignore disconnection reports */
@@ -599,7 +599,7 @@ bearer_update_status_connected (MMBaseBearer *self,
connection_monitor_start (self); connection_monitor_start (self);
/* Run dispatcher scripts */ /* Run dispatcher scripts */
bearer_run_dispatcher_scripts (self, TRUE); bearer_run_dispatcher_scripts (self, MM_DISPATCHER_CONNECTION_EVENT_CONNECTED);
} }
/*****************************************************************************/ /*****************************************************************************/
+23 -12
View File
@@ -31,8 +31,6 @@
#endif #endif
#define OPERATION_DESCRIPTION "connection status report" #define OPERATION_DESCRIPTION "connection status report"
#define CONNECTED_STRING "connected"
#define DISCONNECTED_STRING "disconnected"
/* Maximum time a connection dispatcher command is allowed to run before /* Maximum time a connection dispatcher command is allowed to run before
* us killing it */ * us killing it */
@@ -51,15 +49,28 @@ G_DEFINE_TYPE (MMDispatcherConnection, mm_dispatcher_connection, MM_TYPE_DISPATC
/*****************************************************************************/ /*****************************************************************************/
typedef struct { typedef struct {
gchar *modem_dbus_path; gchar *modem_dbus_path;
gchar *bearer_dbus_path; gchar *bearer_dbus_path;
gchar *data_port; gchar *data_port;
gboolean connected; MMDispatcherConnectionEvent event;
GList *dispatcher_scripts; GList *dispatcher_scripts;
GFile *current; GFile *current;
guint n_failures; guint n_failures;
} ConnectionRunContext; } ConnectionRunContext;
static gchar *
mm_dispatcher_connection_event_to_string (MMDispatcherConnectionEvent event)
{
switch (event) {
case MM_DISPATCHER_CONNECTION_EVENT_CONNECTED:
return g_strdup ("connected");
case MM_DISPATCHER_CONNECTION_EVENT_DISCONNECTED:
return g_strdup ("disconnected");
default:
return NULL;
}
}
static void static void
connection_run_context_free (ConnectionRunContext *ctx) connection_run_context_free (ConnectionRunContext *ctx)
{ {
@@ -137,7 +148,7 @@ connection_run_next (GTask *task)
g_ptr_array_add (aux, g_strdup (ctx->modem_dbus_path)); g_ptr_array_add (aux, g_strdup (ctx->modem_dbus_path));
g_ptr_array_add (aux, g_strdup (ctx->bearer_dbus_path)); g_ptr_array_add (aux, g_strdup (ctx->bearer_dbus_path));
g_ptr_array_add (aux, g_strdup (ctx->data_port)); g_ptr_array_add (aux, g_strdup (ctx->data_port));
g_ptr_array_add (aux, g_strdup (ctx->connected ? CONNECTED_STRING : DISCONNECTED_STRING)); g_ptr_array_add (aux, mm_dispatcher_connection_event_to_string (ctx->event));
g_ptr_array_add (aux, NULL); g_ptr_array_add (aux, NULL);
argv = (GStrv) g_ptr_array_free (aux, FALSE); argv = (GStrv) g_ptr_array_free (aux, FALSE);
@@ -168,7 +179,7 @@ mm_dispatcher_connection_run (MMDispatcherConnection *self,
const gchar *modem_dbus_path, const gchar *modem_dbus_path,
const gchar *bearer_dbus_path, const gchar *bearer_dbus_path,
const gchar *data_port, const gchar *data_port,
gboolean connected, MMDispatcherConnectionEvent event,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
@@ -187,7 +198,7 @@ mm_dispatcher_connection_run (MMDispatcherConnection *self,
ctx->modem_dbus_path = g_strdup (modem_dbus_path); ctx->modem_dbus_path = g_strdup (modem_dbus_path);
ctx->bearer_dbus_path = g_strdup (bearer_dbus_path); ctx->bearer_dbus_path = g_strdup (bearer_dbus_path);
ctx->data_port = g_strdup (data_port); ctx->data_port = g_strdup (data_port);
ctx->connected = connected; ctx->event = event;
g_task_set_task_data (task, ctx, (GDestroyNotify)connection_run_context_free); g_task_set_task_data (task, ctx, (GDestroyNotify)connection_run_context_free);
/* Iterate over all enabled dirs and collect all dispatcher script paths */ /* Iterate over all enabled dirs and collect all dispatcher script paths */
+6 -1
View File
@@ -32,13 +32,18 @@ typedef struct _MMDispatcherConnection MMDispatcherConnection;
typedef struct _MMDispatcherConnectionClass MMDispatcherConnectionClass; typedef struct _MMDispatcherConnectionClass MMDispatcherConnectionClass;
typedef struct _MMDispatcherConnectionPrivate MMDispatcherConnectionPrivate; typedef struct _MMDispatcherConnectionPrivate MMDispatcherConnectionPrivate;
typedef enum { /*< underscore_name=mm_dispatcher_connection_event >*/
MM_DISPATCHER_CONNECTION_EVENT_CONNECTED,
MM_DISPATCHER_CONNECTION_EVENT_DISCONNECTED,
} MMDispatcherConnectionEvent;
GType mm_dispatcher_connection_get_type (void); GType mm_dispatcher_connection_get_type (void);
MMDispatcherConnection *mm_dispatcher_connection_get (void); MMDispatcherConnection *mm_dispatcher_connection_get (void);
void mm_dispatcher_connection_run (MMDispatcherConnection *self, void mm_dispatcher_connection_run (MMDispatcherConnection *self,
const gchar *modem_dbus_path, const gchar *modem_dbus_path,
const gchar *bearer_dbus_path, const gchar *bearer_dbus_path,
const gchar *data_port, const gchar *data_port,
gboolean connected, MMDispatcherConnectionEvent event,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);