1 /*
2 *
3 * Fosstrak LLRP Commander (www.fosstrak.org)
4 *
5 * Copyright (C) 2008 ETH Zurich
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 *
20 */
21
22 package org.fosstrak.llrp.client;
23
24 /**
25 * This wrapper class for Reader. Some extended attributes added for
26 * Editor use.
27 *
28 * @author Haoning Zhang
29 * @version 1.0
30 */
31 public class Reader {
32
33 /**
34 * The default Adapter Name.
35 * For those Readers, which are directly connected form Client side.
36 */
37 public final static String LOCAL_ADAPTER_NAME = "Local";
38
39 private String adapterName;
40 private String name;
41 private String ip;
42 private int port;
43
44 /**
45 * Default Constructor.
46 */
47 public Reader() {
48 setAdapterName(LOCAL_ADAPTER_NAME);
49 }
50
51 /**
52 * Get the Unique Id of this Reader.
53 */
54 public String getId() {
55 return getUniqueReaderId(getAdapterName(), getName());
56 }
57
58 /**
59 * Get IP address.
60 *
61 * @return Reader IP Address
62 */
63 public String getIp() {
64 return ip;
65 }
66
67 /**
68 * Set IP Address
69 *
70 * @param ip Reader IP Address
71 */
72 public void setIp(String ip) {
73 this.ip = ip;
74 }
75
76 /**
77 * Get Port number
78 *
79 * @return Reader Port Number
80 */
81 public int getPort() {
82 return port;
83 }
84
85 /**
86 * Set Port Number
87 *
88 * @param port Reader Port Number
89 */
90 public void setPort(int port) {
91 this.port = port;
92 }
93
94 /**
95 * Get the logical name of the Reader.
96 *
97 * @return Reader Logical Name
98 */
99 public String getName() {
100 return name;
101 }
102
103 /**
104 * Set the logical name of the Reader.
105 *
106 * @param name Reader Logical Name
107 */
108 public void setName(String name) {
109 this.name = name;
110 }
111
112 /**
113 * Get the name of LLRP Adapter, which hold this Reader.
114 */
115 public String getAdapterName() {
116 return adapterName;
117 }
118
119 /**
120 * Set the name of LLRP Adapter, which hold this Reader.
121 *
122 * @param aAdapterName String the name of Adapter.
123 */
124 public void setAdapterName(String aAdapterName) {
125 adapterName = aAdapterName;
126 }
127
128 public boolean isAttachedTo(String aAdapterName) {
129 return aAdapterName.trim().equals(getAdapterName())? true : false;
130 }
131
132 /**
133 * Static function to get system wide unique reader name.
134 * It just combine the AdapterName and the ReaderName.
135 *
136 * @param aAdapterName Adapter Logical Name
137 * @param aReaderName Reader Logical Name
138 * @return a string holding a unique reader name.
139 */
140 public static String getUniqueReaderId(String aAdapterName, String aReaderName) {
141 return aAdapterName + "-" + aReaderName;
142 }
143
144 /**
145 * Get the description of the Reader.
146 */
147 public String toString() {
148 StringBuffer sb = new StringBuffer();
149 sb.append("Name:");
150 sb.append(getName());
151 sb.append(" Adater:");
152 sb.append(getAdapterName());
153 sb.append(" IP:");
154 sb.append(getIp());
155 sb.append(":");
156 sb.append(getPort());
157 return sb.toString();
158 }
159 }