File: PortEncoder.t

package info (click to toggle)
tom 1.1.1-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,340 kB
  • ctags: 2,244
  • sloc: objc: 27,863; ansic: 9,804; sh: 7,411; yacc: 3,377; lex: 966; asm: 208; makefile: 62; cpp: 10
file content (108 lines) | stat: -rw-r--r-- 2,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<copyright> Sending objects over the wire.
    Written by <a href="mailto:tiggr@ics.ele.tue.nl">Pieter J. Schoenmakers</a>

    Copyright &copy; 1997 Pieter J. Schoenmakers.

    This file is part of TOM.  TOM is distributed under the terms of the
    TOM License, a copy of which can be found in the TOM distribution; see
    the file LICENSE.

    <id>$Id: PortEncoder.t,v 1.6 1998/01/05 01:16:47 tiggr Exp $</id>
    </copyright>

implementation class
PortEncoder: BinaryEncoder, PortCoder

end;

implementation instance
PortEncoder

<doc> Designated initializer.  </doc>
id
  initWithConnection ConnectedConnection c
{
  [super (BinaryEncoder) init];
  = [super (PortCoder) initWithConnection c];
}

<doc> Return the object returned by asking {replacementForPortCoder} to
    the argument {object}.  </doc>
protected State
  replacementObjectFor State object
{
  = [object replacementForPortCoder self];
}

<doc> Encode the proxy {p} and return {TRUE}.  </doc>
boolean
  encodeProxy Proxy p
{
  // Note that the local and remote proxies should have different
  // implementations for {encodeUsingCoder}, so that the distinction, by
  // invoking different {encodeProxy} methods, does not cost another
  // method call ({isProxy}).
  // Mon Jan  6 00:55:41 1997, tiggr@tricky.es.ele.tue.nl
  /* A local proxy returns {NO} when asked {isProxy}.  */
  if ([p isProxy])
    {
      Connection con = [p proxy_connection];

      if (con != connection)
	[self unimplemented cmd message: "different-connection proxy encoding"];

      [self writeByte '!'];
    }
  else
    [self writeByte '$'];

  [self writeInt [p proxy_identity]];

  = TRUE;
}

<doc> Forward to the {port}.  </doc>
void
  flushOutput
{
  [port flushOutput];
}

void
  reportDeaths IntArray deaths
{
  int i, n = [deaths length];

  for (i = 0; i < n; i++)
    {
      [self writeByte '~'];
      [self writeInt deaths[i]];
    }
}

protected void
  writeByte byte b
{
  [port write b];
}

protected void
  writeBytes (int, int) (start, length)
	from ByteArray r
{
  int written = [port writeRange (start, length) from r];

  if (written != length)
    [[SelectorCondition for self class program-condition
      message [[MutableByteString new]
	       print ("wrote ", written, " instead of ", length)]
      selector cmd] raise];
}

protected void
  writeBytes (pointer, int) (address, length)
{
  [port writeBytes length from address];
}

end;