1 package org.metricshub.ipmi.core.coding.commands.payload;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.metricshub.ipmi.core.coding.commands.CommandCodes;
26 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
27 import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
28 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
29 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
30 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
31 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
32 import org.metricshub.ipmi.core.coding.protocol.PayloadType;
33 import org.metricshub.ipmi.core.common.MessageComposer;
34 import org.metricshub.ipmi.core.common.MessageReader;
35 import org.metricshub.ipmi.core.common.TypeConverter;
36
37 import java.security.InvalidKeyException;
38 import java.security.NoSuchAlgorithmException;
39
40
41
42
43 public class GetPayloadActivationStatus extends IpmiCommandCoder<GetPayloadActivationStatusResponseData> {
44
45 private static final int REQUEST_DATA_LENGTH = 1;
46 private static final int INSTANCE_CAPACITY_FIELD_LENGTH = 1;
47 private static final int AVAILABLE_INSTANCES_FIELD_LENGTH = 2;
48
49 private final PayloadType payloadType;
50
51
52
53
54
55
56 public GetPayloadActivationStatus(PayloadType payloadType) {
57 this.payloadType = payloadType;
58 }
59
60 @Override
61 public byte getCommandCode() {
62 return CommandCodes.GET_PAYLOAD_ACTIVATION_STATUS;
63 }
64
65 @Override
66 public NetworkFunction getNetworkFunction() {
67 return NetworkFunction.ApplicationRequest;
68 }
69
70 @Override
71 protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
72 byte[] message = MessageComposer.get(REQUEST_DATA_LENGTH)
73 .appendField(TypeConverter.intToByte(payloadType.getCode()))
74 .getMessage();
75
76 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), message, TypeConverter.intToByte(sequenceNumber));
77 }
78
79 @Override
80 public GetPayloadActivationStatusResponseData getResponseData(IpmiMessage message)
81 throws IPMIException,
82 NoSuchAlgorithmException,
83 InvalidKeyException {
84
85 MessageReader messageReader = new MessageReader(validateResponse(message));
86
87 GetPayloadActivationStatusResponseData responseData = new GetPayloadActivationStatusResponseData();
88
89 byte instaceCapacity = messageReader.readNextField(INSTANCE_CAPACITY_FIELD_LENGTH)[0];
90 responseData.setInstanceCapacity(instaceCapacity);
91
92 byte[] availableInstancesData = messageReader.readNextField(AVAILABLE_INSTANCES_FIELD_LENGTH);
93 responseData.setAvailableInstances(availableInstancesData);
94
95 return responseData;
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (this == o) {
101 return true;
102 }
103 if (o == null || getClass() != o.getClass()) {
104 return false;
105 }
106
107 GetPayloadActivationStatus that = (GetPayloadActivationStatus) o;
108
109 return payloadType == that.payloadType;
110 }
111
112 @Override
113 public int hashCode() {
114 int result = payloadType.getCode();
115 return result;
116 }
117 }