[gst-devel] GstInterface

David Schleef ds at schleef.org
Tue Oct 14 16:32:06 CEST 2003


On Wed, Oct 15, 2003 at 12:24:34AM +0200, Ronald Bultje wrote:
> On Tue, 2003-10-14 at 21:34, David Schleef wrote:
> > And why go to all this trouble instead of putting a supported()
> > method in the interfaces that require it?  Seems like a lot of
> > extra code.
> 
> I've explained this in Barcelona: it's duplication of code. We need to
> define the virtual function supported for each interface that requires
> it. The function for each supported function is the same. So why not
> generalize it?

Contrariwise, why generalize it?  You added 248 lines of code to the
core, and a new interface to each class that uses it.  The alternative,
unless I am really not understanding something, is approximately one
line of code in each interface header file, and 5 lines of code in
each interface that uses it.

Moreover, having this code in each interface makes it easier to
understand.  GstInterface isn't.

> That's what this is for! Besides, I want to automate this
> supported()-checking during the cast, and then a generic macro is
> useful. The lot of extra code will end up in the specific interfaces
> then.

I don't like this.  You are overriding and changing the meaning
of GInterface.  It may be a cute trick, but I have yet to see
any problems it actually solves.

Perhaps I'm really not getting it, but you want to change the API an
application uses to get a "sometimes" interface from an object from:

  foo = GST_FOO(some_object);
  if (!gst_foo_supported(foo)) {
    return;
  }

to

  foo = GST_FOO(some_object);
  if (!foo) {
    return;
  }
  
with proper magic in the definition of GST_FOO().  Or perhaps:

  supported = GST_INTERFACE(some_object);
  if(!gst_interface_supported(supported, GST_TYPE_FOO)){
    return;
  }
  foo = GST_FOO(some_object);

In the second case, you have a macro that mostly acts like a
casting macro, but in certain cases, it will return NULL.  This is
unlike anything else in the GObject model.

In the third case, you have more code, and expect the app developer
to comprehend GstInterface, and its relation to other interfaces,
in addition to anything else.

I think I'm the only one that has spent the time trying to figure
out what you're doing.  In my opinion, you are _way_ overengineering
this, in an inappropriate way and place.  The appropriate place for
doing something like this is in glib, and it is probably best done
as a special kind of GInterface, not as a subclass.

Note that in my first code snippet above, the only documentation
necessary is:

  "All gst_foo_* functions must be proceeded by a call to
  gst_foo_supported(), to make sure that the object instance
  actually handles the GstFoo interface."

This is _simple_.

Again, I may be completely missing the boat.  If so, let me know.



dave...





More information about the gstreamer-devel mailing list