The function nmc_print() receives a list of "targets". These are essentially
the rows that should be printed (while the "fields" list represents the columns).
When filling the cells with values, it calles repeatedly get_fcn() on the
column descriptors (fields), by passing each row (target).
The caller must be well aware that the fields and targets are
compatible. For example, in some cases the targets are NMDevice
instances and the target type must correspond to what get_fcn()
expects.
Add another user-data pointer that is passed on along with the
targets. That is useful, if we have a list of targets/rows, but
pass in additional data that applies to all rows alike.
It is still unused.
That allows for the property list to contain derived
property types. Also, the list can be directly passed
off as a "const NMMetaAbstractInfo *const*" list.
This change (improves) behavior.
Before, we would only complete
if (g_strcmp0 (con_type, nmc_tab_completion.con_type) != 0)
which doesn't really make sense as it depends on the slave-type,
not nmc_tab_completion.con_type.
We already have
- data sources (nm_cli, connections or settings)
- meta data information how to access the data sources (NMMetaAbstractInfo,
NmcMetaGenericInfo, NMMetaPropertyInfo)
Add now a generic way to output cli data using nmc_print(). It gets a
list of data-sources (@targets) and a list of available fields (meta
data). It also gets cli configuration (NmcConfig) and field selector
strings (@field_str).
Based on that, it should output the desired data.
This is intended to replaces the previous approach, where functions like
show_nm_status() have full knowledge about how to access the data and
create an intermediate output format (NmcOutputData, NmcOutputField)
that was printed via print_data().
show_nm_status() contained both knowledge about the data itself (how to
print a value) and intimate knoweledge about the output intermediate
format. Also, the intermediate format is hard to understand. For
example, sometimes we put the field prefix in NmcOutputField at index 0
and via the NmcOfFlags we control how to output the data.
Clearly separate the responsibilities.
- The meta data (NmcMetaGenericInfo) is only concerned with converting
a data source to a string (or a color format).
- the field selection (@field_str) only cares about parsing the list
of NMMetaAbstractInfo.
- _print_fill() populates a table with output values and header
entries.
- _print_do() prints the previously prepared table.
The advantage is that if you want to change anything, you only need to
touch a particular part.
This is only a show-case for `nmcli general status`. Parts are still
un-implemented and will follow.
This changes behavior for --terse mode: the values are now no longer
translated:
$ LANG=de_DE.utf8 nmcli -t --mode multiline general
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
Embed a @meta_type structure in NMMetaSettingInfoEditor and
NMMetaPropertyInfo. This allows to make the NMMeta*Info instances
themself to become generic and they can be passed around as generic
NMMetaAbstractInfo types.
For one, the embedded NMMetaType pointer can be used to determine
of which type a NMMetaAbstractInfo instance is. On the other hand,
the NMMetaType struct can be extended to be a VTable to provide
generic access to the type.
In the end, both NMMetaSettingInfoEditor and NMMetaPropertyInfo are
conceptionally very similar: the describe a certain type and provide
accessors.
In nmcli we have yet another NMMetaAbstractInfo type: NmcOutputField
will be modified to become another implementation of meta data (it
already is, it just cannot be used interchangable with the other
types).
Also, embed the NMMetaSettingInfoEditor in the NMMetaPropertyInfo
instance. This allows from a given NMMetaPropertyInfo to retrieve it's
parent NMMetaSettingInfoEditor.
"nm-meta-setting-desc.h" contains static type description, vtable and (internal)
accessor functions. Add accessor functions that operate on top of the type description
to "nm-meta-setting-access.h".