qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V4 1/7] CAN bus simple messages transport implem


From: Pavel Pisa
Subject: Re: [Qemu-devel] [PATCH V4 1/7] CAN bus simple messages transport implementation for QEMU
Date: Fri, 19 Jan 2018 14:28:05 +0100
User-agent: KMail/1.9.10 (enterprise35 0.20100827.1168748)

Hello Philippe,

On Friday 19 of January 2018 13:38:11 Philippe Mathieu-Daudé wrote:
> On 01/14/2018 05:14 PM, address@hidden wrote:
> > From: Pavel Pisa <address@hidden>
> >
> > +extern int (*can_bus_connect_to_host_variant)(CanBusState *bus,
> > +                                              const char *name);
>
> Isn't extern (*func) an anti-pattern?
> One might be tempted to call it without checking it is non-NULL...
>
> Please declare it as a function, and using a static pointer, i.e.:
>
> typedef int (*can_bus_connect_to_host_variant_t)(CanBusState *bus,
>                                        const char *name);
>
>
> static can_bus_connect_to_host_variant_t
> can_bus_connect_to_host_variant_handler;
>
> void
> set_can_bus_connect_to_host_variant(can_bus_connect_to_host_variant_t
> handler)
> {
>     can_bus_connect_to_host_variant_handler = handler;
> }
>
> int can_bus_connect_to_host_variant(CanBusState *bus,
>                           const char *name)
> {
>     if (!can_bus_connect_to_host_variant_handler) {
>         return ERROR;
>     }
>     return can_bus_connect_to_host_variant_handler(bus, name);
> }


Yes, that has been my initial idea but then I need
some way how to setup variant from can_socketcan.c
when it is linked in

Something like

static void __attribute__((constructor)) can_socketcan_setup_variant(void)
{

}

or

module_init()

or

in can_socketcan.c or have there some QOM object which
type initialization setups pointer early before
individual instances of kvaser_pci

Thanks for suggestion in advance,

Pavel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]