Closed Bug 101051 Opened 25 years ago Closed 25 years ago

RFE: IDLified generic callback function type

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: akkzilla, Assigned: dougt)

Details

I shouldn't have to define a whole new type each time I write a class that needs a callback function. But there seems to be no such generic type. There's nsIObserver, but it returns strings; functions or pointers would be cleaner for most applications. Cc'ing some folks who were involved in the IRC discussion.
It would be *really* sweet if you could just pass in a JavaScript or Python function and XPConnect/PyXPCOM would Do The Right Thing.
I like objects. Callback functions are *so* '70s. How do you call a generic callback function from C++? What are the parameters? XPConnect has support for [function] interfaces. See http://lxr.mozilla.org/seamonkey/source/dom/public/idl/events/nsIDOMEventListene r.idl You can create [function] interfaces, but you need to specify specific call signatures. What is generic about that.
> It would be *really* sweet if you could just pass in a JavaScript or Python > function and XPConnect/PyXPCOM would Do The Right Thing. XPConnect *does* do the right thing. In JS functions are objects. They can have functions attached to them (now or later - by the time call time rolls around). If the caller assert that foo implements an interface then xpconnect believes the caller. BTW, I think it would really suck if people started writing and using a bunch of [function] interfaces.
why? I missing the point. what jband said. Use interfaces if you want to do something like this.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → WONTFIX
The point was not to have to define a new type for each new class that ever needs to do asynchronous notification. It bloats our source tree and our app to define all these classes that are only used once, rather than having a generic class which is general purpose and might be reusable. I just got this silly idea that reuse of classes, and bloat reduction, were good ideas. Sorry.
akkana: Show us the patch. What is the magical callback signature that can be reused so widely?
Maybe an object which has a function which takes an nsresult and a generic nsISupports? Something like this: interface nsINotification : nsISupports { void notify(nsISupports object, nsresult status); }; We probably already have such an object, buried somewhere -- I just didn't know where to look, and when I asked on IRC I got several responses agreeing that it would be useful and encouraging me to file an RFE, so I did. Turns out I no longer need this myself at the moment -- the class I was working on got folded into another set of APIs at the request of the module owners. And maybe it's too late for this because everybody's already written a bazillion different callback object classes and wouldn't think to look for the generic one. That would be a documentation issue more than anything.
You need to log in before you can comment on or make changes to this bug.