line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HyperWave::CSP::Message; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copes with Messages for HyperWave |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright (c) 1998 Bek Oberin. All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
8
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Last updated by gossamer on Fri Mar 20 21:26:20 EST 1998 |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# NB: People have to input the 'data' part in the format |
15
|
|
|
|
|
|
|
# they want it to be, we don't format that bit. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
808
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $MSGID = 86; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# Constructor |
26
|
|
|
|
|
|
|
# optionally takes command, data and msgid arguments in which |
27
|
|
|
|
|
|
|
# case it builds a new command |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
sub new { |
30
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
31
|
0
|
|
|
|
|
|
my $command = shift; |
32
|
0
|
|
|
|
|
|
my $data = shift; |
33
|
0
|
|
|
|
|
|
my $msgid = shift; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
36
|
0
|
|
|
|
|
|
my $self = {}; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->{"length"} = undef; |
39
|
0
|
|
|
|
|
|
$self->{"length_set"} = 0; |
40
|
0
|
|
|
|
|
|
$self->{"msgtype"} = undef; |
41
|
0
|
|
|
|
|
|
$self->{"data"} = undef; |
42
|
0
|
|
|
|
|
|
$self->{"msgid"} = undef; |
43
|
0
|
0
|
|
|
|
|
if ($command) { |
44
|
0
|
|
|
|
|
|
$self->{"msgtype"} = $command; |
45
|
0
|
0
|
|
|
|
|
if ($data) { |
46
|
0
|
|
|
|
|
|
$self->{"data"} = $data; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
if ($msgid) { |
49
|
0
|
|
|
|
|
|
$self->{"msgid"} = $msgid; |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
|
$self->{"msgid"} = $MSGID++; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
bless($self, $class); |
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
# destructor |
61
|
|
|
|
|
|
|
# |
62
|
0
|
|
|
0
|
|
|
sub DESTROY { |
63
|
|
|
|
|
|
|
# nothing yet |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# |
67
|
|
|
|
|
|
|
# Data |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# |
71
|
|
|
|
|
|
|
# methods to access per-object data |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
# With args, they set the value. Without any, they only retrieve it/them. |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub length { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if (@_) { |
80
|
|
|
|
|
|
|
# set it |
81
|
0
|
|
|
|
|
|
$self->{"length"} = shift; |
82
|
0
|
|
|
|
|
|
$self->{"length_set"} = 1; |
83
|
|
|
|
|
|
|
} else { |
84
|
|
|
|
|
|
|
# return it |
85
|
0
|
0
|
|
|
|
|
if (!$self->{"length"}) { |
86
|
|
|
|
|
|
|
# NB: The 11 is the number of the self->length_formatted() plus |
87
|
|
|
|
|
|
|
# the separating space. Has to be done this way to avoid getting |
88
|
|
|
|
|
|
|
# into a repeating loop. |
89
|
0
|
|
|
|
|
|
$self->{"length"} = 11 + length($self->msgid_formatted() . " " . $self->msgtype_formatted . " " . $self->data_formatted()); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $self->{"length"}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub length_formatted { |
97
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return sprintf("%10d", $self->length()); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub msgid { |
104
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# set it |
107
|
0
|
0
|
|
|
|
|
if (@_) { |
108
|
0
|
|
|
|
|
|
$self->{"msgid"} = shift; |
109
|
0
|
0
|
|
|
|
|
$self->{"length"} = undef unless $self->{"length_set"}; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
return $self->{"msgid"}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub msgid_formatted { |
115
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $self->msgid(); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub msgtype { |
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
123
|
0
|
0
|
|
|
|
|
if (@_) { |
124
|
0
|
|
|
|
|
|
$self->{"msgtype"} = shift; |
125
|
0
|
0
|
|
|
|
|
$self->{"length"} = undef unless $self->{"length_set"}; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return $self->{"msgtype"}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub msgtype_formatted { |
131
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $self->msgtype(); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#sub msgtype_string { |
138
|
|
|
|
|
|
|
# my $self = shift; |
139
|
|
|
|
|
|
|
# return $message_types[$self->{"msgtype"}]; |
140
|
|
|
|
|
|
|
#} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub data { |
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
144
|
0
|
0
|
|
|
|
|
if (@_) { |
145
|
0
|
|
|
|
|
|
$self->{"data"} = shift; |
146
|
0
|
0
|
|
|
|
|
$self->{"length"} = undef unless $self->{"length_set"}; |
147
|
|
|
|
|
|
|
} |
148
|
0
|
|
|
|
|
|
return $self->{"data"}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub data_formatted { |
152
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $self->data(); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub as_string { |
158
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
159
|
0
|
|
|
|
|
|
my $tmp; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
if (!defined($self->{"length"})) { |
162
|
0
|
|
|
|
|
|
$self->length(); |
163
|
|
|
|
|
|
|
# This just makes sure it's set. |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
return |
167
|
0
|
|
|
|
|
|
$self->length_formatted() . " " . |
168
|
|
|
|
|
|
|
$self->msgid_formatted() . " " . |
169
|
|
|
|
|
|
|
$self->msgtype_formatted . " " . |
170
|
|
|
|
|
|
|
$self->data_formatted(); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# |
174
|
|
|
|
|
|
|
# Debug function only!! |
175
|
|
|
|
|
|
|
# |
176
|
|
|
|
|
|
|
sub dump { |
177
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
178
|
0
|
|
|
|
|
|
my $text = shift; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
print(STDERR "DUMPING Message $self\n"); |
181
|
0
|
0
|
|
|
|
|
print(STDERR ">>$text<<\n") if $text; |
182
|
0
|
|
|
|
|
|
print(STDERR "length = " . dumpvar::stringify($self->{"length"}) . "\n"); |
183
|
0
|
|
|
|
|
|
print(STDERR "msgid = " . dumpvar::stringify($self->{"msgid"}) . "\n"); |
184
|
0
|
|
|
|
|
|
print(STDERR "msgtype = " . dumpvar::stringify($self->{"msgtype"}) . "\n"); |
185
|
0
|
|
|
|
|
|
print(STDERR "data = " . dumpvar::stringify($self->{"data"}) . "\n"); |
186
|
0
|
|
|
|
|
|
print(STDERR "END DUMP.\n"); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
# End. |
192
|
|
|
|
|
|
|
# |
193
|
|
|
|
|
|
|
1; # so the require or use succeeds |