summaryrefslogtreecommitdiff
path: root/java/JACE/netsvcs/Time/TimeRequest.java
blob: 1b0e691398a0560eb967ff150abbc7938d2d8b5d (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
package JACE.netsvcs.Time;

import java.io.*;
import java.net.*;

/**
 * Request for a time update (and its reply).  This is compatible with 
 * C++ ACE_Time_Request.  Currently, the Java version always specifies to
 * block forever for requests.
 */
public class TimeRequest
{
  /**
   * Type for requesting updates.
   */
  public static int TIME_UPDATE = 01;

  /**
   * Default constructor, specifies block forever for an update.
   */
  public TimeRequest ()
  {
    messageType_ = TIME_UPDATE;
    blockForever_ = 1;
  }

  /**
   * Constructor specifying the type of request, the current
   * time, and to block forever.
   */
  public TimeRequest (int messageType,
		      int timeSec)
  {
    time_ = timeSec;
    messageType_ = messageType;
    blockForever_ = 1;
  }

  /**
   * Dump all class information to a String.
   */
  public String toString ()
  {
    return "TimeRequest (" + messageType_ +
      ", " + blockForever_ + ", " + secTimeout_ + ", " +
      usecTimeout_ + ", " + time_ + ")";
  }

  /**
   * Read the TimeRequest in from a given InputStream.
   */
  public void streamInFrom (InputStream is) 
    throws IOException, EOFException
  {
    BufferedInputStream bis = new BufferedInputStream (is, 25);
    DataInputStream dis = new DataInputStream (bis);

    streamInFrom (dis);
  }

  /**
   * Read the TimeRequest in from a given DataInputStream.
   */
  public void streamInFrom (DataInputStream dis)
    throws IOException, EOFException
  {
    messageType_ = dis.readInt ();
    blockForever_ = dis.readInt ();
    secTimeout_ = dis.readInt ();
    usecTimeout_ = dis.readInt ();
    time_ = dis.readInt ();
  }

  /**
   * Write this TimeRequest out to a given OutputStream.
   */
  public void streamOutTo (OutputStream os)
    throws IOException
  {
    BufferedOutputStream bos = new BufferedOutputStream (os, 25);
    DataOutputStream dos = new DataOutputStream (bos);

    streamOutTo (dos);
  }

  /** 
   * Write this TimeRequest out to a given DataOutputStream.
   */
  public void streamOutTo (DataOutputStream dos) throws IOException
  {
    dos.writeInt (messageType_);
    dos.writeInt (blockForever_);
    dos.writeInt (secTimeout_);
    dos.writeInt (usecTimeout_);
    dos.writeInt (time_);

    dos.flush ();
  }

  /**
   * Return the time value in seconds.
   */
  public int time ()
  {
    return time_;
  }

  /**
   * Set the time value in seconds.
   */
  public void time (int value)
  {
    time_ = value;
  }

  private int messageType_;
  private int blockForever_;
  private int secTimeout_;
  private int usecTimeout_;
  private int time_;
}