libnm: use macros function arguments for NMSettInfoPropertType

These functions tend to have many arguments. They are also quite som
boilerplate to implement the hundereds of properties we have, while
we want that properties have common behaviors and similarities.

Instead of repeatedly spelling out the function arguments, use a macro.

Advantages:

- the usage of a _NM_SETT_INFO_PROP_*_FCN_ARGS  macro signals that this
  is an implementation of a property. You can now grep for these macros
  to find all implementation. That was previously rather imprecise, you
  could only `git grep '\.to_dbus_fcn'` to find the uses, but not the
  implementations.
  As the goal is to keep properties "similar", there is a desire to
  reduce the number of similar implementations and to find them.

- changing the arguments now no longer will require you to go through
  all implementations. At least not, if you merely add an argument that
  has a reasonable default behavior and does not require explicit
  handling by most implementation.

- it's convenient to be able to patch the argument list to let the
  compiler help to reason about something. For example, the
  "connection_dict" argument to from_dbus_fcn() is usually unused.
  If you'd like to find who uses it, rename the parameter, and
  review the (few) compiler errors.

- it does save 573 LOC of boilerplate with no actual logic or useful
  information. I argue, that this simplifies the code and review, by
  increasing the relative amount of actually meaningful code.

Disadvantages:

- the user no longer directly sees the argument list. They would need
  cscope/ctags or an IDE to jump to the macro definition and conveniently
  see all arguments.

Also use _nm_nil, so that clang-format interprets this as a function
parameter list. Otherwise, it formats the function differently.
This commit is contained in:
Thomas Haller
2021-07-26 23:45:31 +02:00
parent 2f5543b3ed
commit 77421ba1be
27 changed files with 152 additions and 724 deletions

View File

@@ -38,7 +38,7 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict;
extern const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address;
void _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value);
void _nm_utils_strdict_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil);
void _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value);
@@ -58,14 +58,10 @@ gboolean _nm_utils_bridge_vlan_verify_list(GPtrArray * vlans,
NMTernary _nm_utils_bridge_compare_vlans(GPtrArray *vlans_a, GPtrArray *vlans_b);
GVariant *_nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
GVariant *_nm_team_settings_property_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil);
void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value);
void _nm_team_settings_property_from_dbus_link_watchers(
_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil);
GVariant *_nm_utils_ip4_dns_to_variant(const char *const *dns, gssize len);
GVariant *_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len);