[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87h6s35dx9.fsf@nvidia.com>
Date: Tue, 23 May 2023 15:23:46 +0200
From: Petr Machata <petrm@...dia.com>
To: Daniel Machon <daniel.machon@...rochip.com>
CC: <netdev@...r.kernel.org>, <dsahern@...nel.org>,
<stephen@...workplumber.org>, <petrm@...dia.com>,
<UNGLinuxDriver@...rochip.com>
Subject: Re: [PATCH iproute2-next 3/9] dcb: app: modify dcb-app print
functions for dcb-rewr reuse
Daniel Machon <daniel.machon@...rochip.com> writes:
> -static void dcb_app_print_filtered(const struct dcb_app_table *tab,
> - bool (*filter)(const struct dcb_app *),
> - int (*print_key)(__u16 protocol),
> - const char *json_name,
> - const char *fp_name)
> +void dcb_app_print_filtered(const struct dcb_app_table *tab,
> + bool (*filter)(const struct dcb_app *),
> + int (*print_pid)(__u16 protocol),
> + const char *json_name, const char *fp_name)
> {
> bool first = true;
> size_t i;
> @@ -439,8 +437,14 @@ static void dcb_app_print_filtered(const struct dcb_app_table *tab,
> }
>
> open_json_array(PRINT_JSON, NULL);
> - print_key(app->protocol);
> - print_uint(PRINT_ANY, NULL, "%d ", app->priority);
> + if (tab->attr == DCB_ATTR_IEEE_APP_TABLE) {
> + print_pid(app->protocol);
> + print_uint(PRINT_ANY, NULL, ":%d", app->priority);
> + } else {
> + print_uint(PRINT_ANY, NULL, "%d:", app->priority);
> + print_pid(app->protocol);
> + }
I really dislike the attribute dispatch. I feels too much like mixing
abstraction layers. I think the callback should take a full struct
dcb_app pointer and format it as appropriate. Then you can model the
rewrite table differently from the app table by providing a callback
that invokes the print_ helpers in the correct order.
The app->protocol field as such is not really necessary IMHO, because
the function that invokes the helpers understands what kind of table it
is dealing with and could provide it as a parameter. But OK, I guess it
makes sense and probably saves some boilerplate parameterization.
> + print_string(PRINT_ANY, NULL, "%s", " ");
> close_json_array(PRINT_JSON, NULL);
> }
>
Powered by blists - more mailing lists