bad34e2b72200e1f7f368205cc2da84fab0bbe9c
[public/netxms.git] / src / java / client / netxms-client / src / main / java / org / netxms / client / ProtocolVersion.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client;
20
21 import java.util.Arrays;
22 import org.netxms.base.NXCPCodes;
23 import org.netxms.base.NXCPMessage;
24
25 /**
26 * NetXMS client protocol version
27 */
28 public final class ProtocolVersion
29 {
30 // Versions
31 public static final int BASE = 47;
32 public static final int ALARMS = 1;
33 public static final int PUSH = 1;
34 public static final int TRAP = 1;
35 public static final int MOBILE = 1;
36 public static final int FULL = 5;
37
38 // Indexes
39 public static final int INDEX_BASE = 0;
40 public static final int INDEX_ALARMS = 1;
41 public static final int INDEX_PUSH = 2;
42 public static final int INDEX_TRAP = 3;
43 public static final int INDEX_MOBILE = 4;
44 public static final int INDEX_FULL = 5;
45
46 private static final int[] CURRENT_VERSION = { BASE, ALARMS, PUSH, TRAP, MOBILE, FULL };
47
48 private long versions[];
49
50 /**
51 * Create protocol version information from NXCP message
52 *
53 * @param msg
54 */
55 protected ProtocolVersion(NXCPMessage msg)
56 {
57 versions = msg.getFieldAsUInt32Array(NXCPCodes.VID_PROTOCOL_VERSION_EX);
58 if (versions == null)
59 {
60 versions = new long[1];
61 versions[0] = msg.getFieldAsInt32(NXCPCodes.VID_PROTOCOL_VERSION);
62 }
63 }
64
65 /**
66 * Get version of given component
67 *
68 * @param index
69 * @return
70 */
71 public int getVersion(int index)
72 {
73 return (index >= 0) && (index < versions.length) ? (int)versions[index] : 0;
74 }
75
76 /**
77 * Check if version of given component match current version
78 *
79 * @param index
80 * @return
81 */
82 public boolean isCorrectVersion(int index)
83 {
84 if ((index < 0) || (index >= CURRENT_VERSION.length))
85 return false;
86 return getVersion(index) == CURRENT_VERSION[index];
87 }
88
89 /* (non-Javadoc)
90 * @see java.lang.Object#toString()
91 */
92 @Override
93 public String toString()
94 {
95 return "ProtocolVersion [versions=" + Arrays.toString(versions) + "]";
96 }
97 }