theLink 10.0
|
List of all callback defined by atlmqmsgque
The callback is a regular ATL proc that either stands alone or is part of a class.
The callback is a list: [list ?class::?callback ?instance? args...]
, with automatic callback-name resolution occurs in the following order:
If automatic resolution does NOT produce the desired result, the callback can of course always be specified with the absolute-namespace.
ATL also allows additional parameters to be passed to the callback, for example, to support a specific implementation. These parameters are added at the end of the callback-call.
Example: The instance-callback with two default-arguments (arg1
and arg2
), defined as:
define-callback-command [list callback instance add1 add2 add3]
results in the following callback call:
::class::callback instance arg1 arg2 add1 add2 add3
Example about the delete-callback-setup from the RPC server example/atl/LibSq3LiteRpcServer.atl
ServerSetup : The DeleteCallback is usually installed in the Setup-Callback but only once.
if {[ConfigGetIsParent $myNs ]} { MkObjectC::DeleteCallbackSetup "LibSq3LiteRpcServer" [list ObjectDeleteCall $myNs] "^Sq3" }
The DeleteCallback is called before the deletion. In the RPC example, the RPC client is informed about the impending deletion.
proc LibSq3LiteRpcServer::ObjectDeleteCall { myNs typeName typeHdl objHdl } { Send $myNs "E" "%DEL:CHH" $typeName $typeHdl $objHdl }
ServerCleanup : If the RPC server is deleted, the DeleteCallback is no longer needed and is therefore also deleted.
if {[ConfigGetIsParent $myNs ]} { MkObjectC::DeleteCallbackCleanup "LibSq3LiteRpcServer" }
There a two different types of callback:
There are 4 different types of callback :
type | code | self argument |
---|---|---|
procedure | ... proc | yes |
class-method | ... ?CLASS?::callback | yes |
instance-method of own class | ... callback | no |
instance-method of other class | ... CLASS::callback INSTANCE | yes |
Example from Callback.atl
→ using MqServiceCreate with callback
package require atlmqmsgque # General rules for defining a callback in ATL # -------------------------------------------- # 1. A callback always begins with the "Method" follwed by the "instanceObject" if required. # 2. If the callback is an "instanceMethod" of another instance, the callback is defined as: # `[list ::CLASS::instanceMethod instanceObject]` # 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: # `::CLASS::classMethod` # attention, the "::OtherServerC" has no "::MqContextC" as "base-class" and require the "MqContextC::" prefix. myooX::ClassN ::OtherServerC { proc OtherServerC {otherNs wht} { namespace upvar $otherNs my my set my(wht) $wht } # The "otherInstanceService" require an extra argument, the "cbNs". proc otherInstanceService {otherNs cbNs} { namespace upvar $otherNs my my MqContextC::Send $cbNs "R" "C" "[MqContextC::ReadSTR $cbNs]-$my(wht)-Other-Instance" } # The "otherClassService" require an extra argument, the "cbNs". proc otherClassService {cbNs} { MqContextC::Send $cbNs "R" "C" "[MqContextC::ReadSTR $cbNs]-World-Other-Class" } } # The "procService" require an extra argument, the "cbNs". proc procService {cbNs} { MqContextC::Send $cbNs "R" "C" "[MqContextC::ReadSTR $cbNs]-World-Proc" } # package-item myooX::ClassN ::CallbackC { SuperI ::MqContextC # The "ownInstanceService" require no extra argument. proc ownInstanceService {cbNs} { Send $cbNs "R" "C" "[ReadSTR $cbNs]-World-Own-Instance" } # The "ownClassService" require an extra argument, the "cbNs". proc ownClassService {cbNs} { Send $cbNs "R" "C" "[ReadSTR $cbNs]-World-Own-Class" } # the "serverSetup" defines the test-services proc serverSetup {cbNs} { namespace upvar $cbNs my my # 1. The "otherInstanceCallback" require an extra argument, the "otherNs". # -> remember: use the *absolute-namespace* for the callback ServiceCreate $cbNs "HLW1" [list OtherServerC::otherInstanceService $my(otherNs)] # 2. The "otherClassCallback" require no extra argument. # -> remember: use the *absolute-namespace* for the callback ServiceCreate $cbNs "HLW2" OtherServerC::otherClassService # 3. The "ownInstanceCallback" require no extra argument. ServiceCreate $cbNs "HLW3" ownInstanceService # 4. The "ownClassCallback" require no extra argument. ServiceCreate $cbNs "HLW4" ownClassService # 5. The "procCallback" require NO extra argument ServiceCreate $cbNs "HLW5" procService } # factory startup (constructor) proc CallbackC {cbNs {tmpl ""}} { namespace upvar $cbNs my my MqContextC $cbNs $tmpl ConfigSetServerSetup $cbNs serverSetup set my(otherNs) [myooX::NewN ::OtherServerC "World"] ; # just for test purpose } proc ~CallbackC {cbNs} { namespace upvar $cbNs my my DestroyN $my(otherNs) } } # package-main MqMsgque::Main { # setup commandline arguments for later use set args [MkBufferListC::CreateLA {*}$argv] # create "Callback" factory... and make it to the default. set fct [MqFactoryC::Default [MqFactoryC::Add ::CallbackC]] # inspect commandline-argument for the "factory" to choose... and create a object set fct [MqFactoryC::GetCalledL $args] set srv [MqFactoryC::New $fct] try { MqContextC::LinkCreate $srv $args MqContextC::ProcessEvent $srv MQ_WAIT_FOREVER } on error {} { MqContextC::ErrorCatch $srv } finally { MqContextC::Exit $srv } }