Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package com.github.rosjava.android_remocons.common_tools.master;
00036
00037 import org.jboss.netty.buffer.ChannelBuffer;
00038 import org.jboss.netty.buffer.ChannelBuffers;
00039
00040 import java.util.Date;
00041 import java.util.regex.Matcher;
00042 import java.util.regex.Pattern;
00043
00044 import rocon_std_msgs.Icon;
00045
00051 public class MasterDescription implements java.io.Serializable {
00052
00053 public static final String UNIQUE_KEY = "com.github.rosjava.android_remocons.master.MasterDescription";
00054 private static final long serialVersionUID = 1L;
00055
00056 public static final String CONNECTING = "connecting...";
00057 public static final String OK = "ok";
00058 public static final String ERROR = "exception";
00059 public static final String WIFI = "invalid wifi";
00060 public static final String UNAVAILABLE = "unavailable";
00061 public static final String CONTROL = "not started";
00062 public static final String NAME_UNKNOWN = "Unknown";
00063 public static final String TYPE_UNKNOWN = "Unknown";
00064
00065 private MasterId masterId;
00066 private String masterName;
00067 private String masterType;
00068 private String appsNameSpace;
00069
00072 private String masterIconFormat;
00073 private byte[] masterIconData;
00074 private int masterIconDataOffset;
00075 private int masterIconDataLength;
00076
00077 private String connectionStatus;
00078 private Date timeLastSeen;
00079
00080
00081 public MasterDescription() {
00082 }
00083
00084 public MasterDescription(MasterId masterId, String masterName, String masterType,
00085 Icon masterIcon, String appsNameSpace, Date timeLastSeen) {
00086 setMasterName(masterName);
00087 setMasterId(masterId);
00088 this.masterName = masterName;
00089 this.masterType = masterType;
00090 this.appsNameSpace = appsNameSpace;
00091 if (masterIcon != null) {
00092 this.masterIconFormat = masterIcon.getFormat();
00093 this.masterIconData = masterIcon.getData().array();
00094 this.masterIconDataOffset = masterIcon.getData().arrayOffset();
00095 this.masterIconDataLength = masterIcon.getData().readableBytes();
00096 }
00097 this.timeLastSeen = timeLastSeen;
00098 }
00099
00100 public void copyFrom(MasterDescription other) {
00101 masterId = other.masterId;
00102 masterName = other.masterName;
00103 masterType = other.masterType;
00104 appsNameSpace = other.appsNameSpace;
00105 masterIconFormat = other.masterIconFormat;
00106 masterIconData = other.masterIconData;
00107 masterIconDataOffset = other.masterIconDataOffset;
00108 masterIconDataLength = other.masterIconDataLength;
00109 connectionStatus = other.connectionStatus;
00110 timeLastSeen = other.timeLastSeen;
00111 }
00112
00113 public MasterId getMasterId() {
00114 return masterId;
00115 }
00116
00117 public String getAppsNameSpace() {
00118 return appsNameSpace;
00119 }
00120
00126 public String getMasterUri() {
00127 return masterId.getMasterUri();
00128 }
00129
00130 public void setMasterId(MasterId masterId) {
00131
00132
00133
00134
00135
00136 this.masterId = masterId;
00137 }
00138
00139 public String getMasterName() {
00140 return masterName;
00141 }
00142
00153 public String getMasterFriendlyName() {
00154 String friendlyName = masterName;
00155
00156 if (masterName.length() > 32) {
00157 String possibleUuidPart = masterName.substring(masterName.length() - 32);
00158 Pattern p = Pattern.compile("[^a-f0-9]");
00159 Matcher m = p.matcher(possibleUuidPart);
00160 if (!m.find()) {
00161 friendlyName = masterName.substring(0, masterName.length() - 32);
00162 }
00163 }
00164 friendlyName = friendlyName.replace('_', ' ');
00165 final StringBuilder result = new StringBuilder(friendlyName.length());
00166 String[] words = friendlyName.split("\\s");
00167 for (int i = 0, l = words.length; i < l; ++i) {
00168 if (i > 0) result.append(" ");
00169 result.append(Character.toUpperCase(words[i].charAt(0)))
00170 .append(words[i].substring(1));
00171 }
00172 return result.toString();
00173 }
00174
00175 public void setMasterName(String masterName) {
00176
00177
00178
00179
00180
00181 this.masterName = masterName;
00182 }
00183
00184 public String getMasterType() {
00185 return masterType;
00186 }
00187
00188 public void setMasterType(String masterType) {
00189 this.masterType = masterType;
00190 }
00191
00192 public String getMasterIconFormat() {
00193 return masterIconFormat;
00194 }
00195
00196 public ChannelBuffer getMasterIconData() {
00197 if (masterIconData == null) {
00198 return null;
00199 } else {
00200 ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(masterIconData, masterIconDataOffset, masterIconDataLength);
00201 return channelBuffer;
00202 }
00203 }
00204
00205 public void setMasterIconFormat(String iconFormat) {
00206 this.masterIconFormat = iconFormat;
00207 }
00208
00209 public void setMasterIconData(ChannelBuffer iconData) {
00210 this.masterIconData = iconData.array();
00211 }
00212
00213 public void setMasterIcon(Icon masterIcon) {
00214 this.masterIconFormat = masterIcon.getFormat();
00215 this.masterIconData = masterIcon.getData().array();
00216 }
00217
00218 public String getConnectionStatus() {
00219 return connectionStatus;
00220 }
00221
00222 public void setConnectionStatus(String connectionStatus) {
00223 this.connectionStatus = connectionStatus;
00224 }
00225
00226 public Date getTimeLastSeen() {
00227 return timeLastSeen;
00228 }
00229
00230 public void setTimeLastSeen(Date timeLastSeen) {
00231 this.timeLastSeen = timeLastSeen;
00232 }
00233
00234 public boolean isUnknown() {
00235 return this.masterName.equals(NAME_UNKNOWN);
00236 }
00237
00238
00239
00240
00241
00242 @Override
00243 public boolean equals(Object o) {
00244
00245
00246 if (this == o) {
00247 return true;
00248 }
00249
00250
00251
00252 if (!(o instanceof MasterDescription)) {
00253 return false;
00254 }
00255
00256
00257
00258 MasterDescription lhs = (MasterDescription) o;
00259
00260
00261
00262 return (masterId == null ? lhs.masterId == null : masterId.equals(lhs.masterId));
00263 }
00264
00265
00266 @Override
00267 public int hashCode() {
00268
00269 int result = 17;
00270
00271 result = 31 * result + (masterId == null ? 0 : masterId.hashCode());
00272 return result;
00273 }
00274 }