How do I decide whether a method-function pointer belongs in the instance structure or class structure in GObject? but in gstreamer more function pointers put into instance structure,why?
zhang007z
zhang007z at gmail.com
Sun Dec 27 18:43:27 PST 2015
in glib GObject for example:
//--------------------------------------------------------//
typedef struct _MyInstance MyInstance;
struct _MyInstance {
GObject parent;
......//instance variable
......//this place is method function pointer in instance structure.
};
typedef struct _MyInstanceClass MyInstanceClass;
struct _MyInstanceClass {
GObjectClass parent_class;
......//class variable
......//this place is method function pointer in class structure.
};
//--------------------------------------------------------//
I don't understand that the method function pointer puts in class or
instance structure that it seen to same . what difference are they? I think
that class function method pointers each of instance object is used to call
same, so puting this functions to class structure. However, How to use
instance object's function method pointers about method pointers of its own?
because I think the function method pointers of instance object for itself
is same, How to understand instance object function method? below I give
that gstreamer Gstpad.h code snippet as example :
//-------------------------------------------------------//
struct _GstPad {
GstObject object;
/*< public >*/
gpointer element_private;
GstPadTemplate *padtemplate;
GstPadDirection direction;
/*< public >*/ /* with STREAM_LOCK */
/* streaming rec_lock */
GStaticRecMutex *stream_rec_lock;
GstTask *task;
/*< public >*/ /* with PREROLL_LOCK */
GMutex *preroll_lock;
GCond *preroll_cond;
/*< public >*/ /* with LOCK */
/* block cond, mutex is from the object */
GCond *block_cond;
GstPadBlockCallback block_callback;
gpointer block_data;
/* the pad capabilities */
GstCaps *caps;
GstPadGetCapsFunction getcapsfunc;
GstPadSetCapsFunction setcapsfunc;
GstPadAcceptCapsFunction acceptcapsfunc;
GstPadFixateCapsFunction fixatecapsfunc;
GstPadActivateFunction activatefunc;
GstPadActivateModeFunction activatepushfunc;
GstPadActivateModeFunction activatepullfunc;
/* pad link */
GstPadLinkFunction linkfunc;
GstPadUnlinkFunction unlinkfunc;
GstPad *peer;
gpointer sched_private;
/* data transport functions */
GstPadChainFunction chainfunc;
GstPadCheckGetRangeFunction checkgetrangefunc;
GstPadGetRangeFunction getrangefunc;
GstPadEventFunction eventfunc;
GstActivateMode mode;
/* generic query method */
GstPadQueryTypeFunction querytypefunc;
GstPadQueryFunction queryfunc;
/* internal links */
#ifndef GST_DISABLE_DEPRECATED
GstPadIntLinkFunction intlinkfunc;
#else
#ifndef __GTK_DOC_IGNORE__
gpointer intlinkfunc;
#endif
#endif
GstPadBufferAllocFunction bufferallocfunc;
/* whether to emit signals for have-data. counts number
* of handlers attached. */
gint do_buffer_signals;
gint do_event_signals;
/* ABI added */
/* iterate internal links */
GstPadIterIntLinkFunction iterintlinkfunc;
/* free block_data */
GDestroyNotify block_destroy_data;
/*< private >*/
union {
struct {
gboolean block_callback_called;
GstPadPrivate *priv;
} ABI;
gpointer _gst_reserved[GST_PADDING - 2];
} abidata;
};
struct _GstPadClass {
GstObjectClass parent_class;
/* signal callbacks */
void (*linked) (GstPad *pad, GstPad *peer);
void (*unlinked) (GstPad *pad, GstPad *peer);
void (*request_link) (GstPad *pad);
gboolean (*have_data) (GstPad *pad, GstMiniObject *data);
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
//-------------------------------------------------------//
you can see function method pointer in instance structure and class
structure from giving above code snippet. intance function method pointers
are initialized by gst_pad_init function, as below:
//--------------------------------------------------------------------------------//
static void
gst_pad_init (GstPad * pad)
{
........//other no important code
GST_PAD_CHAINFUNC (pad) = NULL;
GST_PAD_LINKFUNC (pad) = NULL;
GST_PAD_CAPS (pad) = NULL;
GST_PAD_GETCAPSFUNC (pad) = NULL;
GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
GST_PAD_QUERYTYPEFUNC (pad) = gst_pad_get_query_types_default;
GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
#ifndef GST_REMOVE_DEPRECATED
GST_PAD_INTLINKFUNC (pad) = gst_pad_get_internal_links_default;
#endif
GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
GST_PAD_ACCEPTCAPSFUNC (pad) = gst_pad_acceptcaps_default;
............//other no important code
}
//--------------------------------------------------------------------------------//
so I confuse this issue,why there are function method pointers in intance
structure rather than puting into class class structure?
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/How-do-I-decide-whether-a-method-function-pointer-belongs-in-the-instance-structure-or-class-structu-tp4675048.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list