Re: [PATCH spice-server v2 1/2] Introduce some macros to help declaring new GObject

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

 



> 
> On Wed, Sep 06, 2017 at 03:42:29PM +0100, Frediano Ziglio wrote:
> > The macros will implement most of the boilerplate needed
> > to declare an object.
> > Their usage are similar to GLib G_DECLARE_*_TYPE macros.
> 
> Can we/should we use the GLib provided macros when they are available,
> and copy/paste the GLib implementation in a -compat.h header for older
> systems. The GLib macros were introduced in GLib 2.43.4
> 
> Christophe
> 

That's fine. But our objects are currently neither final neither interfaces
so we can't use any of them.
I changed the field names and fields order to better match GLib versions.

Frediano

> > 
> > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> > ---
> > Changes since v1:
> > - use SPICE_ prefix instead of GOBJECT_;
> > - if RED_ prefix is used use this prefix for all GLib
> >   macros.
> > ---
> >  server/red-common.h | 60
> >  +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 60 insertions(+)
> > 
> > diff --git a/server/red-common.h b/server/red-common.h
> > index 9ff1fd9b5..19bb3fb6e 100644
> > --- a/server/red-common.h
> > +++ b/server/red-common.h
> > @@ -93,4 +93,64 @@ typedef struct GListIter {
> >  #define GLIST_FOREACH_REVERSED(_list, _type, _data) \
> >      GLIST_FOREACH_GENERIC(_list, G_PASTE(_iter_, __LINE__), _type, _data,
> >      prev)
> >  
> > +#define SPICE_DECLARE_TYPE_GENERIC(ModuleObjType, ModuleObjName,
> > module_obj_name, MODULE, OBJ_NAME) \
> > +    typedef ModuleObjType ModuleObjName; \
> > +    typedef struct ModuleObjName ## Class ModuleObjName ## Class; \
> > +    typedef struct ModuleObjName ## Private ModuleObjName ## Private; \
> > +    GType module_obj_name ## _get_type(void) G_GNUC_CONST; \
> > +    static inline ModuleObjName *G_PASTE(MODULE,OBJ_NAME)(void *obj) \
> > +    { return G_TYPE_CHECK_INSTANCE_CAST(obj, \
> > +             module_obj_name ## _get_type(), ModuleObjName); } \
> > +    static inline ModuleObjName ## Class
> > *G_PASTE(G_PASTE(MODULE,OBJ_NAME),_CLASS)(void *klass) \
> > +    { return G_TYPE_CHECK_CLASS_CAST(klass, \
> > +             module_obj_name ## _get_type(), ModuleObjName ## Class); } \
> > +    static inline gboolean G_PASTE(G_PASTE(MODULE,IS_),OBJ_NAME)(void
> > *obj) \
> > +    { return G_TYPE_CHECK_INSTANCE_TYPE(obj, module_obj_name ##
> > _get_type()); } \
> > +    static inline gboolean
> > G_PASTE(G_PASTE(G_PASTE(MODULE,IS_),OBJ_NAME),_CLASS)(void *klass) \
> > +    { return G_TYPE_CHECK_CLASS_TYPE((klass), module_obj_name ##
> > _get_type()); } \
> > +    static inline ModuleObjName ## Class
> > *G_PASTE(G_PASTE(MODULE,OBJ_NAME),_GET_CLASS)(void *obj) \
> > +    { return G_TYPE_INSTANCE_GET_CLASS(obj, \
> > +             module_obj_name ## _get_type(), ModuleObjName ## Class); }
> > +
> > +#define SPICE_DECLARE_EMPTY_MODULE
> > +
> > +/* Helper to declare a GObject type
> > + *
> > + * @ModuleObjType     used to specify the structure type in case is not
> > + *                    the same as the @ModuleObjName. For instance can be
> > + *                    "struct MyObjectDefinition"
> > + * @ModuleObjName     type identifier like MyObject
> > + * @module_obj_name   method prefix like my_object (no need to add the
> > + *                    underscore)
> > + * @OBJ_NAME          macro common part like MY_OBJECT
> > + */
> > +#define SPICE_DECLARE_TYPE_STRUCT(ModuleObjType, ModuleObjName,
> > module_obj_name, OBJ_NAME) \
> > +    SPICE_DECLARE_TYPE_GENERIC(ModuleObjType, ModuleObjName,
> > module_obj_name, \
> > +                                 SPICE_DECLARE_EMPTY_MODULE, OBJ_NAME)
> > +
> > +/* Helper to declare a GObject type
> > + *
> > + * Same as SPICE_DECLARE_TYPE_STRUCT but the macro names
> > + * will have the "RED_" prefix.
> > + */
> > +#define SPICE_DECLARE_RED_TYPE_STRUCT(ModuleObjType, ModuleObjName,
> > module_obj_name, OBJ_NAME) \
> > +    SPICE_DECLARE_TYPE_GENERIC(ModuleObjType, ModuleObjName,
> > module_obj_name, RED_, OBJ_NAME)
> > +
> > +/* Helper to declare a GObject type
> > + *
> > + * Same as SPICE_DECLARE_TYPE_STRUCT but the structure is the same
> > + * as the type, most declarations use this convention.
> > + */
> > +#define SPICE_DECLARE_TYPE(ModuleObjName, module_obj_name, OBJ_NAME) \
> > +    SPICE_DECLARE_TYPE_GENERIC(struct ModuleObjName, ModuleObjName,
> > module_obj_name, \
> > +                                 SPICE_DECLARE_EMPTY_MODULE, OBJ_NAME)
> > +
> > +/* Helper to declare a GObject type
> > + *
> > + * Same as SPICE_DECLARE_TYPE but the macro names
> > + * will have the "RED_" prefix.
> > + */
> > +#define SPICE_DECLARE_RED_TYPE(ModuleObjName, module_obj_name, OBJ_NAME) \
> > +    SPICE_DECLARE_TYPE_GENERIC(struct ModuleObjName, ModuleObjName,
> > module_obj_name, RED_, OBJ_NAME)
> > +
> >  #endif /* RED_COMMON_H_ */
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]