[Spice-devel] [PATCH 08/12] smartcard: Turn SmartcardState into a GObject

Christophe Fergeau cfergeau at redhat.com
Fri Mar 25 13:28:54 UTC 2016


On Wed, Mar 23, 2016 at 05:38:32AM -0400, Frediano Ziglio wrote:
> > diff --git a/server/smartcard.h b/server/smartcard.h
> > index 32d2367..4b00433 100644
> > --- a/server/smartcard.h
> > +++ b/server/smartcard.h
> > @@ -1,6 +1,6 @@
> >  /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> >  /*
> > -   Copyright (C) 2010 Red Hat, Inc.
> > +   Copyright (C) 2010-2015 Red Hat, Inc.
> >  
> >     This library is free software; you can redistribute it and/or
> >     modify it under the terms of the GNU Lesser General Public
> > @@ -18,6 +18,34 @@
> >  #ifndef __SMART_CARD_H__
> >  #define __SMART_CARD_H__
> >  
> > +#include <glib-object.h>
> > +
> > +#define RED_TYPE_CHAR_DEVICE_SMARTCARD red_char_device_smartcard_get_type()
> > +
> > +#define RED_CHAR_DEVICE_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),
> > RED_TYPE_CHAR_DEVICE_SMARTCARD, RedCharDeviceSmartcard))
> > +#define RED_CHAR_DEVICE_SMARTCARD_CLASS(klass)
> > (G_TYPE_CHECK_CLASS_CAST((klass), RED_TYPE_CHAR_DEVICE_SMARTCARD,
> > RedCharDeviceSmartcardClass))
> > +#define RED_IS_CHAR_DEVICE_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),
> > RED_TYPE_CHAR_DEVICE_SMARTCARD))
> > +#define RED_IS_CHAR_DEVICE_SMARTCARD_CLASS(klass)
> > (G_TYPE_CHECK_CLASS_TYPE((klass), RED_TYPE_CHAR_DEVICE_SMARTCARD))
> > +#define RED_CHAR_DEVICE_SMARTCARD_GET_CLASS(obj)
> > (G_TYPE_INSTANCE_GET_CLASS((obj), RED_TYPE_CHAR_DEVICE_SMARTCARD,
> > RedCharDeviceSmartcardClass))
> > +
> > +typedef struct RedCharDeviceSmartcard RedCharDeviceSmartcard;
> > +typedef struct RedCharDeviceSmartcardClass RedCharDeviceSmartcardClass;
> > +typedef struct RedCharDeviceSmartcardPrivate RedCharDeviceSmartcardPrivate;
> > +
> > +struct RedCharDeviceSmartcard
> > +{
> > +    RedCharDevice parent;
> > +
> > +    RedCharDeviceSmartcardPrivate *priv;
> > +};
> > +
> > +struct RedCharDeviceSmartcardClass
> > +{
> > +    RedCharDeviceClass parent_class;
> > +};
> > +
> > +GType red_char_device_smartcard_get_type(void) G_GNUC_CONST;
> > +
> >  /*
> >   * connect to smartcard interface, used by smartcard channel
> >   */
> 
> The header was much private before. What's the point in declaring
> all these stuff in the header?

This mostly comes from the runtime type checks, when
upcasting/downcasting between base class / child class, it's preferrable
to use RED_CHAR_DEVICE_SMARTCARD to get some sanity checking that the
object you are casting is of an appropriate type. This in turn needs
red_char_device_smartcard_get_type() and the structs (with opaque
content).
You'll also need the structs there if you need to be able to inherit
from this class (unlikely in this case).
With that said, I haven't checked whether the typedef would be enough
with the struct content moved to the .c file since we don't need
inheritance.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160325/378b2e2c/attachment.sig>


More information about the Spice-devel mailing list