diff --git a/src/background.c b/src/background.c index 9ca7406dc..2c6c0988d 100644 --- a/src/background.c +++ b/src/background.c @@ -775,7 +775,7 @@ handle_request_background_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); GVariant *options; const char *id; Permission permission; diff --git a/src/camera.c b/src/camera.c index 376307ef2..afac07780 100644 --- a/src/camera.c +++ b/src/camera.c @@ -164,7 +164,7 @@ handle_access_camera_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); gboolean allowed; allowed = query_permission_sync (request); diff --git a/src/clipboard.c b/src/clipboard.c index 51879a317..136d01d34 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -80,7 +80,7 @@ handle_request_clipboard (XdpDbusClipboard *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -88,7 +88,7 @@ handle_request_clipboard (XdpDbusClipboard *object, "Invalid session type"); return G_DBUS_METHOD_INVOCATION_HANDLED; } - remote_desktop_session = (RemoteDesktopSession *)session; + remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (!remote_desktop_session_can_request_clipboard (remote_desktop_session)) { @@ -130,7 +130,7 @@ handle_set_selection (XdpDbusClipboard *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -139,7 +139,7 @@ handle_set_selection (XdpDbusClipboard *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } else if (!remote_desktop_session_is_clipboard_enabled ( - (RemoteDesktopSession *)session)) + REMOTE_DESKTOP_SESSION (session))) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -240,7 +240,7 @@ handle_selection_write (XdpDbusClipboard *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -249,7 +249,7 @@ handle_selection_write (XdpDbusClipboard *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } else if (!remote_desktop_session_is_clipboard_enabled ( - (RemoteDesktopSession *)session)) + REMOTE_DESKTOP_SESSION (session))) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -291,7 +291,7 @@ handle_selection_write_done (XdpDbusClipboard *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -300,7 +300,7 @@ handle_selection_write_done (XdpDbusClipboard *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } else if (!remote_desktop_session_is_clipboard_enabled ( - (RemoteDesktopSession *)session)) + REMOTE_DESKTOP_SESSION (session))) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -381,7 +381,7 @@ handle_selection_read (XdpDbusClipboard *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -390,7 +390,7 @@ handle_selection_read (XdpDbusClipboard *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } else if (!remote_desktop_session_is_clipboard_enabled ( - (RemoteDesktopSession *)session)) + REMOTE_DESKTOP_SESSION (session))) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -452,8 +452,7 @@ selection_transfer_cb (XdpDbusImplClipboard *impl, SESSION_AUTOLOCK_UNREF (session); - RemoteDesktopSession *remote_desktop_session = - (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (remote_desktop_session && remote_desktop_session_is_clipboard_enabled (remote_desktop_session) && @@ -489,8 +488,7 @@ selection_owner_changed_cb (XdpDbusImplClipboard *impl, SESSION_AUTOLOCK_UNREF (session); - RemoteDesktopSession *remote_desktop_session = - (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (remote_desktop_session && remote_desktop_session_is_clipboard_enabled (remote_desktop_session) && diff --git a/src/global-shortcuts.c b/src/global-shortcuts.c index ce5eb928f..c95d4da46 100644 --- a/src/global-shortcuts.c +++ b/src/global-shortcuts.c @@ -73,10 +73,23 @@ GType global_shortcuts_session_get_type (void); G_DEFINE_TYPE (GlobalShortcutsSession, global_shortcuts_session, session_get_type ()) +G_GNUC_UNUSED static inline GlobalShortcutsSession * +GLOBAL_SHORTCUTS_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, global_shortcuts_session_get_type (), GlobalShortcutsSession); +} + +G_GNUC_UNUSED static inline gboolean +IS_GLOBAL_SHORTCUTS_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, global_shortcuts_session_get_type ()); +} + static void global_shortcuts_session_close (Session *session) { - GlobalShortcutsSession *global_shortcuts_session = (GlobalShortcutsSession *)session; + GlobalShortcutsSession *global_shortcuts_session = + GLOBAL_SHORTCUTS_SESSION (session); global_shortcuts_session->closed = TRUE; } @@ -133,7 +146,7 @@ global_shortcuts_session_new (GVariant *options, if (session) g_debug ("global shortcuts session owned by '%s' created", session->sender); - return (GlobalShortcutsSession *) session; + return GLOBAL_SHORTCUTS_SESSION (session); } static void @@ -253,7 +266,7 @@ handle_create_session (XdpDbusGlobalShortcuts *object, request_set_impl_request (request, impl_request); request_export (request, g_dbus_method_invocation_get_connection (invocation)); - session = (Session *)global_shortcuts_session_new (options, request, &error); + session = SESSION (global_shortcuts_session_new (options, request, &error)); if (!session) { g_dbus_method_invocation_return_gerror (invocation, error); @@ -593,7 +606,8 @@ activated_cb (XdpDbusImplGlobalShortcuts *impl, { GDBusConnection *connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)); g_autoptr(Session) session = lookup_session (session_id); - GlobalShortcutsSession *global_shortcuts_session = (GlobalShortcutsSession *)session; + GlobalShortcutsSession *global_shortcuts_session = + GLOBAL_SHORTCUTS_SESSION (session); g_debug ("Received activated %s for %s", session_id, shortcut_id); @@ -619,7 +633,8 @@ deactivated_cb (XdpDbusImplGlobalShortcuts *impl, { GDBusConnection *connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)); g_autoptr(Session) session = lookup_session (session_id); - GlobalShortcutsSession *global_shortcuts_session = (GlobalShortcutsSession *)session; + GlobalShortcutsSession *global_shortcuts_session = + GLOBAL_SHORTCUTS_SESSION (session); g_debug ("Received deactivated %s for %s", session_id, shortcut_id); @@ -643,7 +658,8 @@ shortcuts_changed_cb (XdpDbusImplGlobalShortcuts *impl, { GDBusConnection *connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)); g_autoptr(Session) session = lookup_session (session_id); - GlobalShortcutsSession *global_shortcuts_session = (GlobalShortcutsSession *)session; + GlobalShortcutsSession *global_shortcuts_session = + GLOBAL_SHORTCUTS_SESSION (session); g_debug ("Received ShortcutsChanged %s", session_id); diff --git a/src/inhibit.c b/src/inhibit.c index a22e9483d..333431dfb 100644 --- a/src/inhibit.c +++ b/src/inhibit.c @@ -138,7 +138,7 @@ handle_inhibit_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); const char *window; guint32 flags; GVariant *options; @@ -265,10 +265,22 @@ GType inhibit_session_get_type (void); G_DEFINE_TYPE (InhibitSession, inhibit_session, session_get_type ()) +G_GNUC_UNUSED static inline InhibitSession * +INHIBIT_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, inhibit_session_get_type (), InhibitSession); +} + +G_GNUC_UNUSED static inline gboolean +IS_INHIBIT_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, inhibit_session_get_type ()); +} + static void inhibit_session_close (Session *session) { - InhibitSession *inhibit_session = (InhibitSession *)session; + InhibitSession *inhibit_session = INHIBIT_SESSION (session); inhibit_session->closed = TRUE; @@ -421,7 +433,7 @@ handle_create_monitor (XdpDbusInhibit *object, request_set_impl_request (request, impl_request); request_export (request, g_dbus_method_invocation_get_connection (invocation)); - session = (Session *)inhibit_session_new (arg_options, request, &error); + session = SESSION (inhibit_session_new (arg_options, request, &error)); if (!session) { g_dbus_method_invocation_return_gerror (invocation, error); @@ -495,7 +507,7 @@ state_changed_cb (XdpDbusImplInhibit *impl, { GDBusConnection *connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)); g_autoptr(Session) session = lookup_session (session_id); - InhibitSession *inhibit_session = (InhibitSession *)session; + InhibitSession *inhibit_session = INHIBIT_SESSION (session); gboolean active = FALSE; guint32 session_state = 0; diff --git a/src/input-capture.c b/src/input-capture.c index 65101a68f..89bf393dd 100644 --- a/src/input-capture.c +++ b/src/input-capture.c @@ -84,10 +84,16 @@ GType input_capture_session_get_type (void); G_DEFINE_TYPE (InputCaptureSession, input_capture_session, session_get_type ()) -static gboolean -is_input_capture_session (Session *session) +G_GNUC_UNUSED static inline InputCaptureSession * +INPUT_CAPTURE_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, input_capture_session_get_type (), InputCaptureSession); +} + +G_GNUC_UNUSED static inline gboolean +IS_INPUT_CAPTURE_SESSION (gpointer ptr) { - return G_TYPE_CHECK_INSTANCE_TYPE (session, input_capture_session_get_type ()); + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, input_capture_session_get_type ()); } static InputCaptureSession * @@ -255,7 +261,7 @@ handle_create_session (XdpDbusInputCapture *object, request_set_impl_request (request, impl_request); request_export (request, g_dbus_method_invocation_get_connection (invocation)); - session = (Session *)input_capture_session_new (arg_options, request, &error); + session = SESSION (input_capture_session_new (arg_options, request, &error)); if (!session) { g_dbus_method_invocation_return_gerror (invocation, error); @@ -305,7 +311,7 @@ get_zones_done (GObject *source_object, gboolean should_close_session; uint32_t response = 2; - request = (Request *)data; + request = REQUEST (data); REQUEST_AUTOLOCK (request); @@ -376,7 +382,7 @@ handle_get_zones (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -385,7 +391,7 @@ handle_get_zones (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -460,7 +466,7 @@ set_pointer_barriers_done (GObject *source_object, Session *session; uint32_t response = 2; - request = (Request *)data; + request = REQUEST (data); REQUEST_AUTOLOCK (request); @@ -531,7 +537,7 @@ handle_set_pointer_barriers (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -540,7 +546,7 @@ handle_set_pointer_barriers (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -632,7 +638,7 @@ handle_enable (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -641,7 +647,7 @@ handle_enable (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -733,7 +739,7 @@ handle_disable (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -742,7 +748,7 @@ handle_disable (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -834,7 +840,7 @@ handle_release (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -843,7 +849,7 @@ handle_release (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -934,7 +940,7 @@ handle_connect_to_eis (XdpDbusInputCapture *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -943,7 +949,7 @@ handle_connect_to_eis (XdpDbusInputCapture *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - input_capture_session = (InputCaptureSession *)session; + input_capture_session = INPUT_CAPTURE_SESSION (session); switch (input_capture_session->state) { @@ -1027,7 +1033,7 @@ on_disabled_cb (XdpDbusImplInputCapture *impl, g_autoptr(Session) session = lookup_session (session_id); InputCaptureSession *input_capture_session; - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_critical ("Invalid session type for signal"); return; @@ -1060,7 +1066,7 @@ on_activated_cb (XdpDbusImplInputCapture *impl, g_autoptr(Session) session = lookup_session (session_id); InputCaptureSession *input_capture_session; - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_critical ("Invalid session type for signal"); return; @@ -1092,7 +1098,7 @@ on_deactivated_cb (XdpDbusImplInputCapture *impl, g_autoptr(Session) session = lookup_session (session_id); InputCaptureSession *input_capture_session; - if (!is_input_capture_session (session)) + if (!IS_INPUT_CAPTURE_SESSION (session)) { g_critical ("Invalid session type for signal"); return; @@ -1142,7 +1148,7 @@ input_capture_class_init (InputCaptureClass *klass) static void input_capture_session_close (Session *session) { - InputCaptureSession *input_capture_session = (InputCaptureSession *)session; + InputCaptureSession *input_capture_session = INPUT_CAPTURE_SESSION (session); input_capture_session->state = INPUT_CAPTURE_SESSION_STATE_CLOSED; diff --git a/src/location.c b/src/location.c index 56cdfddcd..a6c3781dc 100644 --- a/src/location.c +++ b/src/location.c @@ -73,6 +73,18 @@ GType location_session_get_type (void); G_DEFINE_TYPE (LocationSession, location_session, session_get_type ()) +G_GNUC_UNUSED static inline LocationSession * +LOCATION_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, location_session_get_type (), LocationSession); +} + +G_GNUC_UNUSED static inline gboolean +IS_LOCATION_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, location_session_get_type ()); +} + static void location_session_init (LocationSession *session) { @@ -84,7 +96,7 @@ location_session_init (LocationSession *session) static void location_session_close (Session *session) { - LocationSession *loc_session = (LocationSession *)session; + LocationSession *loc_session = LOCATION_SESSION (session); loc_session->state = LOCATION_SESSION_STATE_CLOSED; @@ -97,7 +109,7 @@ location_session_close (Session *session) static void location_session_finalize (GObject *object) { - LocationSession *loc_session = (LocationSession *)object; + LocationSession *loc_session = LOCATION_SESSION (object); g_clear_object (&loc_session->client); @@ -233,7 +245,7 @@ location_session_start (LocationSession *loc_session) g_debug ("location session '%s', GeoClue client '%s'", ((Session*)loc_session)->id, client_id); g_debug ("location session '%s', distance-threshold %d, time-threshold %d, accuracy %s", - ((Session *)loc_session)->id, + SESSION (loc_session)->id, loc_session->distance_threshold, loc_session->time_threshold, gclue_accuracy_level_to_string (loc_session->accuracy)); @@ -411,7 +423,8 @@ handle_create_session (XdpDbusLocation *object, GVariant *arg_options) { g_autoptr(GError) error = NULL; - LocationSession *session; + LocationSession *loc_session; + Session *session; guint threshold; guint accuracy; @@ -425,31 +438,33 @@ handle_create_session (XdpDbusLocation *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - session = location_session_new (arg_options, invocation, &error); - if (!session) + loc_session = location_session_new (arg_options, invocation, &error); + if (!loc_session) { g_dbus_method_invocation_return_gerror (invocation, error); return G_DBUS_METHOD_INVOCATION_HANDLED; } + session = SESSION (loc_session); + if (g_variant_lookup (arg_options, "distance-threshold", "u", &threshold)) - session->distance_threshold = threshold; + loc_session->distance_threshold = threshold; if (g_variant_lookup (arg_options, "time-threshold", "u", &threshold)) - session->time_threshold = threshold; + loc_session->time_threshold = threshold; if (g_variant_lookup (arg_options, "accuracy", "u", &accuracy)) { if (accuracy == 0) - session->accuracy = GCLUE_ACCURACY_LEVEL_NONE; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_NONE; else if (accuracy == 1) - session->accuracy = GCLUE_ACCURACY_LEVEL_COUNTRY; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_COUNTRY; else if (accuracy == 2) - session->accuracy = GCLUE_ACCURACY_LEVEL_CITY; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_CITY; else if (accuracy == 3) - session->accuracy = GCLUE_ACCURACY_LEVEL_NEIGHBORHOOD; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_NEIGHBORHOOD; else if (accuracy == 4) - session->accuracy = GCLUE_ACCURACY_LEVEL_STREET; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_STREET; else if (accuracy == 5) - session->accuracy = GCLUE_ACCURACY_LEVEL_EXACT; + loc_session->accuracy = GCLUE_ACCURACY_LEVEL_EXACT; else { g_dbus_method_invocation_return_error (invocation, @@ -460,18 +475,18 @@ handle_create_session (XdpDbusLocation *object, } } - if (!session_export ((Session *)session, &error)) + if (!session_export (session, &error)) { g_warning ("Failed to export session: %s", error->message); - session_close ((Session *)session, FALSE); + session_close (session, FALSE); } else { - g_debug ("CreateSession new session '%s'", ((Session *)session)->id); - session_register ((Session *)session); + g_debug ("CreateSession new session '%s'", (session)->id); + session_register (session); } - xdp_dbus_location_complete_create_session (object, invocation, ((Session *)session)->id); + xdp_dbus_location_complete_create_session (object, invocation, (session)->id); return G_DBUS_METHOD_INVOCATION_HANDLED; } @@ -484,7 +499,7 @@ handle_start_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); const char *parent_window; const char *id; gint64 last_used = 0; @@ -499,7 +514,7 @@ handle_start_in_thread_func (GTask *task, session = g_object_get_qdata (G_OBJECT (request), quark_request_session); SESSION_AUTOLOCK_UNREF (g_object_ref (session)); g_object_set_qdata (G_OBJECT (request), quark_request_session, NULL); - loc_session = (LocationSession *)session; + loc_session = LOCATION_SESSION (session); parent_window = (const char *)g_object_get_data (G_OBJECT (request), "parent-window"); @@ -609,7 +624,7 @@ handle_start_in_thread_func (GTask *task, loc_session->accuracy = accuracy; } - if (location_session_start ((LocationSession*)session)) + if (location_session_start (loc_session)) response = 0; else response = 2; @@ -630,7 +645,7 @@ handle_start_in_thread_func (GTask *task, if (response != 0) { g_debug ("closing session"); - session_close ((Session *)session, FALSE); + session_close (session, FALSE); } } @@ -670,7 +685,7 @@ handle_start (XdpDbusLocation *object, SESSION_AUTOLOCK_UNREF (session); - loc_session = (LocationSession *)session; + loc_session = LOCATION_SESSION (session); switch (loc_session->state) { case LOCATION_SESSION_STATE_INIT: diff --git a/src/open-uri.c b/src/open-uri.c index b3c1bc876..2b106657e 100644 --- a/src/open-uri.c +++ b/src/open-uri.c @@ -350,7 +350,7 @@ send_response_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); guint response; GVariant *options; const char *choice; @@ -591,7 +591,7 @@ handle_open_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); const char *parent_window; const char *app_id = xdp_app_info_get_id (request->app_info); const char *activation_token; diff --git a/src/remote-desktop.c b/src/remote-desktop.c index f615b28a7..55abfa118 100644 --- a/src/remote-desktop.c +++ b/src/remote-desktop.c @@ -107,17 +107,8 @@ typedef struct _RemoteDesktopSessionClass SessionClass parent_class; } RemoteDesktopSessionClass; -GType remote_desktop_session_get_type (void); - G_DEFINE_TYPE (RemoteDesktopSession, remote_desktop_session, session_get_type ()) -gboolean -is_remote_desktop_session (Session *session) -{ - return G_TYPE_CHECK_INSTANCE_TYPE (session, - remote_desktop_session_get_type ()); -} - gboolean remote_desktop_session_can_select_sources (RemoteDesktopSession *session) { @@ -227,7 +218,7 @@ remote_desktop_session_new (GVariant *options, if (session) g_debug ("remote desktop session owned by '%s' created", session->sender); - return (RemoteDesktopSession *)session; + return REMOTE_DESKTOP_SESSION (session); } static void @@ -328,7 +319,7 @@ handle_create_session (XdpDbusRemoteDesktop *object, request_set_impl_request (request, impl_request); request_export (request, g_dbus_method_invocation_get_connection (invocation)); - session = (Session *)remote_desktop_session_new (arg_options, request, &error); + session = SESSION (remote_desktop_session_new (arg_options, request, &error)); if (!session) { g_dbus_method_invocation_return_gerror (invocation, error); @@ -408,7 +399,8 @@ select_devices_done (GObject *source_object, } else if (!session->closed) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = + REMOTE_DESKTOP_SESSION (session); remote_desktop_session->devices_selected = TRUE; } @@ -483,7 +475,7 @@ replace_remote_desktop_restore_token_with_data (Session *session, GVariant **in_out_options, GError **error) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *) session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); g_autoptr(GVariant) options = NULL; PersistMode persist_mode; @@ -529,7 +521,7 @@ handle_select_devices (XdpDbusRemoteDesktop *object, SESSION_AUTOLOCK_UNREF (session); - remote_desktop_session = (RemoteDesktopSession *)session; + remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (!remote_desktop_session_can_select_devices (remote_desktop_session)) { @@ -600,7 +592,7 @@ static void replace_restore_remote_desktop_data_with_token (RemoteDesktopSession *remote_desktop_session, GVariant **in_out_results) { - xdp_session_persistence_replace_restore_data_with_token ((Session *) remote_desktop_session, + xdp_session_persistence_replace_restore_data_with_token (SESSION (remote_desktop_session), REMOTE_DESKTOP_TABLE, in_out_results, &remote_desktop_session->persist_mode, @@ -652,7 +644,7 @@ start_done (GObject *source_object, REQUEST_AUTOLOCK (request); session = g_object_get_qdata (G_OBJECT (request), quark_request_session); - remote_desktop_session = (RemoteDesktopSession *)session; + remote_desktop_session = REMOTE_DESKTOP_SESSION (session); SESSION_AUTOLOCK_UNREF (g_object_ref (session)); g_object_set_qdata (G_OBJECT (request), quark_request_session, NULL); @@ -735,7 +727,7 @@ handle_start (XdpDbusRemoteDesktop *object, SESSION_AUTOLOCK_UNREF (session); - remote_desktop_session = (RemoteDesktopSession *)session; + remote_desktop_session = REMOTE_DESKTOP_SESSION (session); switch (remote_desktop_session->state) { case REMOTE_DESKTOP_SESSION_STATE_INIT: @@ -799,7 +791,7 @@ static gboolean check_notify (Session *session, DeviceType device_type) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (!remote_desktop_session->devices_selected || remote_desktop_session->uses_eis) return FALSE; @@ -825,7 +817,7 @@ check_position (Session *session, double x, double y) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); GList *l; for (l = remote_desktop_session->streams; l; l = l->next) @@ -1493,7 +1485,7 @@ handle_connect_to_eis (XdpDbusRemoteDesktop *object, SESSION_AUTOLOCK_UNREF (session); - if (!is_remote_desktop_session (session)) + if (!IS_REMOTE_DESKTOP_SESSION (session)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, @@ -1502,7 +1494,7 @@ handle_connect_to_eis (XdpDbusRemoteDesktop *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } - remote_desktop_session = (RemoteDesktopSession *)session; + remote_desktop_session = REMOTE_DESKTOP_SESSION (session); if (remote_desktop_session->uses_eis) { @@ -1646,7 +1638,7 @@ remote_desktop_create (GDBusConnection *connection, static void remote_desktop_session_close (Session *session) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *)session; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (session); remote_desktop_session->state = REMOTE_DESKTOP_SESSION_STATE_CLOSED; @@ -1656,7 +1648,7 @@ remote_desktop_session_close (Session *session) static void remote_desktop_session_finalize (GObject *object) { - RemoteDesktopSession *remote_desktop_session = (RemoteDesktopSession *)object; + RemoteDesktopSession *remote_desktop_session = REMOTE_DESKTOP_SESSION (object); g_list_free_full (remote_desktop_session->streams, (GDestroyNotify)screen_cast_stream_free); diff --git a/src/remote-desktop.h b/src/remote-desktop.h index 5e47c943f..46813a0f8 100644 --- a/src/remote-desktop.h +++ b/src/remote-desktop.h @@ -27,7 +27,19 @@ typedef struct _RemoteDesktopSession RemoteDesktopSession; -gboolean is_remote_desktop_session (Session *session); +GType remote_desktop_session_get_type (void); + +G_GNUC_UNUSED static inline RemoteDesktopSession * +REMOTE_DESKTOP_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, remote_desktop_session_get_type (), RemoteDesktopSession); +} + +G_GNUC_UNUSED static inline gboolean +IS_REMOTE_DESKTOP_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, remote_desktop_session_get_type ()); +} GList * remote_desktop_session_get_streams (RemoteDesktopSession *session); diff --git a/src/request.c b/src/request.c index 447edc383..70353c636 100644 --- a/src/request.c +++ b/src/request.c @@ -38,7 +38,7 @@ request_on_signal_response (XdpDbusRequest *object, guint arg_response, GVariant *arg_results) { - Request *request = (Request *)object; + Request *request = REQUEST (object); XdpDbusRequestSkeleton *skeleton = XDP_DBUS_REQUEST_SKELETON (object); GList *connections, *l; GVariant *signal_variant; @@ -67,7 +67,7 @@ static gboolean handle_close (XdpDbusRequest *object, GDBusMethodInvocation *invocation) { - Request *request = (Request *)object; + Request *request = REQUEST (object); g_autoptr(GError) error = NULL; g_debug ("Handling Close"); @@ -112,7 +112,7 @@ request_init (Request *request) static void request_finalize (GObject *object) { - Request *request = (Request *)object; + Request *request = REQUEST (object); G_LOCK (requests); g_hash_table_remove (requests, request->id); diff --git a/src/request.h b/src/request.h index 27a8ee3bb..20dfd9c57 100644 --- a/src/request.h +++ b/src/request.h @@ -57,6 +57,18 @@ struct _RequestClass GType request_get_type (void) G_GNUC_CONST; +G_GNUC_UNUSED static inline Request * +REQUEST (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, request_get_type (), Request); +} + +G_GNUC_UNUSED static inline gboolean +IS_REQUEST (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, request_get_type ()); +} + G_DEFINE_AUTOPTR_CLEANUP_FUNC (Request, g_object_unref) void request_init_invocation (GDBusMethodInvocation *invocation, XdpAppInfo *app_info); diff --git a/src/screen-cast.c b/src/screen-cast.c index bb115aa3c..b9f223e2e 100644 --- a/src/screen-cast.c +++ b/src/screen-cast.c @@ -109,11 +109,16 @@ GType screen_cast_session_get_type (void); G_DEFINE_TYPE (ScreenCastSession, screen_cast_session, session_get_type ()) +G_GNUC_UNUSED static inline ScreenCastSession * +SCREEN_CAST_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, screen_cast_session_get_type (), ScreenCastSession); +} -static gboolean -is_screen_cast_session (Session *session) +G_GNUC_UNUSED static inline gboolean +IS_SCREEN_CAST_SESSION (gpointer ptr) { - return G_TYPE_CHECK_INSTANCE_TYPE (session, screen_cast_session_get_type ()); + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, screen_cast_session_get_type ()); } static ScreenCastSession * @@ -246,7 +251,7 @@ handle_create_session (XdpDbusScreenCast *object, request_set_impl_request (request, impl_request); request_export (request, g_dbus_method_invocation_get_connection (invocation)); - session = (Session *)screen_cast_session_new (arg_options, request, &error); + session = SESSION (screen_cast_session_new (arg_options, request, &error)); if (!session) { g_dbus_method_invocation_return_gerror (invocation, error); @@ -325,19 +330,19 @@ select_sources_done (GObject *source_object, } else if (!session->closed) { - if (is_screen_cast_session (session)) + if (IS_SCREEN_CAST_SESSION (session)) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)session; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (session); g_assert_cmpint (screen_cast_session->state, ==, SCREEN_CAST_SESSION_STATE_SELECTING_SOURCES); screen_cast_session->state = SCREEN_CAST_SESSION_STATE_SOURCES_SELECTED; } - else if (is_remote_desktop_session (session)) + else if (IS_REMOTE_DESKTOP_SESSION (session)) { RemoteDesktopSession *remote_desktop_session = - (RemoteDesktopSession *)session; + REMOTE_DESKTOP_SESSION (session); remote_desktop_session_sources_selected (remote_desktop_session); } @@ -444,7 +449,7 @@ replace_screen_cast_restore_token_with_data (Session *session, if (!g_variant_lookup (options, "persist_mode", "u", &persist_mode)) persist_mode = PERSIST_MODE_NONE; - if (is_remote_desktop_session (session)) + if (IS_REMOTE_DESKTOP_SESSION (session)) { if (persist_mode != PERSIST_MODE_NONE || xdp_variant_contains_key (options, "restore_token")) @@ -457,9 +462,9 @@ replace_screen_cast_restore_token_with_data (Session *session, } } - if (is_screen_cast_session (session)) + if (IS_SCREEN_CAST_SESSION (session)) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)session; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (session); screen_cast_session->persist_mode = persist_mode; xdp_session_persistence_replace_restore_token_with_data (session, @@ -502,9 +507,9 @@ handle_select_sources (XdpDbusScreenCast *object, SESSION_AUTOLOCK_UNREF (session); - if (is_screen_cast_session (session)) + if (IS_SCREEN_CAST_SESSION (session)) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)session; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (session); switch (screen_cast_session->state) { @@ -532,10 +537,10 @@ handle_select_sources (XdpDbusScreenCast *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } } - else if (is_remote_desktop_session (session)) + else if (IS_REMOTE_DESKTOP_SESSION (session)) { RemoteDesktopSession *remote_desktop_session = - (RemoteDesktopSession *)session; + REMOTE_DESKTOP_SESSION (session); if (!remote_desktop_session_can_select_sources (remote_desktop_session)) { @@ -596,9 +601,9 @@ handle_select_sources (XdpDbusScreenCast *object, quark_request_session, g_object_ref (session), g_object_unref); - if (is_screen_cast_session (session)) + if (IS_SCREEN_CAST_SESSION (session)) { - ((ScreenCastSession *)session)->state = + SCREEN_CAST_SESSION (session)->state = SCREEN_CAST_SESSION_STATE_SELECTING_SOURCES; } @@ -733,7 +738,7 @@ static void replace_restore_screen_cast_data_with_token (ScreenCastSession *screen_cast_session, GVariant **in_out_results) { - xdp_session_persistence_replace_restore_data_with_token ((Session *) screen_cast_session, + xdp_session_persistence_replace_restore_data_with_token (SESSION (screen_cast_session), SCREEN_CAST_TABLE, in_out_results, &screen_cast_session->persist_mode, @@ -792,7 +797,7 @@ start_done (GObject *source_object, should_close_session = !request->exported || response != 0; - screen_cast_session = (ScreenCastSession *)session; + screen_cast_session = SCREEN_CAST_SESSION (session); if (request->exported) { @@ -862,7 +867,7 @@ handle_start (XdpDbusScreenCast *object, SESSION_AUTOLOCK_UNREF (session); - screen_cast_session = (ScreenCastSession *)session; + screen_cast_session = SCREEN_CAST_SESSION (session); switch (screen_cast_session->state) { case SCREEN_CAST_SESSION_STATE_SOURCES_SELECTED: @@ -959,16 +964,16 @@ handle_open_pipewire_remote (XdpDbusScreenCast *object, SESSION_AUTOLOCK_UNREF (session); - if (is_screen_cast_session (session)) + if (IS_SCREEN_CAST_SESSION (session)) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)session; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (session); streams = screen_cast_session->streams; } - else if (is_remote_desktop_session (session)) + else if (IS_REMOTE_DESKTOP_SESSION (session)) { RemoteDesktopSession *remote_desktop_session = - (RemoteDesktopSession *)session; + REMOTE_DESKTOP_SESSION (session); streams = remote_desktop_session_get_streams (remote_desktop_session); } @@ -1121,7 +1126,7 @@ screen_cast_create (GDBusConnection *connection, static void screen_cast_session_close (Session *session) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)session; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (session); screen_cast_session->state = SCREEN_CAST_SESSION_STATE_CLOSED; @@ -1137,7 +1142,7 @@ screen_cast_session_close (Session *session) static void screen_cast_session_finalize (GObject *object) { - ScreenCastSession *screen_cast_session = (ScreenCastSession *)object; + ScreenCastSession *screen_cast_session = SCREEN_CAST_SESSION (object); g_clear_pointer (&screen_cast_session->restore_token, g_free); g_clear_pointer (&screen_cast_session->restore_data, g_variant_unref); diff --git a/src/screenshot.c b/src/screenshot.c index 1626b0c64..974a33d68 100644 --- a/src/screenshot.c +++ b/src/screenshot.c @@ -191,7 +191,7 @@ handle_screenshot_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); g_autoptr(GError) error = NULL; g_autoptr(XdpDbusImplRequest) impl_request = NULL; GVariantBuilder opt_builder; diff --git a/src/session.c b/src/session.c index ad8d922c0..607256591 100644 --- a/src/session.c +++ b/src/session.c @@ -217,7 +217,7 @@ static gboolean handle_close (XdpDbusSession *object, GDBusMethodInvocation *invocation) { - Session *session = (Session *)object; + Session *session = SESSION (object); SESSION_AUTOLOCK_UNREF (g_object_ref (session)); @@ -283,7 +283,7 @@ close_sessions_for_sender (const char *sender) static void on_closed (XdpDbusImplSession *object, GObject *data) { - Session *session = (Session *)data; + Session *session = SESSION (data); SESSION_AUTOLOCK_UNREF (g_object_ref (session)); @@ -316,7 +316,7 @@ session_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { - Session *session = (Session *)initable; + Session *session = SESSION (initable); g_autofree char *sender_escaped = NULL; g_autofree char *id = NULL; g_autoptr(XdpDbusImplSession) impl_session = NULL; @@ -377,7 +377,7 @@ session_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - Session *session = (Session *)object; + Session *session = SESSION (object); switch (prop_id) { @@ -416,7 +416,7 @@ session_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - Session *session = (Session *)object; + Session *session = SESSION (object); switch (prop_id) { @@ -452,7 +452,7 @@ session_get_property (GObject *object, static void session_finalize (GObject *object) { - Session *session = (Session *)object; + Session *session = SESSION (object); g_assert (!session->id || !g_hash_table_lookup (sessions, session->id)); diff --git a/src/session.h b/src/session.h index f12ca5a4a..283543ae6 100644 --- a/src/session.h +++ b/src/session.h @@ -58,6 +58,18 @@ struct _SessionClass GType session_get_type (void); +G_GNUC_UNUSED static inline Session * +SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, session_get_type (), Session); +} + +G_GNUC_UNUSED static inline gboolean +IS_SESSION (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, session_get_type ()); +} + G_DEFINE_AUTOPTR_CLEANUP_FUNC (Session, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (XdpDbusImplSession, g_object_unref) diff --git a/src/wallpaper.c b/src/wallpaper.c index 5832699f2..66c1f949e 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -125,7 +125,7 @@ handle_set_wallpaper_in_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { - Request *request = (Request *)task_data; + Request *request = REQUEST (task_data); const char *parent_window; const char *id = xdp_app_info_get_id (request->app_info); g_autoptr(GError) error = NULL;