View Javadoc
1   package org.sentrysoftware.ipmi.core.coding.payload.sol;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * IPMI Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 Verax Systems, Sentry Software
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.sentrysoftware.ipmi.core.common.TypeConverter;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  /**
31   * {@link SolInboundStatusField} is a transfer object for status sent by remote system to this application in {@link SolInboundMessage}.
32   */
33  public class SolInboundStatusField {
34  
35      /**
36       * Acknowledge state of {@link SolMessage} that this message is response for.
37       */
38      private final SolAckState ackState;
39  
40      /**
41       * Set of statuses indicated by BMC in this message.
42       */
43      private final Set<SolStatus> statuses;
44  
45      /**
46       * Creates new instance if {@link SolInboundStatusField} without Acknowledge data.
47       *
48       * @param statuses
49       *          Set of SOL specific statuses for inbound message
50       */
51      public SolInboundStatusField(Set<SolStatus> statuses) {
52          this.ackState = SolAckState.ACK;
53          this.statuses = statuses;
54      }
55  
56      /**
57       * Creates new instance of {@link SolInboundStatusField} filled with given data.
58       *
59       * @param ackState
60       *          Acknowledge state carried by this object
61       * @param statuses
62       *          Set of SOL specific statuses for inbound message
63       */
64      public SolInboundStatusField(SolAckState ackState, Set<SolStatus> statuses) {
65          this.ackState = ackState;
66          this.statuses = statuses;
67      }
68  
69      /**
70       * Creates new instance of {@link SolInboundStatusField} from raw byte.
71       *
72       * @param raw
73       *          byte carrying information about SOL status
74       */
75      public SolInboundStatusField(byte raw) {
76          this.ackState = SolAckState.extractFromByte(raw);
77          this.statuses = extractStatusesFromByte(raw);
78      }
79  
80      private Set<SolStatus> extractStatusesFromByte(byte raw) {
81          Set<SolStatus> result = new HashSet<SolStatus>();
82  
83          for (SolStatus status : SolStatus.values()) {
84              if (TypeConverter.isBitSetOnPosition(status.getStatusNumber(), raw)) {
85                  result.add(status);
86              }
87          }
88  
89          return result;
90      }
91  
92      public Set<SolStatus> getStatuses() {
93          return statuses;
94      }
95  
96      public SolAckState getAckState() {
97          return ackState;
98      }
99  
100     /**
101      * Convert this object to it's raw, byte representation.
102      */
103     public byte convertToByte() {
104         byte value = (byte) 0;
105 
106         value = ackState.encodeInByte(value);
107 
108         for (SolStatus status : statuses) {
109             value = TypeConverter.setBitOnPosition(status.getStatusNumber(), value);
110         }
111 
112         return value;
113     }
114 }