~persia/lsb-arm-port/tet-harness

« back to all changes in this revision

Viewing changes to src/java/TET/SyncMessage.java

  • Committer: Emmet Hikory
  • Date: 2010-01-08 04:58:01 UTC
  • Revision ID: persia@ubuntu.com-20100108045801-e6zpplxkui2e9tcp
Upstream tarball for 3.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      SCCS: @(#)SyncMessage.java      1.1 (99/09/03)
 
3
 *
 
4
 *      UniSoft Ltd., London, England
 
5
 *
 
6
 * Copyright (c) 1999 The Open Group
 
7
 * All rights reserved.
 
8
 *
 
9
 * No part of this source code may be reproduced, stored in a retrieval
 
10
 * system, or transmitted, in any form or by any means, electronic,
 
11
 * mechanical, photocopying, recording or otherwise, except as stated
 
12
 * in the end-user licence agreement, without the prior permission of
 
13
 * the copyright owners.
 
14
 * A copy of the end-user licence agreement is contained in the file
 
15
 * Licence which accompanies this distribution.
 
16
 * 
 
17
 * Motif, OSF/1, UNIX and the "X" device are registered trademarks and
 
18
 * IT DialTone and The Open Group are trademarks of The Open Group in
 
19
 * the US and other countries.
 
20
 *
 
21
 * X/Open is a trademark of X/Open Company Limited in the UK and other
 
22
 * countries.
 
23
 *
 
24
 */
 
25
 
 
26
package TET;
 
27
 
 
28
/**
 
29
 * The <code>SyncMessage</code> class provides the details of one message used
 
30
 * during a TET sychronization event.
 
31
 *
 
32
 * @version     @(#)SyncMessage.java    1.1 99/09/03 TETware release 3.7
 
33
 * @author      From JETpack 1.02 source
 
34
 * @author      Matthew Hails, UniSoft Ltd.
 
35
 */
 
36
public class SyncMessage
 
37
{
 
38
        static final String sccsid = "@(#)SyncMessage.java      1.1 (99/09/03) TETware release 3.7";
 
39
 
 
40
        /**
 
41
         * Bit value for flags, indicating that the system is sending message
 
42
         * data.
 
43
         *
 
44
         * <p>
 
45
         * Provided as public for backwards compatibility only; serves no
 
46
         * useful purpose outside package.
 
47
         */
 
48
        public static final int TET_SMSNDMSG    = 001;
 
49
 
 
50
        /**
 
51
         * Bit value for flags, indicating that the system is receiving message
 
52
         * data.
 
53
         *
 
54
         * <p>
 
55
         * Provided as public for backwards compatibility only; serves no
 
56
         * useful purpose outside package.
 
57
         */
 
58
        public static final int TET_SMRCVMSG    = 002;
 
59
 
 
60
        /**
 
61
         * Bit value for flags, indicating that more than one system attempted
 
62
         * to send message data.
 
63
         *
 
64
         * <p>
 
65
         * Provided as public for backwards compatibility only; serves no
 
66
         * useful purpose outside package.
 
67
         */
 
68
        public static final int TET_SMDUP       = 004;
 
69
 
 
70
        /**
 
71
         * Bit value for flags, indicating that the message data was truncated.
 
72
         *
 
73
         * <p>
 
74
         * Provided as public for backwards compatibility only; serves no
 
75
         * useful purpose outside package.
 
76
         */
 
77
        public static final int TET_SMTRUNC     = 010;
 
78
 
 
79
        /**
 
80
         * Maximum size of a sync message. Size must be expressable in 12 bits.
 
81
         */
 
82
        public static final int TET_SMMSGMAX    = 1024;
 
83
 
 
84
        /*
 
85
         * Message data.
 
86
         */
 
87
        private byte[] data;
 
88
 
 
89
        /*
 
90
         * Flags.
 
91
         */
 
92
        private int flags;
 
93
 
 
94
        /*
 
95
         * System ID of system that sent data.
 
96
         */
 
97
        private int sysID;
 
98
 
 
99
        /**
 
100
         * Construct an empty <code>SyncMessage</code>.
 
101
         */
 
102
        public SyncMessage()
 
103
        {
 
104
                data = null;
 
105
                flags = 0;
 
106
                sysID = -1;
 
107
        }
 
108
 
 
109
        /**
 
110
         * Construct a <code>SyncMessage</code> which will be used for the
 
111
         * transmission of a message.
 
112
         *
 
113
         * @param       msg     the message to send.
 
114
         */
 
115
        public SyncMessage(byte[] msg)
 
116
        {
 
117
                set_message(msg);
 
118
        }
 
119
 
 
120
        /**
 
121
         * Construct a <code>SyncMessage</code> which will be used for the
 
122
         * reception of a message.
 
123
         *
 
124
         * @param       msglen  the size of the receive buffer to set up.
 
125
         */
 
126
        public SyncMessage(int msglen)
 
127
        {
 
128
                set_receive_length(msglen);
 
129
        }
 
130
 
 
131
        /**
 
132
         * Set up a <code>SyncMessage</code> for transmission of a message.
 
133
         *
 
134
         * @param       msg     the message to send.
 
135
         */
 
136
        public void set_message(byte[] msg)
 
137
        {
 
138
                data = msg;
 
139
                flags = TET_SMSNDMSG;
 
140
                sysID = -1;
 
141
        }
 
142
 
 
143
        /**
 
144
         * Retrieve the message length.
 
145
         *
 
146
         * @return      the message length.
 
147
         */
 
148
        public int length()
 
149
        {
 
150
                return (data == null) ? 0 : data.length;
 
151
        }
 
152
 
 
153
        /**
 
154
         * Set up a <code>SyncMessage</code> for reception of a message.
 
155
         *
 
156
         * @param       msglen  the size of the receive buffer to set up.
 
157
         */
 
158
        public void set_receive_length(int msglen)
 
159
        {
 
160
                if (msglen > 0)
 
161
                        data = new byte[msglen];
 
162
                else
 
163
                        data = null;
 
164
 
 
165
                flags = TET_SMRCVMSG;
 
166
                sysID = -1;
 
167
        }
 
168
 
 
169
        /**
 
170
         * Retrieve the message data.
 
171
         *
 
172
         * @return      the message data (as a byte array), <code>null</code>
 
173
         *              if there is no message data.
 
174
         */
 
175
        public byte[] message()
 
176
        {
 
177
                return data;
 
178
        }
 
179
 
 
180
        /**
 
181
         * Was this synchronization message truncated?
 
182
         *
 
183
         * @return      <code>true</code> if the message was truncated because
 
184
         *              the message was longer than the receive buffer or
 
185
         *              because the message was longer than the permitted
 
186
         *              message length.
 
187
         */
 
188
        public boolean truncated()
 
189
        {
 
190
                return (flags & TET_SMTRUNC) != 0;
 
191
        }
 
192
 
 
193
        /**
 
194
         * Were there two senders during synchronization?
 
195
         *
 
196
         * @return      <code>true</code> if there were two senders during
 
197
         *              synchronization.
 
198
         */
 
199
        public boolean duplicated()
 
200
        {
 
201
                return (flags & TET_SMDUP) != 0;
 
202
        }
 
203
 
 
204
        /**
 
205
         * Was this message sent or does it contains message received from
 
206
         * another system?
 
207
         *
 
208
         * @return      <code>true</code> if this message was sent during
 
209
         *              synchronization.
 
210
         */
 
211
        public boolean sender()
 
212
        {
 
213
                return (flags & TET_SMSNDMSG) != 0;
 
214
        }
 
215
 
 
216
        /**
 
217
         * Get the value of the system ID of the sending system.
 
218
         *
 
219
         * @return      the value of the system ID, or -1 if this message data
 
220
         *              was not used to receive data.
 
221
         */
 
222
        public int getSysID()
 
223
        {
 
224
                return sysID;
 
225
        }
 
226
 
 
227
        /**
 
228
         * Get the flags value.
 
229
         */
 
230
        int getFlags()
 
231
        {
 
232
                return flags;
 
233
        }
 
234
 
 
235
        /**
 
236
         * Set the fields of the message.
 
237
         *
 
238
         * @param       data    the message data.
 
239
         * @param       flags   the message flags.
 
240
         * @param       sysID   the system ID of the sending system.
 
241
         */
 
242
        void setFields(byte[] data, int flags, int sysID)
 
243
        {
 
244
                this.data = data;
 
245
                this.flags = flags;
 
246
                this.sysID = sysID;
 
247
        }
 
248
}