Subject: Re: [PATCH iproute2-next 3/9] dcb: app: modify dcb-app print functions for dcb-rewr reuse

From: Petr Machata <[email-masked]>
Date: Wed, 24 May 2023 11:37:21 +0200

<[email-masked]> writes:

>> Daniel Machon <[email-masked]> 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.
>
> Roger. And actually, yeah, the callbacks are used heavily throughout
> DCB, so that fits better. Will incorporate CB approach in next v. I
> think this applies more or less to your comments in patch #3, #4 and #5
> too :)

Yeah, I wasn't sure myself how much of a pain the callback approach
brings, so wanted to make sure it's not bending-backwards bad. Hence all
that prototype code :)