Phone app (based on Ali's Control for iotcloud benchmark) to control alarm in the...
[iot2.git] / benchmarks / other / PhoneInterface / Control / app / src / main / java / iotcloud / NewKey.java
1 package iotcloud;
2
3 import java.nio.ByteBuffer;
4
5 /**
6  * This Entry records the abort sent by a given machine.
7  * @author Ali Younis <ayounis@uci.edu>
8  * @version 1.0
9  */
10
11
12 class NewKey extends Entry {
13         private IoTString key;
14         private long machineid;
15
16         public NewKey(Slot slot, IoTString _key, long _machineid) {
17                 super(slot);
18                 key = _key;
19                 machineid = _machineid;
20         }
21
22         public long getMachineID() {
23                 return machineid;
24         }
25
26         public IoTString getKey() {
27                 return key;
28         }
29
30         public void setSlot(Slot s) {
31                 parentslot = s;
32         }
33
34         static Entry decode(Slot slot, ByteBuffer bb) {
35                 int keylength = bb.getInt();
36                 byte[] key = new byte[keylength];
37                 bb.get(key);
38                 long machineid = bb.getLong();
39
40                 return new NewKey(slot, IoTString.shallow(key), machineid);
41         }
42
43         public void encode(ByteBuffer bb) {
44                 bb.put(Entry.TypeNewKey);
45                 bb.putInt(key.length());
46                 bb.put(key.internalBytes());
47                 bb.putLong(machineid);
48         }
49
50         public int getSize() {
51                 //return Long.BYTES + Byte.BYTES + Integer.BYTES + key.length();
52                 return Long.SIZE/8 + Byte.SIZE/8 + Integer.SIZE/8 + key.length();
53         }
54
55         public byte getType() {
56                 return Entry.TypeNewKey;
57         }
58
59         public Entry getCopy(Slot s) {
60                 return new NewKey(s, key, machineid);
61         }
62 }