eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ExternalFunctionCallback':

Home

everywhere
www.exept.de
for:
[back]

Class: ExternalFunctionCallback


Inheritance:

   Object
   |
   +--ExecutableFunction
      |
      +--ExternalFunction
         |
         +--ExternalFunctionCallback

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.15 date: 2009/11/05 16:25:17
user: stefan
file: ExternalFunctionCallback.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


an ExternalFunctionCallback wraps a block into a C-callable function;
i.e. it creates a closure, which as seen from C-code looks like an ordinary
function pointer, but when invoked evaluates a smalltalk block.

A callback is created with:
   cb := ExternalFunctionCallback new.
the arguments (as passed from the C-caller into ST)
and the returnValue (from ST to the C-caller) are specified with:
   cb returnType:#bool argumentTypes:#(uint).
Then, the code is generated with:
   cb generateClosure.

After that, the callBack-functions address can be aquired with:
   cb address.  'can be passed to C'.
and handed out to C. (you can also hand out the callBack directly - as it is a subclass of
ExternalBytes.
The actual action of the callback can be changed (at any time later) with:
    cb action:[:args | Transcript showCR:args. true].

Eventually, the callback MUST be released:
    cb release.


Class protocol:

common callbacks
o  callbackFor: aBlock returnType: returnType argumentTypes: argumentTypes
generate a callback for the ErrorCallbackProc signature:
ErrorCallbackProc(HWND hWnd, int nErrID, LPTSTR lpErrorText)
which, can be given to an external API call and which invokes the
three arg block when clled.
Do not forget to eventually release the callback to avoid a memory leak.

o  errorCallbackProcFor: aThreeArgBlock
generate a callback for the ErrorCallbackProc signature:
ErrorCallbackProc(HWND hWnd, int nErrID, LPTSTR lpErrorText)
which, can be given to an external API call and which invokes the
three arg block when clled.
Do not forget to eventually release the callback to avoid a memory leak.

constants
o  callTypeAPI

o  callTypeC

o  callTypeCDecl

o  callTypeMASK

o  callTypeOLE

helpers
o  closureIndexFor: aCallBack

o  testCall: aCallback withArgument: arg
a simple test, if I can be called

o  testCall: aCallback withArguments: args
a simple test, if I can be called


Instance protocol:

accessing
o  action: aBlock
set the action-block, to be evaluated when C calls me.
The C-arguments will be passed as arguments to the block.
The value returned by the block will be returned to the C-caller.

o  beCallTypeAPI

o  beCallTypeC

o  beCallTypeOLE

o  beCallTypeWINAPI

o  callTypeNumber

o  isCallTypeAPI

o  isCallTypeC

o  isCallTypeOLE

callback
o  callFromCWith: argList
invoked by the C-code, to which we have given out the code-ptr.
Because this is evaluated from C, we probably should not block or abort or do
any other things which confuse C
(its probably a good idea to write something into a queue here)

generation
o  code

private-accessing
o  returnType: aReturnType argumentTypes: argTypes
see generateClosure for valid return types

private-generation
o  generateClosure

private-releasing
o  release


Examples:


|cb| cb := ExternalFunctionCallback new. cb returnType:#bool argumentTypes:#(uint). cb beCallTypeWINAPI. cb generateClosure. cb action:[:args | Transcript showCR:args. true]. cb code. 'can be passed to C'. ExternalFunctionCallback testCall:cb withArgument:123. cb action:[:args | Transcript show:'hello '; showCR:args. true]. ExternalFunctionCallback testCall:cb withArgument:123. cb release

ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 09:06:51 GMT