Blame src/nm-dbus-utils.h

Packit Service 87a54e
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2018 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#ifndef __NM_DBUS_UTILS_H__
Packit 5756e2
#define __NM_DBUS_UTILS_H__
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
struct _NMDBusInterfaceInfoExtended;
Packit 5756e2
struct _NMDBusMethodInfoExtended;
Packit 5756e2
Packit 5756e2
struct _NMDBusPropertyInfoExtendedBase {
Packit Service a1bd4f
    GDBusPropertyInfo _parent;
Packit Service a1bd4f
    const char *      property_name;
Packit 5756e2
Packit Service a1bd4f
    /* Whether the properties needs to be notified on the legacy
Packit Service a1bd4f
     * PropertyChanged signal. This is only to preserve API, new
Packit Service a1bd4f
     * properties should not use this. */
Packit Service a1bd4f
    bool include_in_legacy_property_changed;
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
struct _NMDBusPropertyInfoExtendedReadWritable {
Packit Service a1bd4f
    struct _NMDBusPropertyInfoExtendedBase _base;
Packit 5756e2
Packit Service a1bd4f
    /* this is the polkit permission type for authenticating setting
Packit Service a1bd4f
     * the property. */
Packit Service a1bd4f
    const char *permission;
Packit 5756e2
Packit Service a1bd4f
    /* this is the audit operation type for writing the property. */
Packit Service a1bd4f
    const char *audit_op;
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        GDBusPropertyInfo                              _parent;
Packit Service a1bd4f
        struct _NMDBusPropertyInfoExtendedBase         _base;
Packit Service a1bd4f
        struct _NMDBusPropertyInfoExtendedReadWritable writable;
Packit Service a1bd4f
Packit Service a1bd4f
        /* duplicate the base structure in the union, so that the common fields
Packit Service a1bd4f
         * are accessible directly in the parent struct. */
Packit Service a1bd4f
        struct {
Packit Service a1bd4f
            GDBusPropertyInfo parent;
Packit Service a1bd4f
            const char *      property_name;
Packit Service a1bd4f
Packit Service a1bd4f
            /* Whether the properties needs to be notified on the legacy
Packit Service a1bd4f
             * PropertyChanged signal. This is only to preserve API, new
Packit Service a1bd4f
             * properties should not use this. */
Packit Service a1bd4f
            bool include_in_legacy_property_changed;
Packit Service a1bd4f
        };
Packit Service a1bd4f
    };
Packit 5756e2
} NMDBusPropertyInfoExtended;
Packit 5756e2
Packit Service a1bd4f
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMDBusPropertyInfoExtended, property_name)
Packit Service a1bd4f
                == G_STRUCT_OFFSET(struct _NMDBusPropertyInfoExtendedBase, property_name));
Packit Service a1bd4f
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMDBusPropertyInfoExtended, include_in_legacy_property_changed)
Packit Service a1bd4f
                == G_STRUCT_OFFSET(struct _NMDBusPropertyInfoExtendedBase,
Packit Service a1bd4f
                                   include_in_legacy_property_changed));
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_FULL(m_name,                               \
Packit Service a1bd4f
                                                            m_signature,                          \
Packit Service a1bd4f
                                                            m_property_name,                      \
Packit Service a1bd4f
                                                            m_include_in_legacy_property_changed) \
Packit Service a1bd4f
    ((GDBusPropertyInfo *) &((const struct _NMDBusPropertyInfoExtendedBase){                      \
Packit Service a1bd4f
        ._parent =                                                                                \
Packit Service a1bd4f
            {                                                                                     \
Packit Service a1bd4f
                .ref_count = -1,                                                                  \
Packit Service a1bd4f
                .name      = m_name,                                                              \
Packit Service a1bd4f
                .signature = m_signature,                                                         \
Packit Service a1bd4f
                .flags     = G_DBUS_PROPERTY_INFO_FLAGS_READABLE,                                 \
Packit Service a1bd4f
            },                                                                                    \
Packit Service a1bd4f
        .property_name                      = m_property_name,                                    \
Packit Service a1bd4f
        .include_in_legacy_property_changed = m_include_in_legacy_property_changed,               \
Packit Service a1bd4f
    }))
Packit 5756e2
Packit 5756e2
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE(m_name, m_signature, m_property_name) \
Packit Service a1bd4f
    NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_FULL(m_name, m_signature, m_property_name, FALSE)
Packit 5756e2
Packit 5756e2
/* define a legacy property. Do not use for new code. */
Packit 5756e2
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L(m_name, m_signature, m_property_name) \
Packit Service a1bd4f
    NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_FULL(m_name, m_signature, m_property_name, TRUE)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE_FULL(                            \
Packit Service a1bd4f
    m_name,                                                                                 \
Packit Service a1bd4f
    m_signature,                                                                            \
Packit Service a1bd4f
    m_property_name,                                                                        \
Packit Service a1bd4f
    m_permission,                                                                           \
Packit Service a1bd4f
    m_audit_op,                                                                             \
Packit Service a1bd4f
    m_include_in_legacy_property_changed)                                                   \
Packit Service a1bd4f
    ((GDBusPropertyInfo *) &((const struct _NMDBusPropertyInfoExtendedReadWritable){        \
Packit Service a1bd4f
        ._base =                                                                            \
Packit Service a1bd4f
            {                                                                               \
Packit Service a1bd4f
                ._parent =                                                                  \
Packit Service a1bd4f
                    {                                                                       \
Packit Service a1bd4f
                        .ref_count = -1,                                                    \
Packit Service a1bd4f
                        .name      = m_name,                                                \
Packit Service a1bd4f
                        .signature = m_signature,                                           \
Packit Service a1bd4f
                        .flags     = G_DBUS_PROPERTY_INFO_FLAGS_READABLE                    \
Packit Service a1bd4f
                                 | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,                     \
Packit Service a1bd4f
                    },                                                                      \
Packit Service a1bd4f
                .property_name                      = m_property_name,                      \
Packit Service a1bd4f
                .include_in_legacy_property_changed = m_include_in_legacy_property_changed, \
Packit Service a1bd4f
            },                                                                              \
Packit Service a1bd4f
        .permission = m_permission,                                                         \
Packit Service a1bd4f
        .audit_op   = m_audit_op,                                                           \
Packit Service a1bd4f
    }))
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE(m_name,           \
Packit Service a1bd4f
                                                           m_signature,      \
Packit Service a1bd4f
                                                           m_property_name,  \
Packit Service a1bd4f
                                                           m_permission,     \
Packit Service a1bd4f
                                                           m_audit_op)       \
Packit Service a1bd4f
    NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE_FULL(m_name,          \
Packit Service a1bd4f
                                                            m_signature,     \
Packit Service a1bd4f
                                                            m_property_name, \
Packit Service a1bd4f
                                                            m_permission,    \
Packit Service a1bd4f
                                                            m_audit_op,      \
Packit Service a1bd4f
                                                            FALSE)
Packit 5756e2
Packit 5756e2
/* define a legacy property. Do not use for new code. */
Packit Service a1bd4f
#define NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE_L(m_name,          \
Packit Service a1bd4f
                                                             m_signature,     \
Packit Service a1bd4f
                                                             m_property_name, \
Packit Service a1bd4f
                                                             m_permission,    \
Packit Service a1bd4f
                                                             m_audit_op)      \
Packit Service a1bd4f
    NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READWRITABLE_FULL(m_name,           \
Packit Service a1bd4f
                                                            m_signature,      \
Packit Service a1bd4f
                                                            m_property_name,  \
Packit Service a1bd4f
                                                            m_permission,     \
Packit Service a1bd4f
                                                            m_audit_op,       \
Packit Service a1bd4f
                                                            TRUE)
Packit 5756e2
Packit 5756e2
typedef struct _NMDBusMethodInfoExtended {
Packit Service a1bd4f
    GDBusMethodInfo parent;
Packit Service a1bd4f
    void (*handle)(NMDBusObject *                             obj,
Packit Service a1bd4f
                   const struct _NMDBusInterfaceInfoExtended *interface_info,
Packit Service a1bd4f
                   const struct _NMDBusMethodInfoExtended *   method_info,
Packit Service a1bd4f
                   GDBusConnection *                          connection,
Packit Service a1bd4f
                   const char *                               sender,
Packit Service a1bd4f
                   GDBusMethodInvocation *                    invocation,
Packit Service a1bd4f
                   GVariant *                                 parameters);
Packit Service a1bd4f
    bool allow_during_shutdown;
Packit 5756e2
} NMDBusMethodInfoExtended;
Packit 5756e2
Packit 5756e2
#define NM_DEFINE_DBUS_METHOD_INFO_EXTENDED(parent_, ...) \
Packit Service a1bd4f
    ((GDBusMethodInfo *) (&((const NMDBusMethodInfoExtended){.parent = parent_, __VA_ARGS__})))
Packit 5756e2
Packit 5756e2
typedef struct _NMDBusInterfaceInfoExtended {
Packit Service a1bd4f
    GDBusInterfaceInfo parent;
Packit 5756e2
Packit Service a1bd4f
    /* Whether the interface has a legacy property changed signal (@nm_signal_info_property_changed_legacy).
Packit Service a1bd4f
     * New interfaces should not use this. */
Packit Service a1bd4f
    bool legacy_property_changed : 1;
Packit 5756e2
} NMDBusInterfaceInfoExtended;
Packit 5756e2
Packit 5756e2
extern const GDBusSignalInfo nm_signal_info_property_changed_legacy;
Packit 5756e2
Packit Service a1bd4f
#define NM_DBUS_INTERFACE_INFOS(...)                                           \
Packit Service a1bd4f
    ({                                                                         \
Packit Service a1bd4f
        static const NMDBusInterfaceInfoExtended *const _interface_infos[] = { \
Packit Service a1bd4f
            __VA_ARGS__,                                                       \
Packit Service a1bd4f
            NULL,                                                              \
Packit Service a1bd4f
        };                                                                     \
Packit Service a1bd4f
        _interface_infos;                                                      \
Packit Service a1bd4f
    });
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
GDBusPropertyInfo *
Packit Service a1bd4f
nm_dbus_utils_interface_info_lookup_property(const GDBusInterfaceInfo *interface_info,
Packit Service a1bd4f
                                             const char *              property_name,
Packit Service a1bd4f
                                             guint *                   property_idx);
Packit 5756e2
Packit Service a1bd4f
GDBusMethodInfo *
Packit Service a1bd4f
nm_dbus_utils_interface_info_lookup_method(const GDBusInterfaceInfo *interface_info,
Packit Service a1bd4f
                                           const char *              method_name);
Packit 5756e2
Packit Service a1bd4f
GVariant *
Packit Service a1bd4f
nm_dbus_utils_get_property(GObject *obj, const char *signature, const char *property_name);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
struct CList;
Packit 5756e2
Packit Service a1bd4f
const char **nm_dbus_utils_get_paths_for_clist(const struct CList *lst_head,
Packit Service a1bd4f
                                               gssize              lst_len,
Packit Service a1bd4f
                                               guint               member_offset,
Packit Service a1bd4f
                                               gboolean            expect_all_exported);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_utils_g_value_set_object_path(GValue *value, gpointer object);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_utils_g_value_set_object_path_still_exported(GValue *value, gpointer object);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_utils_g_value_set_object_path_from_hash(GValue *    value,
Packit Service a1bd4f
                                                     GHashTable *hash,
Packit Service a1bd4f
                                                     gboolean    expect_all_exported);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        gpointer const obj;
Packit Service a1bd4f
        gpointer       _obj;
Packit Service a1bd4f
    };
Packit Service a1bd4f
    GObject *         _notify_target;
Packit Service a1bd4f
    const GParamSpec *_notify_pspec;
Packit Service a1bd4f
    gulong            _notify_signal_id;
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        const bool visible;
Packit Service a1bd4f
        bool       _visible;
Packit Service a1bd4f
    };
Packit 5756e2
} NMDBusTrackObjPath;
Packit 5756e2
Packit Service a1bd4f
void
Packit Service a1bd4f
nm_dbus_track_obj_path_init(NMDBusTrackObjPath *track, GObject *target, const GParamSpec *pspec);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_track_obj_path_deinit(NMDBusTrackObjPath *track);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_track_obj_path_notify(const NMDBusTrackObjPath *track);
Packit 5756e2
Packit Service a1bd4f
const char *nm_dbus_track_obj_path_get(const NMDBusTrackObjPath *track);
Packit 5756e2
Packit Service a1bd4f
void nm_dbus_track_obj_path_set(NMDBusTrackObjPath *track, gpointer obj, gboolean visible);
Packit 5756e2
Packit 5756e2
#endif /* __NM_DBUS_UTILS_H__ */