theLink 10.0
|
List of all callback defined by tclmqmsgque
The callback have to be a Tcl proc or method …
There a two different types of callback:
There are 4 different types of callback :
type | code | self argument |
---|---|---|
procedure | ... proc-callback | yes |
class-method | ... [list CLASS callback] | yes |
instance-method of own class | ... callback | no |
instance-method of other class | ... [list INSTANCE callback] | yes |
Example from Callback.tcl
→ using MqServiceCreate with callback
package require tclmqmsgque namespace import tclmqmsgque::* namespace import tclmkkernel::* # General rules for defining a callback in TCL # -------------------------------------------- # 1. A callback always begins with the "Object" argument, either the "instanceObject" or the "classObject". # 2. If the callback is an "instanceMethod" of another instance, the callback is defined as: # `[list instanceObject instanceMethod]` # 3. If the callback is an "instanceMethod" of its own instance, the callback is defined as: # `instanceMethod` # 4. If the callback is a "classMethod," the callback is defined as: # `[list classObject classMethod]` oo::class create OtherServerC { variable wht constructor {_wht} { set wht $_wht } # The "otherInstanceService" require an extra argument, the "cbCtx". method otherInstanceService {cbCtx} { $cbCtx Send "R" "C" "[$cbCtx ReadSTR]-$wht-Other-Instance" } # The "otherClassService" require an extra argument, the "cbCtx". self method otherClassService {cbCtx} { $cbCtx Send "R" "C" "[$cbCtx ReadSTR]-World-Other-Class" } } # The "procService" require an extra argument, the "cbCtx". proc procService {cbCtx} { $cbCtx Send "R" "C" "[$cbCtx ReadSTR]-World-Proc" } # package-item oo::class create CallbackC { superclass MqContextC # The "ownInstanceService" require no extra argument. method ownInstanceService {} { my Send "R" "C" "[my ReadSTR]-World-Own-Instance" } # The "ownClassService" require an extra argument, the "cbCtx". self method ownClassService {cbCtx} { $cbCtx Send "R" "C" "[$cbCtx ReadSTR]-World-Own-Class" } # the "serverSetup" defines the test-services method serverSetup {} { # 1. The "otherInstanceCallback" require an extra argument, the "otherCtx". my ServiceCreate "HLW1" [list otherCtx otherInstanceService] # 2. The "otherClassCallback" require NO extra argument. my ServiceCreate "HLW2" [list OtherServerC otherClassService] # 3. The "ownInstanceCallback" require no extra argument. my ServiceCreate "HLW3" ownInstanceService # 4. The "otherClassCallback" require NO extra argument. my ServiceCreate "HLW4" [list CallbackC ownClassService] # 5. The "procCallback" require NO extra argument my ServiceCreate "HLW5" procService } # factory startup (constructor) constructor {{tmpl ""}} { next $tmpl my ConfigSetServerSetup serverSetup OtherServerC create otherCtx "World" ; # just for test purpose } } # package-main tclmqmsgque::Main { # setup commandline arguments for later use set args [MkBufferListC CreateLA {*}$argv] # create "Callback" factory... and make it to the default. set fct [[MqFactoryC Add CallbackC] Default] # inspect commandline-argument for the "factory" to choose... and create a object set fct [MqFactoryC GetCalledL $args] set srv [$fct New] try { $srv LinkCreate $args $srv ProcessEvent MQ_WAIT_FOREVER } on error {} { $srv ErrorCatch } finally { $srv Exit } }