theKernel 10.0
|
List of all callback defined by csmkkernel
The callback have to be a class-method …
The callback is a class-method :
Read more about how to define a service-callback in theLink .
Example about the delete-callback-setup from the RPC server example/cs/LibSq3LiteRpcServer.cs
ServerSetup : The DeleteCallback is usually installed in the Setup-Callback but only once.
// *only* the initial (Parent) service get a 'DeleteCallback' if (ConfigGetIsParent()) { // all objects that start with the regular expression "^Sq3" as "TypeName" (MkTypeS::type_name) are sent to // the callback "RpcObjectDeleteCall" MkObjectC.DeleteCallbackSetup("LibSq3LiteRpcServer", RpcObjectDeleteCall,"^Sq3"); }
The DeleteCallback is called before the deletion. In the RPC example, the RPC client is informed about the impending deletion.
private void RpcObjectDeleteCall ( String typeName, int typeHdl, int objHdl ) { // example for rpc: send "typName", "typHdl" and "objHdl" to rpc-client Send("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()) { MkObjectC.DeleteCallbackCleanup("LibSq3LiteRpcServer"); }
Example about the delete-callback-setup from the RPC client example/tcl/LibSq3LiteRpcClient.tcl
Constructor: Add the DeleteCallback-Service if not already available :
oo::define Sq3LiteRpc constructor { rpcHdl args} { next $rpcHdl {*}$args # only use "DeleteCallback" on the initial (Parent) context set parentRpc [$rpcHdl LinkGetParent] # add service "%DEL" as static-callback "Sq3LiteDestructor" $parentRpc ServiceCreate "%DEL" [list Sq3LiteRpc Sq3LiteDestructor $rpcHdl] }
DeleteCallback: If the objHdl is still available delete the obj :
oo::define Sq3LiteRpc self method Sq3LiteDestructor {parentRpc childRpc} { set typName [$parentRpc ReadSTR] set typHdl [$parentRpc ReadHDL] set objHdl [$parentRpc ReadHDL] # type=MyClassS -> rpc=MyClassRpc set classRpc [string replace $typName end end Rpc] # hdl=objHdl -> obj set obj [$childRpc CacheLookup $classRpc $objHdl] # is "obj" already deleted ? if {$obj eq "MK_NULL"} return # now delete "obj" try { # the "objHdl" is already deleted on server, avoid resent $obj hdl 0 $obj destroy } on error {} { [$parentRpc ErrorCatch] Println } } oo::define Sq3LiteRpc export Sq3LiteDestructor