1 # DpTcl.tcl --
2 #
3 # OTcl wrapper object for doing TclDP RPC communication. This wraps
4 # around mash-code/lib/tcl/dp-lib.tcl
5 #
6 # Copyright (c) 2000-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 #
33 # Dummy stuff for import.
34 #
35
36 # Make sure dp-lib is loaded. Previously, we source the file directly,
37 # which does not always work if we build outside the source directory.
38 import Dp
39
40 Class DpTcl
41
42 DpTcl instproc init {} {
43 }
44
45 Class DpServer
46
47 DpServer instproc init {port} {
48
49 $self next
50
51 $self instvar server_
52
53 set server_ [dp_MakeRPCServer $port]
54 }
55
56 Class DpClient
57
58 DpClient instproc init {host port} {
59 $self instvar client_
60
61 $self next
62
63 # set client to be the socket file descriptor
64 set client_ [dp_MakeRPCClient $host $port]
65
66 return $client_
67 }
68
69 #
70 # do an RPC and wait for the result
71 #
72 DpClient instproc do { args } {
73 $self instvar client_
74
75 # this is the old way to do it - it's wrong!
76 # when you use eval, you will lose the argument groupings if you presubstitute,
77 # you should use a list to create the arguments, check below
78 # set cmd "dp_RPC $client_"
79 # foreach arg $args {
80 # set cmd "$cmd $arg"
81 # }
82
83 set cmd [list dp_RPC $client_]
84 foreach arg $args {
85 lappend cmd $arg
86 }
87
88 return [eval $cmd]
89 }
90
91 #
92 # do an RPC that doesn't expect a result, return immediately
93 #
94 DpClient instproc doNoWait { args } {
95
96 $self instvar client_
97
98 set cmd [list dp_RDO $client_]
99 foreach arg $args {
100 lappend cmd $arg
101 }
102
103 return [eval $cmd]
104 }
105
106 #
107 # close the connection by sending a signal to the server
108 #
109 DpClient instproc closeRPC {} {
110 $self instvar client_
111
112 set cmd "dp_CloseRPC $client_ "
113
114 return [eval $cmd]
115 }
116
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.