Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cast and type-check functions for Session and Request #1440

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,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;
Expand Down
2 changes: 1 addition & 1 deletion src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,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);
Expand Down
26 changes: 12 additions & 14 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ 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,
G_DBUS_ERROR_ACCESS_DENIED,
"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))
{
Expand Down Expand Up @@ -128,7 +128,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,
Expand All @@ -137,7 +137,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,
Expand Down Expand Up @@ -238,7 +238,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,
Expand All @@ -247,7 +247,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,
Expand Down Expand Up @@ -289,7 +289,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,
Expand All @@ -298,7 +298,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,
Expand Down Expand Up @@ -379,7 +379,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,
Expand All @@ -388,7 +388,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,
Expand Down Expand Up @@ -450,8 +450,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) &&
Expand Down Expand Up @@ -487,8 +486,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) &&
Expand Down
28 changes: 22 additions & 6 deletions src/global-shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,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;
}
Expand Down Expand Up @@ -131,7 +144,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
Expand Down Expand Up @@ -251,7 +264,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);
Expand Down Expand Up @@ -591,7 +604,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);

Expand All @@ -617,7 +631,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);

Expand All @@ -641,7 +656,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);

Expand Down
20 changes: 16 additions & 4 deletions src/inhibit.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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;
Expand Down Expand Up @@ -263,10 +263,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;

Expand Down Expand Up @@ -419,7 +431,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);
Expand Down Expand Up @@ -493,7 +505,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;

Expand Down
Loading
Loading