2 * Copyright (c) 2003 University of Murcia. All rights reserved.
\r
3 * --------------------------------------------------------------
\r
4 * For more information, please see <http://www.umu.euro6ix.org/>.
\r
7 package org.umu.cops.stack;
\r
9 import java.io.IOException;
\r
10 import java.io.OutputStream;
\r
11 import java.net.Socket;
\r
16 * @version COPSTimer.java, v 1.00 2003
\r
19 public class COPSTimer extends COPSObjBase {
\r
21 protected COPSObjHeader _objHdr;
\r
22 private short _reserved;
\r
23 private short _timerValue;
\r
26 * Returns size in number of octects, including header
\r
31 public short getDataLength() {
\r
32 //Add the size of the header also
\r
33 return (_objHdr.getDataLength());
\r
37 * Method getTimerVal
\r
42 public short getTimerVal() {
\r
52 public boolean isTimer() {
\r
62 public boolean isKATimer() {
\r
67 * Method isAcctTimer
\r
72 public boolean isAcctTimer() {
\r
77 * Write data to given socket in Network byte order
\r
79 * @param id a Socket
\r
81 * @throws IOException
\r
84 public void writeData(Socket id) throws IOException {
\r
85 _objHdr.writeData(id);
\r
87 byte[] buf = new byte[4];
\r
89 buf[0] = (byte) (_reserved >> 8);
\r
90 buf[1] = (byte) _reserved;
\r
91 buf[2] = (byte) (_timerValue >> 8);
\r
92 buf[3] = (byte) _timerValue;
\r
93 COPSUtil.writeData(id, buf, 4);
\r
96 protected COPSTimer(short timeVal) {
\r
97 _objHdr = new COPSObjHeader();
\r
98 //Time range is 1 - 65535 seconds
\r
99 _timerValue = timeVal;
\r
100 // _objHdr.setDataLength(sizeof(u_int32_t));
\r
101 _objHdr.setDataLength((short) 4);
\r
105 * Receive data that is in netwrok byte order and fill in the obj.
\r
107 protected COPSTimer(byte[] dataPtr) {
\r
108 _objHdr = new COPSObjHeader();
\r
109 _objHdr.parse(dataPtr);
\r
110 // _objHdr.checkDataLength();
\r
112 _reserved |= ((short) dataPtr[4]) << 8;
\r
113 _reserved |= ((short) dataPtr[5]) & 0xFF;
\r
114 _timerValue |= ((short) dataPtr[6]) << 8;
\r
115 _timerValue |= ((short) dataPtr[7]) & 0xFF;
\r
117 // _objHdr.setDataLength(sizeof(u_int32_t));
\r
118 _objHdr.setDataLength((short) 4);
\r
122 * Write an object textual description in the output stream
\r
124 * @param os an OutputStream
\r
126 * @throws IOException
\r
129 public void dump(OutputStream os) throws IOException {
\r
131 os.write(new String("Timer val: " + _timerValue + "\n").getBytes());
\r