[haiku-development] Re: Signals and Slots

  • From: Clemens Zeidler <clemens.zeidler@xxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 02 Mar 2012 09:07:31 +1300

On Wed, 29 Feb 2012 10:56:59 +1300, Pete Goodeve <pete.goodeve@xxxxxxxxxxxx> wrote:



[I've pulled this out of the R1/A4 thread because it's wandered pretty
far OT, but I thought it worth one more note]

It looks as if we could get pretty adequate "Signals and Slots" in Haiku
with no changes to any kits and essentially no effort.  I've been playing
some more with sigslot.h ( http://sigslot.sourceforge.net/ ) and it's looking
pretty capable.  I suggest that anyone interested in the paradigm should
check it out. We could even put it in the distribution, as it's nothing but
a 5K public domain header!

Does these function pointer approaches support virtual inheritance? If I got it right it always points to a function of a certain base class. If thats the case this lib is only limited useful, e.q. if you have a class that is already wired and you derive this class you may have to rewire the same signal/slot or even get unexpected behaviour.

A signal and slot mechanism is more elegant and could be as powerful as BMessages but it can't be done without additional code generation via moc or something similar. I'm also against having BMessage messaging and signal/slot in parallel, both doing the same and there should only be one system for it. This system should support at least in app and inter app messaging but this is not possible with simple c++ (e.g. for inter process communication the methods arguments have to be marshaled into flat data, send to another process and be unmarshaled there, pretty much what the programmer is manually doing with BMessages at the moment)

I would not be too scared about a moc (meta object compiler) since it has some really nice side effects. For example, you almost get scripting for free; you can just signal a app and so call e.g. the GetWindowCount method without implementing any complicated scripting protocol. Furthermore, with a moc you can have introspection. This means you have detailed meta data of an object. This is e.g. useful to query an object for its scripting abilities or available methods.

Regards,
        Clemens

Other related posts: