View Javadoc
1   package org.metricshub.ipmi.core.coding.commands.payload;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * IPMI Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 Verax Systems, MetricsHub
8    * ჻჻჻჻჻჻
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23   */
24  
25  import org.metricshub.ipmi.core.coding.commands.ResponseData;
26  import org.metricshub.ipmi.core.common.TypeConverter;
27  
28  import java.util.LinkedList;
29  import java.util.List;
30  
31  /**
32   * Wrapper for Get Payload Activation Status response.
33   */
34  public class GetPayloadActivationStatusResponseData implements ResponseData {
35  
36      /**
37       * Number of instances of given payload type that can be simultaneously activated on BMC.
38       */
39      private byte instanceCapacity;
40  
41      /**
42       * List of instance ID's that are still available (not activated).
43       */
44      private List<Byte> availableInstances;
45  
46      public byte getInstanceCapacity() {
47          return instanceCapacity;
48      }
49  
50      public void setInstanceCapacity(byte instanceCapacity) {
51          this.instanceCapacity = instanceCapacity;
52      }
53  
54      public List<Byte> getAvailableInstances() {
55          List<Byte> actuallyAvailableInstances = new LinkedList<Byte>();
56  
57          for (Byte instanceId : availableInstances) {
58              if (instanceId <= instanceCapacity) {
59                  actuallyAvailableInstances.add(instanceId);
60              }
61          }
62  
63          return actuallyAvailableInstances;
64      }
65  
66      public void setAvailableInstances(byte[] availableInstancesData) {
67          this.availableInstances = getAvailableInstancesFromBytes(availableInstancesData);
68      }
69  
70      private List<Byte> getAvailableInstancesFromBytes(byte[] availableInstancesData) {
71          List<Byte> result = new LinkedList<Byte>();
72  
73          List<Byte> instancesFromFirstByte = checkForAvailableInstancesInByte(availableInstancesData[0], 0);
74          List<Byte> instancesFromSecondByte = checkForAvailableInstancesInByte(availableInstancesData[1], 8);
75  
76          result.addAll(instancesFromFirstByte);
77          result.addAll(instancesFromSecondByte);
78  
79          return result;
80      }
81  
82      private List<Byte> checkForAvailableInstancesInByte(byte availableInstancesByte, int instanceIdOffset) {
83          List<Byte> result = new LinkedList<Byte>();
84  
85          for (int i = 0; i < 8; ++i) {
86              if (!TypeConverter.isBitSetOnPosition(i, availableInstancesByte)) {
87                  result.add((byte) (i + 1 + instanceIdOffset));
88              }
89          }
90  
91          return result;
92      }
93  
94      @Override
95      public String toString() {
96          return "GetPayloadActivationStatusResponseData{" +
97                  "instanceCapacity=" + getInstanceCapacity() +
98                  ", availableInstances=" + getAvailableInstances() +
99                  '}';
100     }
101 }