~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/common/mash-remoteobject.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # mash-remoteobject.tcl --
  2 #
  3 #   A wrapper around Dp to allow RPC calls to remote object/methods.
  4 #   Remote object can be treated almost in the same way as local object.
  5 #
  6 # Copyright (c) 1996-2002 The Regents of the University of California.
  7 # All rights reserved.
  8 #
  9 # Redistribution and use in source and binary forms, with or without
 10 # modification, are permitted provided that the following conditions are met:
 11 #
 12 # A. Redistributions of source code must retain the above copyright notice,
 13 #    this list of conditions and the following disclaimer.
 14 # B. Redistributions in binary form must reproduce the above copyright notice,
 15 #    this list of conditions and the following disclaimer in the documentation
 16 #    and/or other materials provided with the distribution.
 17 # C. Neither the names of the copyright holders nor the names of its
 18 #    contributors may be used to endorse or promote products derived from this
 19 #    software without specific prior written permission.
 20 #
 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 24 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31 #
 32 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/common/mash-remoteobject.tcl,v 1.1 2002/05/28 19:55:37 weitsang Exp $
 33 
 34 # Make sure Object's instproc are included
 35 import Application
 36 import Dp
 37 
 38 #-------------------------------------------------------------
 39 # Class:
 40 #   MashRemoteObject
 41 # Description:
 42 #   A wrapper around Dp that allows access to a remote object
 43 #   just like local object.  Mirror to remote object can be 
 44 #   created in different ways by passing different options
 45 #   to the constructor.  "new" takes a name of the Class and
 46 #   creates a new remote object, "copy" takes a name of a 
 47 #   remote object, "eval" takes an expression that will be
 48 #   remotely evaluated and returns a remote object.   
 49 #   IMPORTANT:  It is the caller responsibility to free remote
 50 #   object.  
 51 #-------------------------------------------------------------
 52 Class MashRemoteObject
 53 
 54 # Remove all instprocs (both Tcl and C) of Object, so that 
 55 # unknown will be called instead.  However, we cannot remove
 56 # instproc, since we still need it to define methods below.
 57 
 58 foreach instproc [Object info instcommands] {
 59     if {$instproc != "instvar" && 
 60         $instproc != "next" && 
 61         $instproc != "create" && 
 62         $instproc != "instproc"} {
 63         MashRemoteObject instproc $instproc { args } { 
 64             return [eval $self unknown $proc $args]
 65         }
 66     }
 67 }
 68 MashRemoteObject instproc init { rpc_channel op args } {
 69     $self instvar remote_object_ rpc_channel_ is_copy_
 70     switch $op {
 71         new {
 72             set remote_object_ [eval dp_RPC $rpc_channel new $args]
 73             set is_copy_ 0
 74         }
 75         copy {
 76             set remote_object_ [lindex $args 0]
 77             set is_copy_ 1
 78         }
 79         eval {
 80             set remote_object_ [eval dp_RPC $rpc_channel $args]
 81             set is_copy_ 1
 82         }
 83         default {
 84             error "Unknown option $op.  Valid options are new and copy"
 85         }
 86     }
 87     set rpc_channel_ $rpc_channel
 88 }
 89 
 90 MashRemoteObject instproc delete_tkvar { args } {
 91 }
 92 
 93 MashRemoteObject instproc destroy { args } {
 94     $self instvar is_copy_ rpc_channel_ remote_object_
 95     if {!$is_copy_} {
 96         catch {eval dp_RPC $rpc_channel_ delete $remote_object_}
 97     } 
 98     $self next
 99 }
100 
101 
102 MashRemoteObject instproc unknown { args } {
103     $self instvar rpc_channel_ remote_object_
104     set result [eval dp_RPC $rpc_channel_ $remote_object_ [lindex $args 0] [lrange $args 1 end]]
105     return $result
106 }
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.