[Spice-devel] [PATCH 4/5] tests: create and use a template file for events

Frediano Ziglio fziglio at redhat.com
Thu Dec 17 05:19:09 PST 2015


> 
> On 12/15/2015 02:15 PM, Frediano Ziglio wrote:
> > This template will be reused for main loop
> >
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> >   server/Makefile.am              |   1 +
> >   server/event_loop.tmpl.c        | 191
> >   ++++++++++++++++++++++++++++++++++++++++
> >   server/tests/basic_event_loop.c | 157 +--------------------------------
> >   3 files changed, 196 insertions(+), 153 deletions(-)
> >   create mode 100644 server/event_loop.tmpl.c
> >
> 
> > diff --git a/server/event_loop.tmpl.c b/server/event_loop.tmpl.c
> > new file mode 100644
> > index 0000000..b85e6ee
> > --- /dev/null
> > +++ b/server/event_loop.tmpl.c
> 
> > +#ifndef CORE_NAME
> > +#error  CORE_NAME must be defined!
> > +#endif
> > +
> > +#ifndef CORE_MAIN_CONTEXT
> > +#error  CORE_MAIN_CONTEXT must be defined!
> > +#endif
> > +
> > +#ifndef CORE_CHANNEL_EVENT
> > +#define CORE_CHANNEL_EVENT NULL
> > +#endif
> > +
> > +struct SpiceTimer {
> > +    SpiceTimerFunc func;
> > +    void *opaque;
> > +    GSource *source;
> > +};
> > +
> > +static SpiceTimer* CORE_NAME(timer_add)(SpiceTimerFunc func, void *opaque)
> > +{
> > +    SpiceTimer *timer = spice_malloc0(sizeof(SpiceTimer));
> > +
> > +    timer->func = func;
> > +    timer->opaque = opaque;
> > +
> > +    return timer;
> > +}
> > +
> > +static gboolean timer_func(gpointer user_data)
> 
> You probably want this to be CORE_NAME(timer_func), in case
> this file is included more than once (with different CORE_NAMES).
> 

I'm adding the missing CORE_NAME. However this template is more
intented to be included by two programs (spice-server and tests)
instead of being included more in same source.

> If it is only used once, no template is needed, just use
> a "regular" .c file and add it where appropriate in the Makefile.
> 
> Alternatively gather all those functions and put only them
> in a separate .c file (possibly with an additional .h file).
> 
> That holds for other non CORE_NAME() structs/functions.
> 
> Regards,
>      Uri.
> 
> 

I'll send another version.

Frediano


More information about the Spice-devel mailing list