mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 00:38:07 +02:00
cli: move NmcMetaGenericInfo to "utils.h"
This commit is contained in:
parent
bb40abb3de
commit
9276655975
11 changed files with 107 additions and 93 deletions
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "agent.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -31,7 +33,6 @@
|
|||
#include "utils.h"
|
||||
#include "nm-secret-agent-simple.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "agent.h"
|
||||
|
||||
static void
|
||||
usage (void)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -32,7 +34,6 @@
|
|||
#include "nm-vpn-helpers.h"
|
||||
#include "nm-client-utils.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern GMainLoop *loop;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "connections.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -30,16 +32,15 @@
|
|||
#include <readline/history.h>
|
||||
|
||||
#include "nm-client-utils.h"
|
||||
#include "nm-vpn-helpers.h"
|
||||
#include "nm-meta-setting-access.h"
|
||||
#include "nm-secret-agent-simple.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "common.h"
|
||||
#include "settings.h"
|
||||
#include "connections.h"
|
||||
#include "devices.h"
|
||||
#include "nm-secret-agent-simple.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "nm-vpn-helpers.h"
|
||||
#include "nm-meta-setting-access.h"
|
||||
|
||||
typedef struct _OptionInfo OptionInfo;
|
||||
struct _OptionInfo {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "devices.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -31,7 +33,6 @@
|
|||
#include "polkit-agent.h"
|
||||
#include "utils.h"
|
||||
#include "common.h"
|
||||
#include "devices.h"
|
||||
#include "connections.h"
|
||||
|
||||
/* define some prompts */
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "general.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -29,7 +31,6 @@
|
|||
#include "polkit-agent.h"
|
||||
#include "utils.h"
|
||||
#include "common.h"
|
||||
#include "general.h"
|
||||
#include "common.h"
|
||||
#include "devices.h"
|
||||
#include "connections.h"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nmcli.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -35,7 +37,6 @@
|
|||
#include "nm-client-utils.h"
|
||||
|
||||
#include "polkit-agent.h"
|
||||
#include "nmcli.h"
|
||||
#include "utils.h"
|
||||
#include "common.h"
|
||||
#include "connections.h"
|
||||
|
|
@ -55,64 +56,6 @@ NmCli nm_cli;
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
{
|
||||
return ((const NmcMetaGenericInfo *) abstract_info)->name;
|
||||
}
|
||||
|
||||
static const NMMetaAbstractInfo *const*
|
||||
_meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info;
|
||||
guint n;
|
||||
|
||||
info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
if (out_len) {
|
||||
n = 0;
|
||||
if (info->nested) {
|
||||
for (; info->nested[n]; n++) {
|
||||
}
|
||||
}
|
||||
*out_len = n;
|
||||
}
|
||||
*out_to_free = NULL;
|
||||
return (const NMMetaAbstractInfo *const*) info->nested;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *abstract_info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
nm_assert (out_to_free && !*out_to_free);
|
||||
|
||||
if (!info->get_fcn)
|
||||
g_return_val_if_reached (NULL);
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type, get_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
||||
const NMMetaType nmc_meta_type_generic_info = {
|
||||
.type_name = "nmc-generic-info",
|
||||
.get_name = _meta_type_nmc_generic_info_get_name,
|
||||
.get_nested = _meta_type_nmc_generic_info_get_nested,
|
||||
.get_fcn = _meta_type_nmc_generic_info_get_fcn,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
NmCli *nmc;
|
||||
int argc;
|
||||
|
|
|
|||
|
|
@ -113,29 +113,6 @@ extern const const NMMetaType nmc_meta_type_generic_info;
|
|||
typedef struct _NmcOutputField NmcOutputField;
|
||||
typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo;
|
||||
|
||||
struct _NmcMetaGenericInfo {
|
||||
const NMMetaType *meta_type;
|
||||
const char *name;
|
||||
const NmcMetaGenericInfo *const*nested;
|
||||
const char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free);
|
||||
};
|
||||
|
||||
#define NMC_META_GENERIC(n, ...) \
|
||||
(&((NmcMetaGenericInfo) { \
|
||||
.meta_type = &nmc_meta_type_generic_info, \
|
||||
.name = N_ (n), \
|
||||
__VA_ARGS__ \
|
||||
}))
|
||||
|
||||
#define NMC_META_GENERIC_WITH_NESTED(n, nest) \
|
||||
NMC_META_GENERIC (n, .nested = (nest))
|
||||
|
||||
struct _NmcOutputField {
|
||||
const NMMetaAbstractInfo *info;
|
||||
int width; /* Width in screen columns */
|
||||
|
|
|
|||
|
|
@ -21,13 +21,15 @@
|
|||
|
||||
#if WITH_POLKIT_AGENT
|
||||
|
||||
#include "polkit-agent.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "polkit-agent.h"
|
||||
#include "nm-polkit-listener.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static char *
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "nm-meta-setting-desc.h"
|
||||
|
||||
#include "nmcli.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -29,10 +31,69 @@
|
|||
|
||||
#include "nm-client-utils.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "common.h"
|
||||
#include "settings.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
{
|
||||
return ((const NmcMetaGenericInfo *) abstract_info)->name;
|
||||
}
|
||||
|
||||
static const NMMetaAbstractInfo *const*
|
||||
_meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info;
|
||||
guint n;
|
||||
|
||||
info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
if (out_len) {
|
||||
n = 0;
|
||||
if (info->nested) {
|
||||
for (; info->nested[n]; n++) {
|
||||
}
|
||||
}
|
||||
*out_len = n;
|
||||
}
|
||||
*out_to_free = NULL;
|
||||
return (const NMMetaAbstractInfo *const*) info->nested;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *abstract_info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
nm_assert (out_to_free && !*out_to_free);
|
||||
|
||||
if (!info->get_fcn)
|
||||
g_return_val_if_reached (NULL);
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type, get_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
||||
const NMMetaType nmc_meta_type_generic_info = {
|
||||
.type_name = "nmc-generic-info",
|
||||
.get_name = _meta_type_nmc_generic_info_get_name,
|
||||
.get_nested = _meta_type_nmc_generic_info_get_nested,
|
||||
.get_fcn = _meta_type_nmc_generic_info_get_fcn,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
parse_global_arg (NmCli *nmc, const char *arg)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -98,4 +98,31 @@ void print_data (const NmcConfig *nmc_config,
|
|||
int indent,
|
||||
const NmcOutputData *out);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NmcMetaGenericInfo {
|
||||
const NMMetaType *meta_type;
|
||||
const char *name;
|
||||
const NmcMetaGenericInfo *const*nested;
|
||||
const char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free);
|
||||
};
|
||||
|
||||
#define NMC_META_GENERIC(n, ...) \
|
||||
(&((NmcMetaGenericInfo) { \
|
||||
.meta_type = &nmc_meta_type_generic_info, \
|
||||
.name = N_ (n), \
|
||||
__VA_ARGS__ \
|
||||
}))
|
||||
|
||||
#define NMC_META_GENERIC_WITH_NESTED(n, nest) \
|
||||
NMC_META_GENERIC (n, .nested = (nest))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* NMC_UTILS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue