Added new constructor. May need to tighten down interfaces in the future.
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / stack / COPSTimer.java
1 /*
2  * Copyright (c) 2003 University of Murcia.  All rights reserved.
3  * --------------------------------------------------------------
4  * For more information, please see <http://www.umu.euro6ix.org/>.
5  */
6
7 package org.umu.cops.stack;
8
9 import java.io.IOException;
10 import java.io.OutputStream;
11 import java.net.Socket;
12
13 /**
14  * For extension by other COPS Timer Objects such as COPSAcctTimer & COPSKATimer
15  */
16 public abstract class COPSTimer extends COPSObjBase {
17
18     // TODO - determine what is the function of this member
19     private final short _reserved;
20
21     /**
22      * The timer values
23      */
24     private final short _timerValue;
25
26     /**
27      * Constructor generally used when parsing the bytes of an inbound COPS message but can also be used when the
28      * COPSObjHeader information is known
29      * @param header - the object header
30      * @param reserved - ???
31      * @param timerVal - the timer value
32      */
33     protected COPSTimer(final COPSObjHeader header, final short reserved, final short timerVal) {
34         super(header);
35         _reserved = reserved;
36         _timerValue = timerVal;
37     }
38
39     /**
40      * Method getTimerVal
41      * @return   a short
42      */
43     public short getTimerVal() {
44         return _timerValue;
45     }
46
47     @Override
48     public void writeBody(Socket socket) throws IOException {
49         byte[] buf = new byte[4];
50
51         buf[0] = (byte) (_reserved >> 8);
52         buf[1] = (byte) _reserved;
53         buf[2] = (byte) (_timerValue >> 8);
54         buf[3] = (byte) _timerValue;
55         COPSUtil.writeData(socket, buf, 4);
56     }
57
58     @Override
59     protected int getDataLength() {
60         return 4;
61     }
62
63     @Override
64     public void dumpBody(final OutputStream os) throws IOException {
65         os.write(("Timer val: " + _timerValue + "\n").getBytes());
66     }
67
68 }
69