diff options
author | Thomas Haller <thaller@redhat.com> | 2021-02-03 15:25:56 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-02-04 09:45:55 +0100 |
commit | ac1a9e03e4d6674e1e60529b47b325a8f62e67b3 (patch) | |
tree | ef0445da3fd804e6cc5ee1e9c48a352dd348df1f /src/devices/bluetooth/tests/nm-bt-test.c | |
parent | 97ed143e04e74323a59a0f24a965d36341233670 (diff) | |
download | NetworkManager-ac1a9e03e4d6674e1e60529b47b325a8f62e67b3.tar.gz |
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.
Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.
We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.
As the name "src/" is already taken, that prevents any sensible
restructuring of the code.
As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".
For inspiration, look at systemd's "src/" directory.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
Diffstat (limited to 'src/devices/bluetooth/tests/nm-bt-test.c')
-rw-r--r-- | src/devices/bluetooth/tests/nm-bt-test.c | 223 |
1 files changed, 0 insertions, 223 deletions
diff --git a/src/devices/bluetooth/tests/nm-bt-test.c b/src/devices/bluetooth/tests/nm-bt-test.c deleted file mode 100644 index 546c06a77e..0000000000 --- a/src/devices/bluetooth/tests/nm-bt-test.c +++ /dev/null @@ -1,223 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#include "nm-default.h" - -#include <glib-unix.h> - -#include "devices/bluetooth/nm-bluez5-dun.h" - -#include "nm-test-utils-core.h" - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_BT -#define _NMLOG(level, ...) \ - nm_log((level), \ - _NMLOG_DOMAIN, \ - NULL, \ - NULL, \ - "bt%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - NM_PRINT_FMT_QUOTED(gl.argv_cmd, "[", gl.argv_cmd, "]", "") \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)) - -/*****************************************************************************/ - -struct { - int argc; - const char *const *argv; - const char * argv_cmd; - GMainLoop * loop; -} gl; - -typedef struct _MainCmdInfo { - const char *name; - int (*main_func)(const struct _MainCmdInfo *main_cmd_info); -} MainCmdInfo; - -/*****************************************************************************/ - -#if WITH_BLUEZ5_DUN - -typedef struct { - NMBluez5DunContext *dun_context; - GCancellable * cancellable; - guint timeout_id; - guint sig_term_id; - guint sig_int_id; -} DunConnectData; - -static void -_dun_connect_cb(NMBluez5DunContext *context, - const char * rfcomm_dev, - GError * error, - gpointer user_data) -{ - DunConnectData *dun_connect_data = user_data; - - g_assert(dun_connect_data); - g_assert(!dun_connect_data->dun_context); - g_assert((!!error) != (!!rfcomm_dev)); - - if (rfcomm_dev && !context) { - _LOGI("dun-connect notifies path \"%s\". Wait longer...", rfcomm_dev); - return; - } - - if (rfcomm_dev) { - g_assert(context); - _LOGI("dun-connect completed with path \"%s\"", rfcomm_dev); - } else { - g_assert(!context); - _LOGI("dun-connect failed with error: %s", error->message); - } - - dun_connect_data->dun_context = context; - - g_main_loop_quit(gl.loop); -} - -static void -_dun_notify_tty_hangup_cb(NMBluez5DunContext *context, gpointer user_data) -{ - _LOGI("dun-connect: notified TTY hangup"); -} - -static gboolean -_timeout_cb(gpointer user_data) -{ - DunConnectData *dun_connect_data = user_data; - - _LOGI("timeout"); - dun_connect_data->timeout_id = 0; - if (dun_connect_data->cancellable) - g_cancellable_cancel(dun_connect_data->cancellable); - return G_SOURCE_REMOVE; -} - -static gboolean -_sig_xxx_cb(DunConnectData *dun_connect_data, int sigid) -{ - _LOGI("signal %s received", sigid == SIGTERM ? "SIGTERM" : "SIGINT"); - g_main_loop_quit(gl.loop); - return G_SOURCE_CONTINUE; -} - -static gboolean -_sig_term_cb(gpointer user_data) -{ - return _sig_xxx_cb(user_data, SIGTERM); -} - -static gboolean -_sig_int_cb(gpointer user_data) -{ - return _sig_xxx_cb(user_data, SIGINT); -} -#endif - -static int -do_dun_connect(const MainCmdInfo *main_cmd_info) -{ -#if WITH_BLUEZ5_DUN - gs_unref_object GCancellable *cancellable = NULL; - gs_free_error GError *error = NULL; - const char * adapter; - const char * remote; - DunConnectData dun_connect_data = {}; - - if (gl.argc < 4) { - _LOGE("missing arguments \"adapter\" and \"remote\""); - return -1; - } - - adapter = gl.argv[2]; - remote = gl.argv[3]; - - cancellable = g_cancellable_new(); - dun_connect_data.cancellable = cancellable; - - if (!nm_bluez5_dun_connect(adapter, - remote, - cancellable, - _dun_connect_cb, - &dun_connect_data, - _dun_notify_tty_hangup_cb, - &dun_connect_data, - &error)) { - _LOGE("connect failed to start: %s", error->message); - return -1; - } - - dun_connect_data.timeout_id = g_timeout_add(60000, _timeout_cb, &dun_connect_data); - - g_main_loop_run(gl.loop); - - nm_clear_g_source(&dun_connect_data.timeout_id); - - if (dun_connect_data.dun_context) { - dun_connect_data.sig_term_id = g_unix_signal_add(SIGTERM, _sig_term_cb, &dun_connect_data); - dun_connect_data.sig_int_id = g_unix_signal_add(SIGINT, _sig_int_cb, &dun_connect_data); - - g_main_loop_run(gl.loop); - - nm_clear_g_source(&dun_connect_data.sig_term_id); - nm_clear_g_source(&dun_connect_data.sig_int_id); - - nm_bluez5_dun_disconnect(g_steal_pointer(&dun_connect_data.dun_context)); - } - - return 0; -#else - _LOGE("compiled without bluetooth DUN support"); - return 1; -#endif -} - -/*****************************************************************************/ - -NMTST_DEFINE(); - -int -main(int argc, char **argv) -{ - static const MainCmdInfo main_cmd_infos[] = { - { - .name = "dun-connect", - .main_func = do_dun_connect, - }, - }; - int exit_code = 0; - guint i; - - if (!g_getenv("G_MESSAGES_DEBUG")) - g_setenv("G_MESSAGES_DEBUG", "all", TRUE); - - nmtst_init_with_logging(&argc, &argv, "DEBUG", "ALL"); - - nm_logging_init(NULL, TRUE); - - gl.argv = (const char *const *) argv; - gl.argc = argc; - gl.loop = g_main_loop_new(NULL, FALSE); - - _LOGI("bluetooth test util start"); - - gl.argv_cmd = argc >= 2 ? argv[1] : NULL; - - for (i = 0; i < G_N_ELEMENTS(main_cmd_infos); i++) { - if (nm_streq0(main_cmd_infos[i].name, gl.argv_cmd)) { - _LOGD("start \"%s\"", gl.argv_cmd); - exit_code = main_cmd_infos[i].main_func(&main_cmd_infos[i]); - _LOGD("completed with %d", exit_code); - break; - } - } - if (gl.argv_cmd && i >= G_N_ELEMENTS(main_cmd_infos)) { - nm_log_err(LOGD_BT, "invalid command \"%s\"", gl.argv_cmd); - exit_code = -1; - } - - nm_clear_pointer(&gl.loop, g_main_loop_unref); - - return exit_code; -} |