Callbacks in Squeak

David T. Lewis lewis at mail.msen.com
Sat Dec 15 15:31:06 UTC 2007


On Sat, Dec 15, 2007 at 03:06:28PM +0100, Conrad P?pke wrote:
> 
> I googled a little bit about callbacks and Squeak and found these links:
> http://www.nabble.com/Callbacks%2C-simplified.-tf3294768.html#a9165431 - 
> synchron callbacks
> http://www.nabble.com/Updated-callbacks-tf3294849.html#a9165690
> http://www.nabble.com/Callbacks-%28sigh-%3A-%29-tf1076074.html#a2801345 
> - someone used asynchron callbacks
> http://www.nabble.com/FFI-Callbacks-tf2200056.html#a6090814 - discussion 
> about the implementation of callbacks and a short description of how to 
> implement them
> 
> It seems that some people built in callbacks with semaphores, but I have 
> no clue how they do it.

Conrad,

The basic idea is to have the plugin signal a semaphore using
InterpreterProxy>>signalSemaphoreWithIndex:. This will refer to a
semaphore in the Squeak image that has been registered as an
"external object" with SystemDictionary>>registerExternalObject:.
You can then set up a process in the image that waits on the semaphore,
and does things whenever the plugin signals the semaphore.

This sort of callback does not send any data back to the image,
it just provides the notification mechanism to tell the image
that something must be done. Of course you have have different
semaphores corresponding to different kinds of events to be handled,
and you can have your plugin provide primitives for getting at
whatever data you might want to pass back to the image.

Sockets use this mechanism, and if you happen to have OSProcess
loaded, take a look at class AioEventHandler for an example that
does nothing more than set up the semaphore and listener process
for a specific external IO event. The corresponding plugin methods
are found in AioPlugin (on SqueakMap).

Dave




More information about the Squeak-dev mailing list