00001 /* 00002 * Copyright (C) 2012 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.node.service; 00018 00019 import org.apache.commons.logging.Log; 00020 import org.apache.commons.logging.LogFactory; 00021 import org.ros.internal.node.BaseClientHandshake; 00022 import org.ros.internal.transport.ConnectionHeader; 00023 import org.ros.internal.transport.ConnectionHeaderFields; 00024 00030 public class ServiceClientHandshake extends BaseClientHandshake { 00031 00032 private static final boolean DEBUG = false; 00033 private static final Log log = LogFactory.getLog(ServiceClientHandshake.class); 00034 00035 public ServiceClientHandshake(ConnectionHeader outgoingConnectionHeader) { 00036 super(outgoingConnectionHeader); 00037 } 00038 00039 @Override 00040 public boolean handshake(ConnectionHeader incommingConnectionHeader) { 00041 if (DEBUG) { 00042 log.info("Outgoing service client connection header: " + outgoingConnectionHeader); 00043 log.info("Incoming service server connection header: " + incommingConnectionHeader); 00044 } 00045 setErrorMessage(incommingConnectionHeader.getField(ConnectionHeaderFields.ERROR)); 00046 if (getErrorMessage() != null) { 00047 return false; 00048 } 00049 if (!incommingConnectionHeader.getField(ConnectionHeaderFields.TYPE).equals( 00050 incommingConnectionHeader.getField(ConnectionHeaderFields.TYPE))) { 00051 setErrorMessage("Message types don't match."); 00052 } 00053 if (!incommingConnectionHeader.getField(ConnectionHeaderFields.MD5_CHECKSUM).equals( 00054 incommingConnectionHeader.getField(ConnectionHeaderFields.MD5_CHECKSUM))) { 00055 setErrorMessage("Checksums don't match."); 00056 } 00057 return getErrorMessage() == null; 00058 } 00059 }