00001 /* 00002 * Copyright (C) 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 00005 * use this file except in compliance with the License. You may obtain a copy of 00006 * the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 00013 * License for the specific language governing permissions and limitations under 00014 * the License. 00015 */ 00016 00017 package org.ros.internal.message.service; 00018 00019 import org.ros.internal.message.definition.MessageDefinitionTupleParser; 00020 00021 import org.ros.message.MessageDeclaration; 00022 import org.ros.message.MessageIdentifier; 00023 00024 import java.util.List; 00025 00031 public class ServiceDescription extends MessageDeclaration { 00032 00033 private final String requestType; 00034 private final String requestDefinition; 00035 private final String responseType; 00036 private final String responseDefinition; 00037 private final String md5Checksum; 00038 00039 public ServiceDescription(String type, String definition, String md5Checksum) { 00040 super(MessageIdentifier.of(type), definition); 00041 this.md5Checksum = md5Checksum; 00042 List<String> requestAndResponse = MessageDefinitionTupleParser.parse(definition, 2); 00043 requestType = type + "Request"; 00044 responseType = type + "Response"; 00045 requestDefinition = requestAndResponse.get(0); 00046 responseDefinition = requestAndResponse.get(1); 00047 } 00048 00049 public String getMd5Checksum() { 00050 return md5Checksum; 00051 } 00052 00053 public String getRequestType() { 00054 return requestType; 00055 } 00056 00057 public String getRequestDefinition() { 00058 return requestDefinition; 00059 } 00060 00061 public String getResponseType() { 00062 return responseType; 00063 } 00064 00065 public String getResponseDefinition() { 00066 return responseDefinition; 00067 } 00068 00069 @Override 00070 public String toString() { 00071 return "ServiceDescription<" + getType() + ", " + md5Checksum + ">"; 00072 } 00073 00074 @Override 00075 public int hashCode() { 00076 final int prime = 31; 00077 int result = super.hashCode(); 00078 result = prime * result + ((md5Checksum == null) ? 0 : md5Checksum.hashCode()); 00079 return result; 00080 } 00081 00082 @Override 00083 public boolean equals(Object obj) { 00084 if (this == obj) 00085 return true; 00086 if (!super.equals(obj)) 00087 return false; 00088 if (getClass() != obj.getClass()) 00089 return false; 00090 ServiceDescription other = (ServiceDescription) obj; 00091 if (md5Checksum == null) { 00092 if (other.md5Checksum != null) 00093 return false; 00094 } else if (!md5Checksum.equals(other.md5Checksum)) 00095 return false; 00096 return true; 00097 } 00098 }