Blame shared/nm-default.h

Packit Service a1bd4f
/* SPDX-License-Identifier: LGPL-2.1+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2015 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/* With autotools (and also meson), all our source files are expected to include <config.h>.
Packit 5756e2
 * as very first header. Then they are expected to include "config-extra.h" and a small set
Packit 5756e2
 * of headers that we always want to have included (depending on what sources we compile
Packit 5756e2
 * (as determined by NETWORKMANAGER_COMPILATION define) that can be  "nm-glib-aux/nm-macros-internal.h"
Packit 5756e2
 * and similar.
Packit 5756e2
 *
Packit 5756e2
 * To simplify that, all our source files are only expected to include "nm-default.h" as first,
Packit 5756e2
 * and thereby rely on getting a basic set of headers already.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#ifndef __NM_DEFAULT_H__
Packit 5756e2
#define __NM_DEFAULT_H__
Packit 5756e2
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB                (1 << 0)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB       (1 << 1)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG      (1 << 2)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM               (1 << 3)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE       (1 << 4)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE          (1 << 5)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL (1 << 6)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE  (1 << 7)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON              (1 << 10)
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD             (1 << 11)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE             \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB             \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB      \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE         \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_LIBNM                                                        \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB                                                   \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE                                            \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE                                               \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_CLIENT             \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB         \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_DAEMON                  \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB              \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG      \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE          \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL \
Packit Service a1bd4f
     | NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD_SHARED \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB | NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD \
Packit Service a1bd4f
    (0 | NM_NETWORKMANAGER_COMPILATION_DAEMON | NM_NETWORKMANAGER_COMPILATION_SYSTEMD_SHARED)
Packit Service a1bd4f
Packit Service a1bd4f
#define NM_NETWORKMANAGER_COMPILATION_GLIB (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB)
Packit 5756e2
Packit 5756e2
#ifndef NETWORKMANAGER_COMPILATION
Packit Service a1bd4f
    #error Define NETWORKMANAGER_COMPILATION accordingly
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#ifndef G_LOG_DOMAIN
Packit Service a1bd4f
    #if defined(NETWORKMANAGER_COMPILATION_TEST)
Packit Service a1bd4f
        #define G_LOG_DOMAIN "test"
Packit Service a1bd4f
    #elif NETWORKMANAGER_COMPILATION & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
Packit Service a1bd4f
        #define G_LOG_DOMAIN "NetworkManager"
Packit Service a1bd4f
    #else
Packit Service a1bd4f
        #error Need to define G_LOG_DOMAIN
Packit Service a1bd4f
    #endif
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
/* always include these headers for our internal source files. */
Packit 5756e2
Packit 5756e2
#ifndef ___CONFIG_H__
Packit Service a1bd4f
    #define ___CONFIG_H__
Packit Service a1bd4f
    #include <config.h>
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#include "config-extra.h"
Packit 5756e2
Packit 5756e2
/* for internal compilation we don't want the deprecation macros
Packit 5756e2
 * to be in effect. Define the widest range of versions to effectively
Packit 5756e2
 * disable deprecation checks */
Packit Service a1bd4f
#define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8
Packit 5756e2
Packit 5756e2
#ifndef NM_MORE_ASSERTS
Packit Service a1bd4f
    #define NM_MORE_ASSERTS 0
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#if NM_MORE_ASSERTS == 0
Packit Service a1bd4f
    /* The cast macros like NM_TYPE() are implemented via G_TYPE_CHECK_INSTANCE_CAST()
Packit 5756e2
 * and _G_TYPE_CIC(). The latter, by default performs runtime checks of the type
Packit 5756e2
 * by calling g_type_check_instance_cast().
Packit 5756e2
 * This check has a certain overhead without being helpful.
Packit 5756e2
 *
Packit 5756e2
 * Example 1:
Packit 5756e2
 *     static void foo (NMType *obj)
Packit 5756e2
 *     {
Packit 5756e2
 *         access_obj_without_check (obj);
Packit 5756e2
 *     }
Packit 5756e2
 *     foo ((NMType *) obj);
Packit 5756e2
 *     // There is no runtime check and passing an invalid pointer
Packit 5756e2
 *     // leads to a crash.
Packit 5756e2
 *
Packit 5756e2
 * Example 2:
Packit 5756e2
 *     static void foo (NMType *obj)
Packit 5756e2
 *     {
Packit 5756e2
 *         access_obj_without_check (obj);
Packit 5756e2
 *     }
Packit 5756e2
 *     foo (NM_TYPE (obj));
Packit 5756e2
 *     // There is a runtime check which prints a g_warning(), but that doesn't
Packit 5756e2
 *     // avoid the crash as NM_TYPE() cannot do anything then passing on the
Packit 5756e2
 *     // invalid pointer.
Packit 5756e2
 *
Packit 5756e2
 * Example 3:
Packit 5756e2
 *     static void foo (NMType *obj)
Packit 5756e2
 *     {
Packit 5756e2
 *         g_return_if_fail (NM_IS_TYPE (obj));
Packit 5756e2
 *         access_obj_without_check (obj);
Packit 5756e2
 *     }
Packit 5756e2
 *     foo ((NMType *) obj);
Packit 5756e2
 *     // There is a runtime check which prints a g_critical() which also avoids
Packit 5756e2
 *     // the crash. That is actually helpful to catch bugs and avoid crashes.
Packit 5756e2
 *
Packit 5756e2
 * Example 4:
Packit 5756e2
 *     static void foo (NMType *obj)
Packit 5756e2
 *     {
Packit 5756e2
 *         g_return_if_fail (NM_IS_TYPE (obj));
Packit 5756e2
 *         access_obj_without_check (obj);
Packit 5756e2
 *     }
Packit 5756e2
 *     foo (NM_TYPE (obj));
Packit 5756e2
 *     // The runtime check is performed twice, with printing a g_warning() and
Packit 5756e2
 *     // a g_critical() and avoiding the crash.
Packit 5756e2
 *
Packit 5756e2
 * Example 3 is how it should be done. Type checks in NM_TYPE() are pointless.
Packit 5756e2
 * Disable them for our production builds.
Packit 5756e2
 */
Packit Service a1bd4f
    #ifndef G_DISABLE_CAST_CHECKS
Packit Service a1bd4f
        #define G_DISABLE_CAST_CHECKS
Packit Service a1bd4f
    #endif
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#if NM_MORE_ASSERTS == 0
Packit Service a1bd4f
    #ifndef G_DISABLE_CAST_CHECKS
Packit Service a1bd4f
        /* Unless compiling with G_DISABLE_CAST_CHECKS, glib performs type checking
Packit 5756e2
 * during G_VARIANT_TYPE() via g_variant_type_checked_(). This is not necessary
Packit 5756e2
 * because commonly this cast is needed during something like
Packit 5756e2
 *
Packit 5756e2
 *   g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
Packit 5756e2
 *
Packit 5756e2
 * Note that in if the variant type would be invalid, the check still
Packit 5756e2
 * wouldn't make the buggy code magically work. Instead of passing a
Packit 5756e2
 * bogus type string (bad), it would pass %NULL to g_variant_builder_init()
Packit 5756e2
 * (also bad).
Packit 5756e2
 *
Packit 5756e2
 * Also, a function like g_variant_builder_init() already validates
Packit 5756e2
 * the input type via something like
Packit 5756e2
 *
Packit 5756e2
 *   g_return_if_fail (g_variant_type_is_container (type));
Packit 5756e2
 *
Packit 5756e2
 * So, by having G_VARIANT_TYPE() also validate the type, we validate
Packit 5756e2
 * twice, whereas the first validation is rather pointless because it
Packit 5756e2
 * doesn't prevent the function to be called with invalid arguments.
Packit 5756e2
 *
Packit 5756e2
 * Just patch G_VARIANT_TYPE() to perform no check.
Packit 5756e2
 */
Packit Service a1bd4f
        #undef G_VARIANT_TYPE
Packit Service a1bd4f
        #define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
Packit Service a1bd4f
    #endif
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#include <stdlib.h>
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB
Packit 5756e2
Packit Service a1bd4f
    #include <glib.h>
Packit 5756e2
Packit Service a1bd4f
    #if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG
Packit Service a1bd4f
        #if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
Packit Service a1bd4f
            #error Cannot define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG and NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
Packit Service a1bd4f
        #endif
Packit Service a1bd4f
        #include <glib/gi18n.h>
Packit Service a1bd4f
    #elif (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
Packit Service a1bd4f
        #include <glib/gi18n-lib.h>
Packit Service a1bd4f
    #endif
Packit 5756e2
Packit Service a1bd4f
    /*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
    #if NM_MORE_ASSERTS == 0
Packit 5756e2
Packit 5756e2
/* glib assertions (g_return_*(), g_assert*()) contain a textual representation
Packit 5756e2
 * of the checked statement. This part of the assertion blows up the size of the
Packit 5756e2
 * binary. Unless we compile a debug-build with NM_MORE_ASSERTS, drop these
Packit 5756e2
 * parts. Note that the failed assertion still prints the file and line where the
Packit 5756e2
 * assertion fails. That shall suffice. */
Packit 5756e2
Packit 5756e2
static inline void
Packit Service a1bd4f
_nm_g_return_if_fail_warning(const char *log_domain, const char *file, int line)
Packit 5756e2
{
Packit Service a1bd4f
    char file_buf[256 + 15];
Packit 5756e2
Packit Service a1bd4f
    g_snprintf(file_buf, sizeof(file_buf), "((%s:%d))", file, line);
Packit Service a1bd4f
    g_return_if_fail_warning(log_domain, file_buf, "<dropped>");
Packit 5756e2
}
Packit 5756e2
Packit Service a1bd4f
        #define g_return_if_fail_warning(log_domain, pretty_function, expression) \
Packit Service a1bd4f
            _nm_g_return_if_fail_warning(log_domain, __FILE__, __LINE__)
Packit Service a1bd4f
Packit Service a1bd4f
        #define g_assertion_message_expr(domain, file, line, func, expr) \
Packit Service a1bd4f
            g_assertion_message_expr(domain,                             \
Packit Service a1bd4f
                                     file,                               \
Packit Service a1bd4f
                                     line,                               \
Packit Service a1bd4f
                                     "<unknown-fcn>",                    \
Packit Service a1bd4f
                                     (expr) ? "<dropped>" : NULL)
Packit Service a1bd4f
Packit Service a1bd4f
        #undef g_return_val_if_reached
Packit Service a1bd4f
        #define g_return_val_if_reached(val)                          \
Packit Service a1bd4f
            G_STMT_START                                              \
Packit Service a1bd4f
            {                                                         \
Packit Service a1bd4f
                g_log(G_LOG_DOMAIN,                                   \
Packit Service a1bd4f
                      G_LOG_LEVEL_CRITICAL,                           \
Packit Service a1bd4f
                      "file %s: line %d (%s): should not be reached", \
Packit Service a1bd4f
                      __FILE__,                                       \
Packit Service a1bd4f
                      __LINE__,                                       \
Packit Service a1bd4f
                      "<dropped>");                                   \
Packit Service a1bd4f
                return (val);                                         \
Packit Service a1bd4f
            }                                                         \
Packit Service a1bd4f
            G_STMT_END
Packit Service a1bd4f
Packit Service a1bd4f
        #undef g_return_if_reached
Packit Service a1bd4f
        #define g_return_if_reached()                                 \
Packit Service a1bd4f
            G_STMT_START                                              \
Packit Service a1bd4f
            {                                                         \
Packit Service a1bd4f
                g_log(G_LOG_DOMAIN,                                   \
Packit Service a1bd4f
                      G_LOG_LEVEL_CRITICAL,                           \
Packit Service a1bd4f
                      "file %s: line %d (%s): should not be reached", \
Packit Service a1bd4f
                      __FILE__,                                       \
Packit Service a1bd4f
                      __LINE__,                                       \
Packit Service a1bd4f
                      "<dropped>");                                   \
Packit Service a1bd4f
                return;                                               \
Packit Service a1bd4f
            }                                                         \
Packit Service a1bd4f
            G_STMT_END
Packit Service a1bd4f
Packit Service a1bd4f
        #define NM_ASSERT_G_RETURN_EXPR(expr) "<dropped>"
Packit Service a1bd4f
        #define NM_ASSERT_NO_MSG              1
Packit Service a1bd4f
Packit Service a1bd4f
    #else
Packit Service a1bd4f
Packit Service a1bd4f
        #define NM_ASSERT_G_RETURN_EXPR(expr) "" expr ""
Packit Service a1bd4f
        #define NM_ASSERT_NO_MSG              0
Packit Service a1bd4f
Packit Service a1bd4f
    #endif
Packit Service a1bd4f
Packit Service a1bd4f
    /*****************************************************************************/
Packit Service a1bd4f
Packit Service a1bd4f
    #include "nm-std-aux/nm-std-aux.h"
Packit Service a1bd4f
    #include "nm-std-aux/nm-std-utils.h"
Packit Service a1bd4f
    #include "nm-glib-aux/nm-macros-internal.h"
Packit Service a1bd4f
    #include "nm-glib-aux/nm-shared-utils.h"
Packit Service a1bd4f
    #include "nm-glib-aux/nm-errno.h"
Packit Service a1bd4f
    #include "nm-glib-aux/nm-hash-utils.h"
Packit Service a1bd4f
Packit Service a1bd4f
    /*****************************************************************************/
Packit Service a1bd4f
Packit Service a1bd4f
    #if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE
Packit Service a1bd4f
        #include "nm-version.h"
Packit Service a1bd4f
    #endif
Packit Service a1bd4f
Packit Service a1bd4f
    /*****************************************************************************/
Packit Service a1bd4f
Packit Service a1bd4f
    #if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
Packit Service a1bd4f
        #include "nm-core-types.h"
Packit Service a1bd4f
        #include "nm-types.h"
Packit Service a1bd4f
        #include "nm-logging.h"
Packit Service a1bd4f
    #endif
Packit Service a1bd4f
Packit Service a1bd4f
    #if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE
Packit Service a1bd4f
        #include "nm-libnm-utils.h"
Packit Service a1bd4f
    #endif
Packit Service a1bd4f
Packit Service a1bd4f
    #if ((NETWORKMANAGER_COMPILATION) &NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM) \
Packit Service a1bd4f
        && !((NETWORKMANAGER_COMPILATION)                                        \
Packit Service a1bd4f
             & (NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE                 \
Packit Service a1bd4f
                | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL))
Packit Service a1bd4f
        #include "NetworkManager.h"
Packit Service a1bd4f
    #endif
Packit 5756e2
Packit 5756e2
#endif /* NM_NETWORKMANAGER_COMPILATION_WITH_GLIB */
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
#endif /* __NM_DEFAULT_H__ */