├── .classpath ├── .gitignore ├── .project ├── 3rdparty ├── BUILD ├── jvm │ ├── com │ │ └── google │ │ │ ├── code │ │ │ └── findbugs │ │ │ │ └── BUILD │ │ │ └── guava │ │ │ └── BUILD │ ├── commons_pool │ │ └── BUILD │ ├── dnsjava │ │ └── BUILD │ ├── io │ │ └── netty │ │ │ └── BUILD │ ├── junit │ │ └── BUILD │ ├── org │ │ ├── apache │ │ │ ├── commons │ │ │ │ └── BUILD │ │ │ └── ws │ │ │ │ └── commons │ │ │ │ └── BUILD │ │ ├── mockito │ │ │ └── BUILD │ │ └── ros │ │ │ ├── rosjava_bootstrap │ │ │ └── BUILD │ │ │ └── rosjava_messages │ │ │ └── BUILD │ └── xml_apis │ │ └── BUILD └── workspace.bzl ├── CHANGELOG.rst ├── CMakeLists.txt ├── README.md ├── WORKSPACE ├── build.gradle ├── buildscript.gradle ├── dependencies.yaml ├── experiments └── ros-java.gradle ├── gradle.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle_plugins ├── build.gradle └── src │ └── main │ ├── groovy │ └── org │ │ └── ros │ │ └── gradle_plugins │ │ ├── CatkinPlugin.groovy │ │ ├── RosAndroid.groovy │ │ ├── RosJavaPlugin.groovy │ │ └── RosPlugin.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ ├── catkin.properties │ ├── ros-android.properties │ ├── ros-java.properties │ └── ros.properties ├── gradlew ├── gradlew.bat ├── message_generation ├── BUILD.bazel ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── ros │ │ ├── exception │ │ ├── RosMessageRuntimeException.java │ │ └── package-info.java │ │ ├── internal │ │ └── message │ │ │ ├── DefaultMessageDeserializer.java │ │ │ ├── DefaultMessageFactory.java │ │ │ ├── DefaultMessageInterfaceClassProvider.java │ │ │ ├── DefaultMessageSerializationFactory.java │ │ │ ├── DefaultMessageSerializer.java │ │ │ ├── GenerateInterface.java │ │ │ ├── GenerateInterfaces.java │ │ │ ├── GetInstance.java │ │ │ ├── Md5Generator.java │ │ │ ├── Message.java │ │ │ ├── MessageBufferPool.java │ │ │ ├── MessageBuffers.java │ │ │ ├── MessageGenerationTemplate.java │ │ │ ├── MessageImpl.java │ │ │ ├── MessageInterfaceBuilder.java │ │ │ ├── MessageInterfaceClassProvider.java │ │ │ ├── MessageProxyFactory.java │ │ │ ├── MessageProxyInvocationHandler.java │ │ │ ├── RawMessage.java │ │ │ ├── StringFileProvider.java │ │ │ ├── StringResourceProvider.java │ │ │ ├── action │ │ │ ├── ActionDefinitionFileProvider.java │ │ │ ├── ActionGenerationTemplateActionFeedback.java │ │ │ ├── ActionGenerationTemplateActionGoal.java │ │ │ ├── ActionGenerationTemplateActionResult.java │ │ │ ├── ActionGenerationTemplateFeedback.java │ │ │ ├── ActionGenerationTemplateGoal.java │ │ │ ├── ActionGenerationTemplateResult.java │ │ │ └── package-info.java │ │ │ ├── context │ │ │ ├── MessageContext.java │ │ │ ├── MessageContextBuilder.java │ │ │ └── MessageContextProvider.java │ │ │ ├── definition │ │ │ ├── MessageDefinitionFileProvider.java │ │ │ ├── MessageDefinitionParser.java │ │ │ ├── MessageDefinitionProviderChain.java │ │ │ ├── MessageDefinitionReflectionProvider.java │ │ │ └── MessageDefinitionTupleParser.java │ │ │ ├── field │ │ │ ├── BooleanArrayField.java │ │ │ ├── ByteArrayField.java │ │ │ ├── ChannelBufferField.java │ │ │ ├── DoubleArrayField.java │ │ │ ├── Field.java │ │ │ ├── FieldFactory.java │ │ │ ├── FieldType.java │ │ │ ├── FloatArrayField.java │ │ │ ├── IntegerArrayField.java │ │ │ ├── ListField.java │ │ │ ├── LongArrayField.java │ │ │ ├── MessageFieldType.java │ │ │ ├── MessageFields.java │ │ │ ├── PrimitiveFieldType.java │ │ │ ├── ShortArrayField.java │ │ │ └── ValueField.java │ │ │ ├── package-info.java │ │ │ ├── service │ │ │ ├── ServiceDefinitionFileProvider.java │ │ │ ├── ServiceDefinitionResourceProvider.java │ │ │ ├── ServiceDescription.java │ │ │ ├── ServiceDescriptionFactory.java │ │ │ ├── ServiceRequestMessageFactory.java │ │ │ ├── ServiceRequestMessageInterfaceClassProvider.java │ │ │ ├── ServiceResponseMessageFactory.java │ │ │ ├── ServiceResponseMessageInterfaceClassProvider.java │ │ │ └── package-info.java │ │ │ └── topic │ │ │ ├── TopicDefinitionFileProvider.java │ │ │ ├── TopicDefinitionResourceProvider.java │ │ │ ├── TopicDescription.java │ │ │ ├── TopicDescriptionFactory.java │ │ │ ├── TopicMessageFactory.java │ │ │ └── package-info.java │ │ └── message │ │ ├── Duration.java │ │ ├── MessageDeclaration.java │ │ ├── MessageDefinitionProvider.java │ │ ├── MessageDeserializer.java │ │ ├── MessageFactory.java │ │ ├── MessageFactoryProvider.java │ │ ├── MessageIdentifier.java │ │ ├── MessageListener.java │ │ ├── MessageSerializationFactory.java │ │ ├── MessageSerializer.java │ │ ├── Time.java │ │ └── package-info.java │ └── test │ ├── java │ └── org │ │ └── ros │ │ ├── internal │ │ └── message │ │ │ ├── Md5GeneratorTest.java │ │ │ ├── MessageInterfaceBuilderTest.java │ │ │ ├── MessageTest.java │ │ │ ├── RawMessageSerializationTest.java │ │ │ ├── ServiceTest.java │ │ │ └── field │ │ │ └── ArrayFieldTest.java │ │ └── message │ │ ├── DurationTest.java │ │ └── TimeTest.java │ └── resources │ ├── geometry_msgs │ └── msg │ │ ├── Point.msg │ │ ├── Point32.msg │ │ ├── PointStamped.msg │ │ ├── Polygon.msg │ │ ├── PolygonStamped.msg │ │ ├── Pose.msg │ │ ├── Pose2D.msg │ │ ├── PoseArray.msg │ │ ├── PoseStamped.msg │ │ ├── PoseWithCovariance.msg │ │ ├── PoseWithCovarianceStamped.msg │ │ ├── Quaternion.msg │ │ ├── QuaternionStamped.msg │ │ ├── Transform.msg │ │ ├── TransformStamped.msg │ │ ├── Twist.msg │ │ ├── TwistStamped.msg │ │ ├── TwistWithCovariance.msg │ │ ├── TwistWithCovarianceStamped.msg │ │ ├── Vector3.msg │ │ ├── Vector3Stamped.msg │ │ ├── Wrench.msg │ │ └── WrenchStamped.msg │ ├── nav_msgs │ ├── action │ │ └── GetMap.action │ ├── msg │ │ ├── GetMapAction.msg │ │ ├── GetMapActionFeedback.msg │ │ ├── GetMapActionGoal.msg │ │ ├── GetMapActionResult.msg │ │ ├── GetMapFeedback.msg │ │ ├── GetMapGoal.msg │ │ ├── GetMapResult.msg │ │ ├── GridCells.msg │ │ ├── MapMetaData.msg │ │ ├── OccupancyGrid.msg │ │ ├── Odometry.msg │ │ └── Path.msg │ └── srv │ │ ├── GetMap.srv │ │ └── GetPlan.srv │ ├── std_msgs │ └── msg │ │ ├── Bool.msg │ │ ├── Byte.msg │ │ ├── ByteMultiArray.msg │ │ ├── Char.msg │ │ ├── ColorRGBA.msg │ │ ├── Duration.msg │ │ ├── Empty.msg │ │ ├── Float32.msg │ │ ├── Float32MultiArray.msg │ │ ├── Float64.msg │ │ ├── Float64MultiArray.msg │ │ ├── Header.msg │ │ ├── Int16.msg │ │ ├── Int16MultiArray.msg │ │ ├── Int32.msg │ │ ├── Int32MultiArray.msg │ │ ├── Int64.msg │ │ ├── Int64MultiArray.msg │ │ ├── Int8.msg │ │ ├── Int8MultiArray.msg │ │ ├── MultiArrayDimension.msg │ │ ├── MultiArrayLayout.msg │ │ ├── String.msg │ │ ├── Time.msg │ │ ├── UInt16.msg │ │ ├── UInt16MultiArray.msg │ │ ├── UInt32.msg │ │ ├── UInt32MultiArray.msg │ │ ├── UInt64.msg │ │ ├── UInt64MultiArray.msg │ │ ├── UInt8.msg │ │ └── UInt8MultiArray.msg │ ├── std_srvs │ └── srv │ │ └── Empty.srv │ └── test_msgs │ ├── msg │ ├── ArrayVal.msg │ ├── Composite.msg │ ├── CompositeA.msg │ ├── CompositeB.msg │ ├── EmbedTest.msg │ ├── Floats.msg │ ├── HeaderHeaderVal.msg │ ├── HeaderVal.msg │ ├── PythonKeyword.msg │ ├── TestArrays.msg │ ├── TestConstants.msg │ ├── TestFixedArray.msg │ ├── TestHeader.msg │ ├── TestPrimitives.msg │ ├── TestString.msg │ ├── TransitiveImport.msg │ ├── TransitiveMsg1.msg │ ├── TransitiveMsg2.msg │ └── Val.msg │ └── srv │ ├── AddTwoInts.srv │ ├── ConstantsMultiplex.srv │ ├── EmptyReqSrv.srv │ ├── EmptyRespSrv.srv │ ├── EmptySrv.srv │ ├── ListReturn.srv │ ├── MultipleAddTwoInts.srv │ ├── StringString.srv │ └── TransitiveSrv.srv ├── package.xml └── settings.gradle /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build 3 | bin 4 | .project 5 | .classpath 6 | .settings 7 | *.iml 8 | .idea 9 | local.properties 10 | bazel-* 11 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rosjava_bootstrap 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /3rdparty/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rosjava/rosjava_bootstrap/e971dff6284e406067df4c7aa04843ec20c9be54/3rdparty/BUILD -------------------------------------------------------------------------------- /3rdparty/jvm/com/google/code/findbugs/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "jsr305", 4 | exports = [ 5 | "//external:jar/com/google/code/findbugs/jsr305" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/jvm/com/google/guava/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "guava", 4 | exports = [ 5 | "//external:jar/com/google/guava/guava" 6 | ], 7 | runtime_deps = [ 8 | "//3rdparty/jvm/com/google/code/findbugs:jsr305" 9 | ], 10 | visibility = [ 11 | "//visibility:public" 12 | ] 13 | ) 14 | 15 | 16 | -------------------------------------------------------------------------------- /3rdparty/jvm/commons_pool/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "commons_pool", 4 | exports = [ 5 | "//external:jar/commons_pool/commons_pool" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/jvm/dnsjava/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "dnsjava", 4 | exports = [ 5 | "//external:jar/dnsjava/dnsjava" 6 | ], 7 | runtime_deps = [ 8 | "//3rdparty/jvm/junit:junit" 9 | ], 10 | visibility = [ 11 | "//visibility:public" 12 | ] 13 | ) 14 | 15 | 16 | -------------------------------------------------------------------------------- /3rdparty/jvm/io/netty/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "netty", 4 | exports = [ 5 | "//external:jar/io/netty/netty" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/jvm/junit/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "junit", 4 | exports = [ 5 | "//external:jar/junit/junit" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/jvm/org/apache/commons/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "com_springsource_org_apache_commons_codec", 4 | exports = [ 5 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_codec" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | 14 | java_library( 15 | name = "com_springsource_org_apache_commons_httpclient", 16 | exports = [ 17 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_httpclient" 18 | ], 19 | runtime_deps = [ 20 | ":com_springsource_org_apache_commons_codec", 21 | ":com_springsource_org_apache_commons_logging" 22 | ], 23 | visibility = [ 24 | "//visibility:public" 25 | ] 26 | ) 27 | 28 | 29 | 30 | java_library( 31 | name = "com_springsource_org_apache_commons_io", 32 | exports = [ 33 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_io" 34 | ], 35 | visibility = [ 36 | "//visibility:public" 37 | ] 38 | ) 39 | 40 | 41 | 42 | java_library( 43 | name = "com_springsource_org_apache_commons_lang", 44 | exports = [ 45 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_lang" 46 | ], 47 | visibility = [ 48 | "//visibility:public" 49 | ] 50 | ) 51 | 52 | 53 | 54 | java_library( 55 | name = "com_springsource_org_apache_commons_logging", 56 | exports = [ 57 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_logging" 58 | ], 59 | visibility = [ 60 | "//visibility:public" 61 | ] 62 | ) 63 | 64 | 65 | 66 | java_library( 67 | name = "com_springsource_org_apache_commons_net", 68 | exports = [ 69 | "//external:jar/org/apache/commons/com_springsource_org_apache_commons_net" 70 | ], 71 | visibility = [ 72 | "//visibility:public" 73 | ] 74 | ) 75 | 76 | 77 | -------------------------------------------------------------------------------- /3rdparty/jvm/org/apache/ws/commons/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "ws_commons_util", 4 | exports = [ 5 | "//external:jar/org/apache/ws/commons/ws_commons_util" 6 | ], 7 | runtime_deps = [ 8 | "//3rdparty/jvm/junit:junit", 9 | "//3rdparty/jvm/xml_apis:xml_apis" 10 | ], 11 | visibility = [ 12 | "//visibility:public" 13 | ] 14 | ) 15 | 16 | 17 | -------------------------------------------------------------------------------- /3rdparty/jvm/org/mockito/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "mockito_all", 4 | exports = [ 5 | "//external:jar/org/mockito/mockito_all" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/jvm/org/ros/rosjava_bootstrap/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "gradle_plugins", 4 | exports = [ 5 | "//external:jar/org/ros/rosjava_bootstrap/gradle_plugins" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | 14 | java_library( 15 | name = "message_generation", 16 | exports = [ 17 | "//external:jar/org/ros/rosjava_bootstrap/message_generation" 18 | ], 19 | runtime_deps = [ 20 | "//3rdparty/jvm/com/google/guava:guava", 21 | "//3rdparty/jvm/commons_pool:commons_pool", 22 | "//3rdparty/jvm/io/netty:netty", 23 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_codec", 24 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_io", 25 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_lang", 26 | ":gradle_plugins" 27 | ], 28 | visibility = [ 29 | "//visibility:public" 30 | ] 31 | ) 32 | 33 | 34 | -------------------------------------------------------------------------------- /3rdparty/jvm/org/ros/rosjava_messages/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "rosgraph_msgs", 4 | exports = [ 5 | "//external:jar/org/ros/rosjava_messages/rosgraph_msgs" 6 | ], 7 | runtime_deps = [ 8 | "//3rdparty/jvm/org/ros/rosjava_bootstrap:message_generation", 9 | ":std_msgs" 10 | ], 11 | visibility = [ 12 | "//visibility:public" 13 | ] 14 | ) 15 | 16 | 17 | 18 | java_library( 19 | name = "std_msgs", 20 | exports = [ 21 | "//external:jar/org/ros/rosjava_messages/std_msgs" 22 | ], 23 | runtime_deps = [ 24 | "//3rdparty/jvm/org/ros/rosjava_bootstrap:message_generation" 25 | ], 26 | visibility = [ 27 | "//visibility:public" 28 | ] 29 | ) 30 | 31 | 32 | -------------------------------------------------------------------------------- /3rdparty/jvm/xml_apis/BUILD: -------------------------------------------------------------------------------- 1 | # Do not edit. bazel-deps autogenerates this file from dependencies.yaml. 2 | java_library( 3 | name = "xml_apis", 4 | exports = [ 5 | "//external:jar/xml_apis/xml_apis" 6 | ], 7 | visibility = [ 8 | "//visibility:public" 9 | ] 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # CMake 3 | ############################################################################## 4 | 5 | cmake_minimum_required(VERSION 2.8.3) 6 | project(rosjava_bootstrap) 7 | 8 | ############################################################################## 9 | # Catkin 10 | ############################################################################## 11 | 12 | find_package(catkin REQUIRED rosjava_build_tools) 13 | 14 | catkin_rosjava_setup(publish installDist) 15 | 16 | catkin_package() 17 | 18 | ############################################################################## 19 | # Installation 20 | ############################################################################## 21 | 22 | install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/ros/rosjava_bootstrap/ 23 | DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/ros/rosjava_bootstrap) 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | See [rosjava_core](https://github.com/rosjava/rosjava_core) readme. 2 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "com_github_rosjava_rosjava_bootstrap") 2 | 3 | load("//3rdparty:workspace.bzl", "maven_dependencies") 4 | 5 | maven_dependencies() 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | apply from: project.file('gradle.gradle') 18 | 19 | allprojects { 20 | group="org.ros.rosjava_bootstrap" 21 | version = "0.3.3" 22 | } 23 | 24 | subprojects { 25 | apply plugin: 'java' 26 | apply plugin: 'maven' 27 | apply plugin: 'maven-publish' 28 | apply plugin: "idea" 29 | apply plugin: "eclipse" 30 | 31 | sourceCompatibility = 1.6 32 | targetCompatibility = 1.6 33 | 34 | // These external repositories are copied from bootstrap.gradle. 35 | repositories { 36 | jcenter() 37 | maven { 38 | url "http://repository.springsource.com/maven/bundles/release" 39 | } 40 | maven { 41 | url "http://repository.springsource.com/maven/bundles/external" 42 | } 43 | } 44 | 45 | // Configuration of the deployment repository is copied from the RosPlugin. 46 | String mavenDeploymentRepository = System.getenv("ROS_MAVEN_DEPLOYMENT_REPOSITORY") 47 | if (mavenDeploymentRepository != null && 48 | mavenDeploymentRepository != "") { 49 | publishing { 50 | publications { 51 | mavenJava(MavenPublication) { 52 | from components.java 53 | } 54 | } 55 | repositories { 56 | maven { 57 | url 'file://' + mavenDeploymentRepository 58 | } 59 | } 60 | } 61 | } else { 62 | logger.warn("ROS_MAVEN_DEPLOYMENT_REPOSITORY is not set. Have you sourced setup.bash?") 63 | } 64 | } 65 | 66 | defaultTasks 'publish', 'installDist' 67 | -------------------------------------------------------------------------------- /buildscript.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | rootProject.buildscript { 18 | String rosMavenPath = System.getenv("ROS_MAVEN_PATH") 19 | String rosMavenRepository = System.getenv("ROS_MAVEN_REPOSITORY") 20 | repositories { 21 | if (rosMavenPath != null) { 22 | rosMavenPath.tokenize(":").each { path -> 23 | maven { 24 | // We can't use uri() here because we aren't running inside something 25 | // that implements the Script interface. 26 | url "file:${path}" 27 | } 28 | } 29 | } 30 | maven { 31 | url "http://repository.springsource.com/maven/bundles/release" 32 | } 33 | maven { 34 | url "http://repository.springsource.com/maven/bundles/external" 35 | } 36 | if (rosMavenRepository != null) { 37 | maven { 38 | url rosMavenRepository 39 | } 40 | } 41 | maven { 42 | url "https://github.com/rosjava/rosjava_mvn_repo/raw/master" 43 | } 44 | google() 45 | jcenter() 46 | } 47 | dependencies { 48 | classpath "org.ros.rosjava_bootstrap:gradle_plugins:[0.3,0.4)" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dependencies.yaml: -------------------------------------------------------------------------------- 1 | # If you edit this file, follow these instructions to generate the output 2 | # files: 3 | # 4 | # cd .. 5 | # git clone https://github.com/johnynek/bazel-deps 6 | # cd bazel-deps 7 | # bazel build src/scala/com/github/johnynek/bazel_deps:parseproject_deploy.jar 8 | # cd ../rosjava_bootstrap 9 | # ../bazel-deps/gen_maven_deps.sh generate -r $PWD -s 3rdparty/workspace.bzl -d dependencies.yaml 10 | 11 | options: 12 | languages: [ "java" ] 13 | resolvers: 14 | - id: "jcenter" 15 | type: "default" 16 | url: https://jcenter.bintray.com/ 17 | - id: "rosjava_mvn_repo" 18 | type: "default" 19 | url: https://github.com/rosjava/rosjava_mvn_repo/raw/master 20 | resolverCache: bazel_output_base 21 | transitivity: runtime_deps 22 | versionConflictPolicy: highest 23 | buildHeader: 24 | - "# Do not edit. bazel-deps autogenerates this file from dependencies.yaml." 25 | 26 | dependencies: 27 | commons-pool: 28 | commons-pool: 29 | lang: java 30 | version: "1.6" 31 | com.google.guava: 32 | guava: 33 | lang: java 34 | version: "12.0" 35 | dnsjava: 36 | dnsjava: 37 | lang: java 38 | version: "2.1.1" 39 | io.netty: 40 | netty: 41 | lang: java 42 | version: "3.5.13.Final" 43 | junit: 44 | junit: 45 | lang: java 46 | version: "4.8.2" 47 | org.apache.commons: 48 | com.springsource.org.apache.commons.codec: 49 | lang: java 50 | version: "1.3.0" 51 | com.springsource.org.apache.commons.httpclient: 52 | lang: java 53 | version: "3.1.0" 54 | com.springsource.org.apache.commons.io: 55 | lang: java 56 | version: "1.4.0" 57 | com.springsource.org.apache.commons.lang: 58 | lang: java 59 | version: "2.4.0" 60 | com.springsource.org.apache.commons.logging: 61 | lang: java 62 | version: "1.1.1" 63 | com.springsource.org.apache.commons.net: 64 | lang: java 65 | version: "2.0.0" 66 | org.apache.ws.commons: 67 | ws-commons-util: 68 | lang: java 69 | version: "1.0.1" 70 | org.mockito: 71 | mockito-all: 72 | lang: java 73 | version: "1.8.5" 74 | org.ros.rosjava_messages: 75 | rosgraph_msgs: 76 | lang: java 77 | version: "1.11.2" 78 | std_msgs: 79 | lang: java 80 | version: "0.5.11" 81 | -------------------------------------------------------------------------------- /gradle.gradle: -------------------------------------------------------------------------------- 1 | task wrapper(type: Wrapper) { 2 | gradleVersion = '4.10.2' 3 | } 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon=true 2 | # Fixes "handshake alert: unrecognized_name" error in Java 7. 3 | org.gradle.jvmargs=-Djsse.enableSNIExtension=false 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rosjava/rosjava_bootstrap/e971dff6284e406067df4c7aa04843ec20c9be54/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradle_plugins/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | apply plugin: 'groovy' 18 | 19 | //noinspection GroovyAssignabilityCheck 20 | dependencies { 21 | compile gradleApi() 22 | compile localGroovy() 23 | } 24 | -------------------------------------------------------------------------------- /gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosAndroid.groovy: -------------------------------------------------------------------------------- 1 | package org.ros.gradle_plugins; 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.Plugin 5 | import java.util.HashMap 6 | 7 | /** 8 | * Configures ROS on Android build environment. 9 | */ 10 | class RosAndroidPlugin implements Plugin { 11 | void apply(Project project) { 12 | project.apply plugin: "ros" 13 | project.extensions.create("rosandroid", RosAndroidPluginExtension) 14 | project.rosandroid.buildToolsVersion = "28.0.3" 15 | 16 | /********************************************************************** 17 | * Publishing - not we're using old style here. Upgrade to maven-publish 18 | * once they have support: 19 | * https://github.com/rosjava/rosjava_bootstrap/issues/1 20 | * This is specifically for releasing and working in a ros workspace. 21 | **********************************************************************/ 22 | project.uploadArchives { 23 | repositories.mavenDeployer { 24 | repository(url: 'file://' + project.ros.mavenDeploymentRepository) 25 | } 26 | } 27 | /********************************************************************** 28 | * Our maven repo 3rd parties are currently incompatible with android 29 | * junit especially could use a look at - find a compatible version! 30 | **********************************************************************/ 31 | project.configurations.maybeCreate("compile") 32 | project.configurations.compile.exclude "group": "junit" 33 | project.configurations.compile.exclude "group": "xml-apis" 34 | /********************************************************************** 35 | * Delay android plugin configuration because that will depend on 36 | * the subproject's late loading of android or android-library plugin. 37 | **********************************************************************/ 38 | project.afterEvaluate { 39 | project.android { 40 | buildToolsVersion project.rosandroid.buildToolsVersion 41 | } 42 | } 43 | } 44 | } 45 | 46 | class RosAndroidPluginExtension { 47 | String buildToolsVersion 48 | } 49 | -------------------------------------------------------------------------------- /gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosJavaPlugin.groovy: -------------------------------------------------------------------------------- 1 | package org.ros.gradle_plugins; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.api.Plugin; 5 | import org.gradle.api.publish.maven.MavenPublication; 6 | import org.gradle.api.*; 7 | 8 | /* 9 | * Configures java for the ros build environment. Pretty elementary right now, 10 | * just applies the java plugin and defines the jdk compatibility level. 11 | */ 12 | class RosJavaPlugin implements Plugin { 13 | Project project 14 | 15 | def void apply(Project project) { 16 | this.project = project 17 | if (!project.plugins.findPlugin('ros')) { 18 | project.apply(plugin: 'ros') 19 | } 20 | if (!project.plugins.findPlugin('java')) { 21 | project.apply(plugin: 'java') 22 | } 23 | if (!project.plugins.findPlugin('maven-publish')) { 24 | project.apply(plugin: 'maven-publish') 25 | } 26 | 27 | project.sourceCompatibility = 1.7 28 | project.targetCompatibility = 1.7 29 | 30 | if ( project.ros.mavenDeploymentRepository != 'null' && project.ros.mavenDeploymentRepository != '' ) { 31 | project.publishing { 32 | publications { 33 | mavenJava(MavenPublication) { 34 | from project.components.java 35 | } 36 | } 37 | repositories { 38 | maven { 39 | url 'file://' + project.ros.mavenDeploymentRepository 40 | } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | 47 | class RosJavaPluginExtension { 48 | String maven 49 | } 50 | -------------------------------------------------------------------------------- /gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosPlugin.groovy: -------------------------------------------------------------------------------- 1 | package org.ros.gradle_plugins; 2 | 3 | import org.gradle.api.*; 4 | import org.gradle.api.publish.maven.MavenPublication; 5 | 6 | /** 7 | * Configures a Java project for use with ROS. 8 | * 9 | * - project.ros.mavenPath : location of local ros maven repositories (in your chained workspaces) 10 | * - project.ros.mavenDeploymentRepository : location of the ros maven repository you will publish to 11 | * 12 | * It also performs the following actions 13 | * 14 | * - checks and makes sure the maven plugin is running 15 | * - constructs the sequence of dependent maven repos (local ros maven repos, mavenLocal, external ros maven repo) 16 | * - configures the uploadArchives for artifact deployment to the local ros maven repo (devel/share/maven) 17 | */ 18 | class RosPlugin implements Plugin { 19 | 20 | def void apply(Project project) { 21 | project.apply plugin: "maven" 22 | 23 | project.extensions.create("ros", RosPluginExtension) 24 | 25 | project.ros.mavenRepository = System.getenv("ROS_MAVEN_REPOSITORY") 26 | project.ros.mavenDeploymentRepository = System.getenv("ROS_MAVEN_DEPLOYMENT_REPOSITORY") 27 | String mavenPath = System.getenv("ROS_MAVEN_PATH") 28 | if (mavenPath != null) { 29 | project.ros.mavenPath = mavenPath.tokenize(":") 30 | } 31 | project.repositories { 32 | if (project.ros.mavenPath != null) { 33 | project.ros.mavenPath.each { path -> 34 | maven { 35 | url project.uri(path) 36 | } 37 | } 38 | } 39 | if (project.ros.mavenRepository != null) { 40 | maven { 41 | url project.ros.mavenRepository 42 | } 43 | } 44 | /* 45 | * This will often be the same as ROS_MAVEN_REPOSITORY, but this way it lets a user 46 | * provide a repository of their own via the environment variable and use this as a fallback. 47 | */ 48 | maven { 49 | url "https://github.com/rosjava/rosjava_mvn_repo/raw/master" 50 | } 51 | mavenLocal() 52 | maven { 53 | url "http://repository.springsource.com/maven/bundles/release" 54 | } 55 | maven { 56 | url "http://repository.springsource.com/maven/bundles/external" 57 | } 58 | jcenter() 59 | } 60 | } 61 | } 62 | 63 | /* http://www.gradle.org/docs/nightly/dsl/org.gradle.api.plugins.ExtensionAware.html */ 64 | class RosPluginExtension { 65 | String mavenRepository 66 | String mavenDeploymentRepository 67 | List mavenPath 68 | 69 | RosPluginExtension() { 70 | /* Initialising the strings here gets rid of the dynamic property deprecated warnings. */ 71 | this.mavenDeploymentRepository = "" 72 | this.mavenRepository = "" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /gradle_plugins/src/main/resources/META-INF/gradle-plugins/catkin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.ros.gradle_plugins.CatkinPlugin -------------------------------------------------------------------------------- /gradle_plugins/src/main/resources/META-INF/gradle-plugins/ros-android.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.ros.gradle_plugins.RosAndroidPlugin -------------------------------------------------------------------------------- /gradle_plugins/src/main/resources/META-INF/gradle-plugins/ros-java.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.ros.gradle_plugins.RosJavaPlugin -------------------------------------------------------------------------------- /gradle_plugins/src/main/resources/META-INF/gradle-plugins/ros.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.ros.gradle_plugins.RosPlugin -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /message_generation/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | java_library( 4 | name = "message_generation", 5 | srcs = glob([ 6 | "src/main/**/*.java", 7 | ]), 8 | deps = [ 9 | "//3rdparty/jvm/com/google/guava", 10 | "//3rdparty/jvm/commons_pool", 11 | "//3rdparty/jvm/io/netty", 12 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_codec", 13 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_io", 14 | "//3rdparty/jvm/org/apache/commons:com_springsource_org_apache_commons_lang", 15 | ], 16 | ) 17 | 18 | java_test( 19 | name = "ArrayFieldTest", 20 | size = "small", 21 | srcs = ["src/test/java/org/ros/internal/message/field/ArrayFieldTest.java"], 22 | deps = [ 23 | ":message_generation", 24 | "//3rdparty/jvm/io/netty", 25 | "//3rdparty/jvm/junit", 26 | ], 27 | ) 28 | 29 | java_test( 30 | name = "MessageInterfaceBuilderTest", 31 | size = "small", 32 | srcs = ["src/test/java/org/ros/internal/message/MessageInterfaceBuilderTest.java"], 33 | deps = [ 34 | ":message_generation", 35 | "//3rdparty/jvm/junit", 36 | ], 37 | ) 38 | 39 | java_test( 40 | name = "Md5GeneratorTest", 41 | size = "small", 42 | srcs = ["src/test/java/org/ros/internal/message/Md5GeneratorTest.java"], 43 | resources = glob(["src/test/resources/**/*"]), 44 | deps = [ 45 | ":message_generation", 46 | "//3rdparty/jvm/junit", 47 | ], 48 | ) 49 | 50 | java_test( 51 | name = "MessageTest", 52 | size = "small", 53 | srcs = ["src/test/java/org/ros/internal/message/MessageTest.java"], 54 | resources = glob(["src/test/resources/**/*"]), 55 | deps = [ 56 | ":message_generation", 57 | "//3rdparty/jvm/com/google/guava", 58 | "//3rdparty/jvm/junit", 59 | ], 60 | ) 61 | 62 | java_test( 63 | name = "RawMessageSerializationTest", 64 | size = "small", 65 | srcs = ["src/test/java/org/ros/internal/message/RawMessageSerializationTest.java"], 66 | resources = glob(["src/test/resources/**/*"]), 67 | deps = [ 68 | ":message_generation", 69 | "//3rdparty/jvm/com/google/guava", 70 | "//3rdparty/jvm/io/netty", 71 | "//3rdparty/jvm/junit", 72 | ], 73 | ) 74 | 75 | java_test( 76 | name = "ServiceTest", 77 | size = "small", 78 | srcs = ["src/test/java/org/ros/internal/message/ServiceTest.java"], 79 | deps = [ 80 | ":message_generation", 81 | "//3rdparty/jvm/junit", 82 | ], 83 | ) 84 | 85 | java_test( 86 | name = "DurationTest", 87 | size = "small", 88 | srcs = ["src/test/java/org/ros/message/DurationTest.java"], 89 | deps = [ 90 | ":message_generation", 91 | "//3rdparty/jvm/junit", 92 | ], 93 | ) 94 | 95 | java_test( 96 | name = "TimeTest", 97 | size = "small", 98 | srcs = ["src/test/java/org/ros/message/TimeTest.java"], 99 | deps = [ 100 | ":message_generation", 101 | "//3rdparty/jvm/junit", 102 | ], 103 | ) 104 | -------------------------------------------------------------------------------- /message_generation/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /* Shift to mavenCentral apache artifacts (currently rosajva_mvn_repo) when ready 18 | * Currently we have conflicts when dexing android executables since there is a 19 | * mix of mavenCentral/springsource providers. 20 | * 21 | * https://github.com/rosjava/rosjava_bootstrap/issues/40#issuecomment-75043854 22 | */ 23 | /* 24 | compile 'org.apache.directory.studio:org.apache.commons.codec:1.8' 25 | compile 'org.apache.directory.studio:org.apache.commons.io:2.4' 26 | compile 'org.apache.directory.studio:org.apache.commons.lang:2.6' 27 | */ 28 | 29 | //noinspection GroovyAssignabilityCheck 30 | dependencies { 31 | compile 'io.netty:netty:3.5.2.Final' 32 | compile 'com.google.guava:guava:12.0' 33 | compile 'org.apache.commons:com.springsource.org.apache.commons.codec:1.3.0' 34 | compile 'org.apache.commons:com.springsource.org.apache.commons.io:1.4.0' 35 | compile 'commons-pool:commons-pool:1.6' 36 | compile 'org.apache.commons:com.springsource.org.apache.commons.lang:2.4.0' 37 | compile project(':gradle_plugins') 38 | testCompile 'junit:junit:4.8.2' 39 | } 40 | 41 | apply plugin: "application" 42 | 43 | //noinspection GroovyUnusedAssignment 44 | mainClassName = "org.ros.internal.message.GenerateInterfaces" 45 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/exception/RosMessageRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.exception; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | * @author d.stonier@gmail.com (Daniel Stonier) 22 | */ 23 | public class RosMessageRuntimeException extends RuntimeException { 24 | 25 | public RosMessageRuntimeException(final Throwable throwable) { 26 | super(throwable); 27 | } 28 | 29 | public RosMessageRuntimeException(final String message, final Throwable throwable) { 30 | super(message, throwable); 31 | } 32 | 33 | public RosMessageRuntimeException(final String message) { 34 | super(message); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides the classes for representing common rosjava exceptions. 19 | */ 20 | package org.ros.exception; -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/DefaultMessageDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | import org.ros.internal.message.field.Field; 21 | import org.ros.message.MessageDeserializer; 22 | import org.ros.message.MessageFactory; 23 | import org.ros.message.MessageIdentifier; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class DefaultMessageDeserializer implements MessageDeserializer { 29 | 30 | private final MessageIdentifier messageIdentifier; 31 | private final MessageFactory messageFactory; 32 | 33 | public DefaultMessageDeserializer(MessageIdentifier messageIdentifier, 34 | MessageFactory messageFactory) { 35 | this.messageIdentifier = messageIdentifier; 36 | this.messageFactory = messageFactory; 37 | } 38 | 39 | @SuppressWarnings("unchecked") 40 | @Override 41 | public T deserialize(ChannelBuffer buffer) { 42 | Message message = messageFactory.newFromType(messageIdentifier.getType()); 43 | for (Field field : message.toRawMessage().getFields()) { 44 | if (!field.isConstant()) { 45 | field.deserialize(buffer); 46 | } 47 | } 48 | return (T) message; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/DefaultMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import com.google.common.annotations.VisibleForTesting; 20 | 21 | import org.ros.message.MessageDeclaration; 22 | import org.ros.message.MessageDefinitionProvider; 23 | import org.ros.message.MessageFactory; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class DefaultMessageFactory implements MessageFactory { 29 | 30 | private final MessageDefinitionProvider messageDefinitionProvider; 31 | private final DefaultMessageInterfaceClassProvider messageInterfaceClassProvider; 32 | private final MessageProxyFactory messageProxyFactory; 33 | 34 | public DefaultMessageFactory(MessageDefinitionProvider messageDefinitionProvider) { 35 | this.messageDefinitionProvider = messageDefinitionProvider; 36 | messageInterfaceClassProvider = new DefaultMessageInterfaceClassProvider(); 37 | messageProxyFactory = new MessageProxyFactory(getMessageInterfaceClassProvider(), this); 38 | } 39 | 40 | @Override 41 | public T newFromType(String messageType) { 42 | String messageDefinition = messageDefinitionProvider.get(messageType); 43 | MessageDeclaration messageDeclaration = MessageDeclaration.of(messageType, messageDefinition); 44 | return messageProxyFactory.newMessageProxy(messageDeclaration); 45 | } 46 | 47 | @VisibleForTesting 48 | DefaultMessageInterfaceClassProvider getMessageInterfaceClassProvider() { 49 | return messageInterfaceClassProvider; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/DefaultMessageInterfaceClassProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import com.google.common.annotations.VisibleForTesting; 20 | import com.google.common.collect.Maps; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * @author damonkohler@google.com (Damon Kohler) 26 | */ 27 | public class DefaultMessageInterfaceClassProvider implements MessageInterfaceClassProvider { 28 | 29 | private final Map> cache; 30 | 31 | public DefaultMessageInterfaceClassProvider() { 32 | cache = Maps.newConcurrentMap(); 33 | } 34 | 35 | @SuppressWarnings("unchecked") 36 | @Override 37 | public Class get(String messageType) { 38 | if (cache.containsKey(messageType)) { 39 | return (Class) cache.get(messageType); 40 | } 41 | try { 42 | String className = messageType.replace("/", "."); 43 | Class messageInterfaceClass = (Class) getClass().getClassLoader().loadClass(className); 44 | cache.put(messageType, messageInterfaceClass); 45 | return messageInterfaceClass; 46 | } catch (ClassNotFoundException e) { 47 | return (Class) RawMessage.class; 48 | } 49 | } 50 | 51 | @VisibleForTesting 52 | void add(String messageType, Class messageInterfaceClass) { 53 | cache.put(messageType, messageInterfaceClass); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/DefaultMessageSerializationFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.ros.internal.message.service.ServiceRequestMessageFactory; 20 | import org.ros.internal.message.service.ServiceResponseMessageFactory; 21 | import org.ros.message.MessageDefinitionProvider; 22 | import org.ros.message.MessageDeserializer; 23 | import org.ros.message.MessageFactory; 24 | import org.ros.message.MessageIdentifier; 25 | import org.ros.message.MessageSerializationFactory; 26 | import org.ros.message.MessageSerializer; 27 | 28 | /** 29 | * @author damonkohler@google.com (Damon Kohler) 30 | */ 31 | public class DefaultMessageSerializationFactory implements MessageSerializationFactory { 32 | 33 | private final MessageFactory topicMessageFactory; 34 | private final ServiceRequestMessageFactory serviceRequestMessageFactory; 35 | private final ServiceResponseMessageFactory serviceResponseMessageFactory; 36 | 37 | public DefaultMessageSerializationFactory(MessageDefinitionProvider messageDefinitionProvider) { 38 | topicMessageFactory = new DefaultMessageFactory(messageDefinitionProvider); 39 | serviceRequestMessageFactory = new ServiceRequestMessageFactory(messageDefinitionProvider); 40 | serviceResponseMessageFactory = new ServiceResponseMessageFactory(messageDefinitionProvider); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public MessageSerializer newMessageSerializer(String messageType) { 46 | return (MessageSerializer) new DefaultMessageSerializer(); 47 | } 48 | 49 | @Override 50 | public MessageDeserializer newMessageDeserializer(String messageType) { 51 | return new DefaultMessageDeserializer(MessageIdentifier.of(messageType), 52 | topicMessageFactory); 53 | } 54 | 55 | @SuppressWarnings("unchecked") 56 | @Override 57 | public MessageSerializer newServiceRequestSerializer(String serviceType) { 58 | return (MessageSerializer) new DefaultMessageSerializer(); 59 | } 60 | 61 | @Override 62 | public org.ros.message.MessageDeserializer 63 | newServiceRequestDeserializer(String serviceType) { 64 | return new DefaultMessageDeserializer(MessageIdentifier.of(serviceType), 65 | serviceRequestMessageFactory); 66 | } 67 | 68 | @SuppressWarnings("unchecked") 69 | @Override 70 | public org.ros.message.MessageSerializer newServiceResponseSerializer(String serviceType) { 71 | return (MessageSerializer) new DefaultMessageSerializer(); 72 | } 73 | 74 | @Override 75 | public org.ros.message.MessageDeserializer newServiceResponseDeserializer( 76 | String serviceType) { 77 | return new DefaultMessageDeserializer(MessageIdentifier.of(serviceType), 78 | serviceResponseMessageFactory); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/DefaultMessageSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | import org.ros.internal.message.field.Field; 21 | import org.ros.message.MessageSerializer; 22 | 23 | /** 24 | * @author damonkohler@google.com (Damon Kohler) 25 | */ 26 | public class DefaultMessageSerializer implements MessageSerializer { 27 | 28 | @Override 29 | public void serialize(Message message, ChannelBuffer buffer) { 30 | for (Field field : message.toRawMessage().getFields()) { 31 | if (!field.isConstant()) { 32 | field.serialize(buffer); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/GetInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | interface GetInstance { 23 | 24 | public Object getInstance(); 25 | } 26 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | public interface Message { 23 | 24 | /** 25 | * @return returns this {@link Message} as a {@link RawMessage} 26 | */ 27 | RawMessage toRawMessage(); 28 | } 29 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageBufferPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.apache.commons.pool.ObjectPool; 20 | import org.apache.commons.pool.PoolableObjectFactory; 21 | import org.apache.commons.pool.impl.StackObjectPool; 22 | import org.jboss.netty.buffer.ChannelBuffer; 23 | import org.ros.exception.RosMessageRuntimeException; 24 | 25 | /** 26 | * A pool of {@link ChannelBuffer}s for serializing and deserializing messages. 27 | *

28 | * By contract, {@link ChannelBuffer}s provided by {@link #acquire()} must be 29 | * returned using {@link #release(ChannelBuffer)}. 30 | * 31 | * @author damonkohler@google.com (Damon Kohler) 32 | */ 33 | public class MessageBufferPool { 34 | 35 | private final ObjectPool pool; 36 | 37 | public MessageBufferPool() { 38 | pool = new StackObjectPool(new PoolableObjectFactory() { 39 | @Override 40 | public ChannelBuffer makeObject() throws Exception { 41 | return MessageBuffers.dynamicBuffer(); 42 | } 43 | 44 | @Override 45 | public void destroyObject(ChannelBuffer channelBuffer) throws Exception { 46 | } 47 | 48 | @Override 49 | public boolean validateObject(ChannelBuffer channelBuffer) { 50 | return true; 51 | } 52 | 53 | @Override 54 | public void activateObject(ChannelBuffer channelBuffer) throws Exception { 55 | } 56 | 57 | @Override 58 | public void passivateObject(ChannelBuffer channelBuffer) throws Exception { 59 | channelBuffer.clear(); 60 | } 61 | }); 62 | } 63 | 64 | /** 65 | * Acquired {@link ChannelBuffer}s must be returned using 66 | * {@link #release(ChannelBuffer)}. 67 | * 68 | * @return an unused {@link ChannelBuffer} 69 | */ 70 | public ChannelBuffer acquire() { 71 | try { 72 | return pool.borrowObject(); 73 | } catch (Exception e) { 74 | throw new RosMessageRuntimeException(e); 75 | } 76 | } 77 | 78 | /** 79 | * Release a previously acquired {@link ChannelBuffer}. 80 | * 81 | * @param channelBuffer 82 | * the {@link ChannelBuffer} to release 83 | */ 84 | public void release(ChannelBuffer channelBuffer) { 85 | try { 86 | pool.returnObject(channelBuffer); 87 | } catch (Exception e) { 88 | throw new RosMessageRuntimeException(e); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageBuffers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | import org.jboss.netty.buffer.ChannelBuffers; 21 | 22 | import java.nio.ByteOrder; 23 | 24 | /** 25 | * Provides {@link ChannelBuffer}s for serializing and deserializing messages. 26 | * 27 | * @author damonkohler@google.com (Damon Kohler) 28 | */ 29 | public class MessageBuffers { 30 | 31 | static final int ESTIMATED_LENGTH = 256; 32 | 33 | private MessageBuffers() { 34 | // Utility class. 35 | } 36 | 37 | /** 38 | * @return a new {@link ChannelBuffer} for {@link Message} serialization that 39 | * grows dynamically 40 | */ 41 | public static ChannelBuffer dynamicBuffer() { 42 | return ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, ESTIMATED_LENGTH); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageGenerationTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | /** 20 | * @author arne.peters@tum.de (Arne Peters) 21 | */ 22 | public interface MessageGenerationTemplate { 23 | 24 | /** 25 | * @return returns this {@link Message} as a {@link RawMessage} 26 | */ 27 | public String applyTemplate(String messageSource); 28 | } 29 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageInterfaceClassProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | public interface MessageInterfaceClassProvider { 23 | 24 | /** 25 | * @param 26 | * the message interface class type 27 | * @param messageType 28 | * the type of message to provide an interface class for 29 | * @return the interface class for the specified message type 30 | */ 31 | Class get(String messageType); 32 | } 33 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageProxyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.ros.internal.message.context.MessageContext; 22 | import org.ros.internal.message.context.MessageContextProvider; 23 | import org.ros.message.MessageDeclaration; 24 | import org.ros.message.MessageFactory; 25 | 26 | import java.lang.reflect.Proxy; 27 | import java.util.concurrent.atomic.AtomicInteger; 28 | 29 | /** 30 | * @author damonkohler@google.com (Damon Kohler) 31 | */ 32 | public class MessageProxyFactory { 33 | 34 | // We can't use the constant here since the rosjava_messages package depends 35 | // on rosjava_bootstrap. 36 | private static final String HEADER_MESSAGE_TYPE = "std_msgs/Header"; 37 | private static final String SEQUENCE_FIELD_NAME = "seq"; 38 | private static final AtomicInteger SEQUENCE_NUMBER = new AtomicInteger(0); 39 | 40 | private final MessageInterfaceClassProvider messageInterfaceClassProvider; 41 | private final MessageContextProvider messageContextProvider; 42 | 43 | public MessageProxyFactory(MessageInterfaceClassProvider messageInterfaceClassProvider, 44 | MessageFactory messageFactory) { 45 | this.messageInterfaceClassProvider = messageInterfaceClassProvider; 46 | messageContextProvider = new MessageContextProvider(messageFactory); 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | public T newMessageProxy(MessageDeclaration messageDeclaration) { 51 | Preconditions.checkNotNull(messageDeclaration); 52 | MessageContext messageContext = messageContextProvider.get(messageDeclaration); 53 | MessageImpl messageImpl = new MessageImpl(messageContext); 54 | // Header messages are automatically populated with a monotonically 55 | // increasing sequence number. 56 | if (messageImpl.getType().equals(HEADER_MESSAGE_TYPE)) { 57 | messageImpl.setUInt32(SEQUENCE_FIELD_NAME, SEQUENCE_NUMBER.getAndIncrement()); 58 | } 59 | Class messageInterfaceClass = 60 | (Class) messageInterfaceClassProvider.get(messageDeclaration.getType()); 61 | return newProxy(messageInterfaceClass, messageImpl); 62 | } 63 | 64 | /** 65 | * @param interfaceClass 66 | * the interface class to provide 67 | * @param messageImpl 68 | * the instance to proxy 69 | * @return a new proxy for {@code implementation} that implements 70 | * {@code interfaceClass} 71 | */ 72 | @SuppressWarnings("unchecked") 73 | private T newProxy(Class interfaceClass, final MessageImpl messageImpl) { 74 | ClassLoader classLoader = messageImpl.getClass().getClassLoader(); 75 | Class[] interfaces = new Class[] { interfaceClass, GetInstance.class }; 76 | MessageProxyInvocationHandler invocationHandler = 77 | new MessageProxyInvocationHandler(messageImpl); 78 | return (T) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/MessageProxyInvocationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.ros.internal.message.field.Field; 20 | import org.ros.internal.message.field.MessageFields; 21 | 22 | import java.lang.reflect.InvocationHandler; 23 | import java.lang.reflect.Method; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class MessageProxyInvocationHandler implements InvocationHandler { 29 | 30 | private final MessageImpl messageImpl; 31 | 32 | MessageProxyInvocationHandler(MessageImpl messageImpl) { 33 | this.messageImpl = messageImpl; 34 | } 35 | 36 | @Override 37 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 38 | String methodName = method.getName(); 39 | MessageFields mesageFields = messageImpl.getMessageFields(); 40 | Field getterField = mesageFields.getGetterField(methodName); 41 | if (getterField != null) { 42 | return getterField.getValue(); 43 | } 44 | Field setterField = mesageFields.getSetterField(methodName); 45 | if (setterField != null) { 46 | setterField.setValue(args[0]); 47 | return null; 48 | } 49 | return method.invoke(messageImpl, args); 50 | } 51 | } -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/StringResourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import com.google.common.collect.ImmutableMap; 20 | import com.google.common.collect.Maps; 21 | 22 | import org.ros.exception.RosMessageRuntimeException; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.nio.charset.Charset; 27 | import java.util.Map; 28 | import java.util.NoSuchElementException; 29 | 30 | /** 31 | * @author damonkohler@google.com (Damon Kohler) 32 | */ 33 | public class StringResourceProvider { 34 | 35 | private final Map cache; 36 | 37 | public StringResourceProvider() { 38 | cache = Maps.newConcurrentMap(); 39 | } 40 | 41 | public String get(String resourceName) { 42 | if (!has(resourceName)) { 43 | throw new NoSuchElementException("Resource does not exist: " + resourceName); 44 | } 45 | if (!cache.containsKey(resourceName)) { 46 | InputStream in = getClass().getResourceAsStream(resourceName); 47 | StringBuilder out = new StringBuilder(); 48 | Charset charset = Charset.forName("US-ASCII"); 49 | byte[] buffer = new byte[8192]; 50 | try { 51 | for (int bytesRead; (bytesRead = in.read(buffer)) != -1;) { 52 | out.append(new String(buffer, 0, bytesRead, charset)); 53 | } 54 | } catch (IOException e) { 55 | throw new RosMessageRuntimeException("Failed to read resource: " + resourceName, e); 56 | } 57 | cache.put(resourceName, out.toString()); 58 | } 59 | return cache.get(resourceName); 60 | } 61 | 62 | public boolean has(String resourceName) { 63 | return cache.containsKey(resourceName) || getClass().getResource(resourceName) != null; 64 | } 65 | 66 | public Map getCachedStrings() { 67 | return ImmutableMap.copyOf(cache); 68 | } 69 | 70 | public void addStringToCache(String resourceName, String resourceContent) { 71 | cache.put(resourceName, resourceContent); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionDefinitionFileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.definition.MessageDefinitionFileProvider; 20 | 21 | import org.apache.commons.io.filefilter.FileFilterUtils; 22 | import org.apache.commons.io.filefilter.IOFileFilter; 23 | import org.ros.internal.message.StringFileProvider; 24 | 25 | import java.io.File; 26 | import java.io.FileFilter; 27 | 28 | /** 29 | * @author arne.peters@tum.de (Arne Peters) 30 | */ 31 | public class ActionDefinitionFileProvider extends MessageDefinitionFileProvider { 32 | 33 | private static final String PARENT = "action"; 34 | private static final String SUFFIX = "action"; 35 | 36 | private static StringFileProvider newStringFileProvider() { 37 | IOFileFilter extensionFilter = FileFilterUtils.suffixFileFilter(SUFFIX); 38 | IOFileFilter parentBaseNameFilter = FileFilterUtils.asFileFilter(new FileFilter() { 39 | @Override 40 | public boolean accept(File file) { 41 | return getParentBaseName(file.getAbsolutePath()).equals(PARENT); 42 | } 43 | }); 44 | IOFileFilter fileFilter = FileFilterUtils.andFileFilter(extensionFilter, parentBaseNameFilter); 45 | return new StringFileProvider(fileFilter); 46 | } 47 | 48 | public ActionDefinitionFileProvider() { 49 | super(newStringFileProvider()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateActionFeedback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateActionFeedback implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "\n" + 32 | "Header header\n" + 33 | "actionlib_msgs/GoalStatus status\n" + 34 | messageSource + "Feedback feedback"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateActionGoal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateActionGoal implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "\n" + 32 | "Header header\n" + 33 | "actionlib_msgs/GoalID goal_id\n" + 34 | messageSource + "Goal goal"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateActionResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateActionResult implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "\n" + 32 | "Header header\n" + 33 | "actionlib_msgs/GoalStatus status\n" + 34 | messageSource + "Result result"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateFeedback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateFeedback implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "#feedback definition\n" + 32 | messageSource; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateGoal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateGoal implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "#goal definition" + 32 | messageSource; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/ActionGenerationTemplateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.action; 18 | 19 | import org.ros.internal.message.MessageGenerationTemplate; 20 | 21 | /** 22 | * @author arne.peters@tum.de (Arne Peters) 23 | */ 24 | public class ActionGenerationTemplateResult implements MessageGenerationTemplate { 25 | 26 | /** 27 | * @return returns this {@link Message} as a {@link RawMessage} 28 | */ 29 | public String applyTemplate(String messageSource) { 30 | return "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======\n" + 31 | "#result definition" + 32 | messageSource; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/action/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides internal classes for representing action messages. 19 | *

20 | * These classes should _not_ be used directly outside of the org.ros package. 21 | */ 22 | package org.ros.internal.message.action; -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/context/MessageContextBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.context; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.ros.internal.message.definition.MessageDefinitionParser.MessageDefinitionVisitor; 22 | import org.ros.internal.message.field.Field; 23 | import org.ros.internal.message.field.FieldFactory; 24 | import org.ros.internal.message.field.FieldType; 25 | import org.ros.internal.message.field.MessageFieldType; 26 | import org.ros.internal.message.field.PrimitiveFieldType; 27 | import org.ros.message.MessageIdentifier; 28 | 29 | /** 30 | * @author damonkohler@google.com (Damon Kohler) 31 | */ 32 | class MessageContextBuilder implements MessageDefinitionVisitor { 33 | 34 | private final MessageContext messageContext; 35 | 36 | public MessageContextBuilder(MessageContext context) { 37 | this.messageContext = context; 38 | } 39 | 40 | private FieldType getFieldType(String type) { 41 | Preconditions.checkArgument(!type.equals(messageContext.getType()), 42 | "Message definitions may not be self-referential."); 43 | FieldType fieldType; 44 | if (PrimitiveFieldType.existsFor(type)) { 45 | fieldType = PrimitiveFieldType.valueOf(type.toUpperCase()); 46 | } else { 47 | fieldType = 48 | new MessageFieldType(MessageIdentifier.of(type), messageContext.getMessageFactory()); 49 | } 50 | return fieldType; 51 | } 52 | 53 | @Override 54 | public void variableValue(String type, final String name) { 55 | final FieldType fieldType = getFieldType(type); 56 | messageContext.addFieldFactory(name, new FieldFactory() { 57 | @Override 58 | public Field create() { 59 | return fieldType.newVariableValue(name); 60 | } 61 | }); 62 | } 63 | 64 | @Override 65 | public void variableList(String type, final int size, final String name) { 66 | final FieldType fieldType = getFieldType(type); 67 | messageContext.addFieldFactory(name, new FieldFactory() { 68 | @Override 69 | public Field create() { 70 | return fieldType.newVariableList(name, size); 71 | } 72 | }); 73 | } 74 | 75 | @Override 76 | public void constantValue(String type, final String name, final String value) { 77 | final FieldType fieldType = getFieldType(type); 78 | messageContext.addFieldFactory(name, new FieldFactory() { 79 | @Override 80 | public Field create() { 81 | return fieldType.newConstantValue(name, fieldType.parseFromString(value)); 82 | } 83 | }); 84 | } 85 | } -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/context/MessageContextProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.context; 18 | 19 | import com.google.common.base.Preconditions; 20 | import com.google.common.collect.Maps; 21 | 22 | import org.ros.internal.message.definition.MessageDefinitionParser; 23 | import org.ros.internal.message.definition.MessageDefinitionParser.MessageDefinitionVisitor; 24 | import org.ros.message.MessageDeclaration; 25 | import org.ros.message.MessageFactory; 26 | 27 | import java.util.Map; 28 | 29 | /** 30 | * @author damonkohler@google.com (Damon Kohler) 31 | */ 32 | public class MessageContextProvider { 33 | 34 | private final Map cache; 35 | private final MessageFactory messageFactory; 36 | 37 | public MessageContextProvider(MessageFactory messageFactory) { 38 | Preconditions.checkNotNull(messageFactory); 39 | this.messageFactory = messageFactory; 40 | cache = Maps.newConcurrentMap(); 41 | } 42 | 43 | public MessageContext get(MessageDeclaration messageDeclaration) { 44 | MessageContext messageContext = cache.get(messageDeclaration); 45 | if (messageContext == null) { 46 | messageContext = new MessageContext(messageDeclaration, messageFactory); 47 | MessageDefinitionVisitor visitor = new MessageContextBuilder(messageContext); 48 | MessageDefinitionParser messageDefinitionParser = new MessageDefinitionParser(visitor); 49 | messageDefinitionParser.parse(messageDeclaration.getType(), 50 | messageDeclaration.getDefinition()); 51 | cache.put(messageDeclaration, messageContext); 52 | } 53 | return messageContext; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionProviderChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.definition; 18 | 19 | import com.google.common.collect.Lists; 20 | import com.google.common.collect.Sets; 21 | 22 | import org.ros.message.MessageDefinitionProvider; 23 | import org.ros.message.MessageIdentifier; 24 | 25 | import java.util.Collection; 26 | import java.util.NoSuchElementException; 27 | import java.util.Set; 28 | 29 | /** 30 | * @author damonkohler@google.com (Damon Kohler) 31 | */ 32 | public class MessageDefinitionProviderChain implements MessageDefinitionProvider { 33 | 34 | private final Collection messageDefinitionProviders; 35 | 36 | public MessageDefinitionProviderChain() { 37 | messageDefinitionProviders = Lists.newArrayList(); 38 | } 39 | 40 | public void addMessageDefinitionProvider(MessageDefinitionProvider messageDefinitionProvider) { 41 | messageDefinitionProviders.add(messageDefinitionProvider); 42 | } 43 | 44 | @Override 45 | public String get(String messageType) { 46 | for (MessageDefinitionProvider messageDefinitionProvider : messageDefinitionProviders) { 47 | if (messageDefinitionProvider.has(messageType)) { 48 | return messageDefinitionProvider.get(messageType); 49 | } 50 | } 51 | throw new NoSuchElementException("No message definition available for: " + messageType); 52 | } 53 | 54 | @Override 55 | public boolean has(String messageType) { 56 | for (MessageDefinitionProvider messageDefinitionProvider : messageDefinitionProviders) { 57 | if (messageDefinitionProvider.has(messageType)) { 58 | return true; 59 | } 60 | } 61 | return false; 62 | } 63 | 64 | @Override 65 | public Collection getPackages() { 66 | Set result = Sets.newHashSet(); 67 | for (MessageDefinitionProvider messageDefinitionProvider : messageDefinitionProviders) { 68 | Collection packages = messageDefinitionProvider.getPackages(); 69 | result.addAll(packages); 70 | } 71 | return result; 72 | } 73 | 74 | @Override 75 | public Collection getMessageIdentifiersByPackage(String pkg) { 76 | Set result = Sets.newHashSet(); 77 | for (MessageDefinitionProvider messageDefinitionProvider : messageDefinitionProviders) { 78 | Collection messageIdentifiers = 79 | messageDefinitionProvider.getMessageIdentifiersByPackage(pkg); 80 | if (messageIdentifiers != null) { 81 | result.addAll(messageIdentifiers); 82 | } 83 | } 84 | return result; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionReflectionProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.definition; 18 | 19 | import com.google.common.annotations.VisibleForTesting; 20 | import com.google.common.collect.Maps; 21 | 22 | import org.ros.exception.RosMessageRuntimeException; 23 | import org.ros.message.MessageDefinitionProvider; 24 | import org.ros.message.MessageIdentifier; 25 | 26 | import java.util.Collection; 27 | import java.util.Map; 28 | 29 | /** 30 | * A {@link MessageDefinitionProvider} that uses reflection to load the message 31 | * definition {@link String} from a generated interface {@link Class}. 32 | *

33 | * Note that this {@link MessageDefinitionProvider} does not support enumerating 34 | * messages by package. 35 | * 36 | * @author damonkohler@google.com (Damon Kohler) 37 | */ 38 | public class MessageDefinitionReflectionProvider implements MessageDefinitionProvider { 39 | 40 | private static final String DEFINITION_FIELD = "_DEFINITION"; 41 | 42 | private final Map cache; 43 | 44 | public MessageDefinitionReflectionProvider() { 45 | cache = Maps.newConcurrentMap(); 46 | } 47 | 48 | @Override 49 | public String get(String messageType) { 50 | String messageDefinition = cache.get(messageType); 51 | if (messageDefinition == null) { 52 | String className = messageType.replace("/", "."); 53 | try { 54 | Class loadedClass = getClass().getClassLoader().loadClass(className); 55 | messageDefinition = (String) loadedClass.getDeclaredField(DEFINITION_FIELD).get(null); 56 | cache.put(messageType, messageDefinition); 57 | } catch (Exception e) { 58 | throw new RosMessageRuntimeException(e); 59 | } 60 | } 61 | return messageDefinition; 62 | } 63 | 64 | @Override 65 | public boolean has(String messageType) { 66 | try { 67 | get(messageType); 68 | } catch (Exception e) { 69 | return false; 70 | } 71 | return true; 72 | } 73 | 74 | @Override 75 | public Collection getPackages() { 76 | throw new UnsupportedOperationException(); 77 | } 78 | 79 | @Override 80 | public Collection getMessageIdentifiersByPackage(String pkg) { 81 | throw new UnsupportedOperationException(); 82 | } 83 | 84 | @VisibleForTesting 85 | public void add(String messageType, String messageDefinition) { 86 | cache.put(messageType, messageDefinition); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/definition/MessageDefinitionTupleParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.definition; 18 | 19 | import com.google.common.base.Preconditions; 20 | import com.google.common.collect.Lists; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Splits message definitions tuples (e.g. service definitions) into separate 26 | * message definitions. 27 | * 28 | * @author damonkohler@google.com (Damon Kohler) 29 | */ 30 | public class MessageDefinitionTupleParser { 31 | 32 | private static final String SEPARATOR = "---"; 33 | 34 | /** 35 | * Splits the message definition tuple into a {@link List} of message 36 | * definitions. Split message definitions may be empty (e.g. std_srvs/Empty). 37 | * 38 | * @param definition 39 | * the message definition tuple 40 | * @param size 41 | * the expected tuple size, or -1 to ignore this requirement 42 | * @return a {@link List} of the specified size 43 | */ 44 | public static List parse(String definition, int size) { 45 | Preconditions.checkNotNull(definition); 46 | List definitions = Lists.newArrayList(); 47 | StringBuilder current = new StringBuilder(); 48 | for (String line : definition.split("\n")) { 49 | if (line.startsWith(SEPARATOR)) { 50 | definitions.add(current.toString()); 51 | current = new StringBuilder(); 52 | continue; 53 | } 54 | current.append(line); 55 | current.append("\n"); 56 | } 57 | if (current.length() > 0) { 58 | current.deleteCharAt(current.length() - 1); 59 | } 60 | definitions.add(current.toString()); 61 | Preconditions.checkState(size == -1 || definitions.size() <= size, 62 | String.format("Message tuple exceeds expected size: %d > %d", definitions.size(), size)); 63 | while (definitions.size() < size) { 64 | definitions.add(""); 65 | } 66 | return definitions; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/BooleanArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class BooleanArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private boolean[] value; 33 | 34 | public static BooleanArrayField newVariable(String name, int size) { 35 | return new BooleanArrayField(PrimitiveFieldType.BOOL, name, size); 36 | } 37 | 38 | private BooleanArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new boolean[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public boolean[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((boolean[]) value).length == size); 53 | this.value = (boolean[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (boolean v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new boolean[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readByte() == 1; 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "BooleanArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | BooleanArrayField other = (BooleanArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/ByteArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class ByteArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private byte[] value; 33 | 34 | public static ByteArrayField newVariable(FieldType type, String name, int size) { 35 | return new ByteArrayField(type, name, size); 36 | } 37 | 38 | private ByteArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new byte[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public byte[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((byte[]) value).length == size); 53 | this.value = (byte[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (byte v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new byte[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readByte(); 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "ByteArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | ByteArrayField other = (ByteArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/DoubleArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class DoubleArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private double[] value; 33 | 34 | public static DoubleArrayField newVariable(String name, int size) { 35 | return new DoubleArrayField(PrimitiveFieldType.FLOAT64, name, size); 36 | } 37 | 38 | private DoubleArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new double[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public double[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((double[]) value).length == size); 53 | this.value = (double[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (double v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new double[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readDouble(); 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "DoubleArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | DoubleArrayField other = (DoubleArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public abstract class Field { 26 | 27 | protected final FieldType type; 28 | protected final String name; 29 | protected final boolean isConstant; 30 | 31 | protected Field(FieldType type, String name, boolean isConstant) { 32 | this.name = name; 33 | this.type = type; 34 | this.isConstant = isConstant; 35 | } 36 | 37 | /** 38 | * @return the name 39 | */ 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | /** 45 | * @return the type 46 | */ 47 | public FieldType getType() { 48 | return type; 49 | } 50 | 51 | /** 52 | * @return true if this {@link ListField} represents a constant 53 | */ 54 | public boolean isConstant() { 55 | return isConstant; 56 | } 57 | 58 | /** 59 | * @return the textual representation of this field used for computing the MD5 60 | * of a message definition 61 | */ 62 | public String getMd5String() { 63 | if (isConstant()) { 64 | return String.format("%s %s=%s\n", getType().getMd5String(), getName(), getValue()); 65 | } 66 | return String.format("%s %s\n", getType().getMd5String(), getName()); 67 | } 68 | 69 | public abstract void serialize(ChannelBuffer buffer); 70 | 71 | public abstract void deserialize(ChannelBuffer buffer); 72 | 73 | public abstract T getValue(); 74 | 75 | // TODO(damonkohler): Why not make Field generic? 76 | public abstract void setValue(Object value); 77 | 78 | public abstract String getJavaTypeName(); 79 | 80 | @Override 81 | public int hashCode() { 82 | final int prime = 31; 83 | int result = 1; 84 | result = prime * result + (isConstant ? 1231 : 1237); 85 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 86 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 87 | return result; 88 | } 89 | 90 | @Override 91 | public boolean equals(Object obj) { 92 | if (this == obj) 93 | return true; 94 | if (obj == null) 95 | return false; 96 | if (getClass() != obj.getClass()) 97 | return false; 98 | Field other = (Field) obj; 99 | if (isConstant != other.isConstant) 100 | return false; 101 | if (name == null) { 102 | if (other.name != null) 103 | return false; 104 | } else if (!name.equals(other.name)) 105 | return false; 106 | if (type == null) { 107 | if (other.type != null) 108 | return false; 109 | } else if (!type.equals(other.type)) 110 | return false; 111 | return true; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/FieldFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | public interface FieldFactory { 23 | 24 | Field create(); 25 | } 26 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/FieldType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | 21 | /** 22 | * @author damonkohler@google.com (Damon Kohler) 23 | */ 24 | public interface FieldType { 25 | 26 | public T getDefaultValue(); 27 | 28 | public String getName(); 29 | 30 | public T parseFromString(String value); 31 | 32 | public String getMd5String(); 33 | 34 | public String getJavaTypeName(); 35 | 36 | /** 37 | * @return the serialized size of this {@link FieldType} in bytes 38 | */ 39 | public int getSerializedSize(); 40 | 41 | public void serialize(T value, ChannelBuffer buffer); 42 | 43 | public T deserialize(ChannelBuffer buffer); 44 | 45 | public Field newVariableValue(String name); 46 | 47 | public Field newVariableList(String name, int size); 48 | 49 | public Field newConstantValue(String name, T value); 50 | } 51 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/FloatArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class FloatArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private float[] value; 33 | 34 | public static FloatArrayField newVariable(String name, int size) { 35 | return new FloatArrayField(PrimitiveFieldType.FLOAT32, name, size); 36 | } 37 | 38 | private FloatArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new float[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public float[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((float[]) value).length == size); 53 | this.value = (float[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (float v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new float[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readFloat(); 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "FloatArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | FloatArrayField other = (FloatArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/IntegerArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class IntegerArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private int[] value; 33 | 34 | public static IntegerArrayField newVariable(FieldType type, String name, int size) { 35 | return new IntegerArrayField(type, name, size); 36 | } 37 | 38 | private IntegerArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new int[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public int[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((int[]) value).length == size); 53 | this.value = (int[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (int v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new int[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readInt(); 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "IntegerArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | IntegerArrayField other = (IntegerArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/ListField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * @author damonkohler@google.com (Damon Kohler) 28 | * 29 | * @param 30 | * the value type 31 | */ 32 | public class ListField extends Field { 33 | 34 | private List value; 35 | 36 | public static ListField newVariable(FieldType type, String name) { 37 | return new ListField(type, name); 38 | } 39 | 40 | private ListField(FieldType type, String name) { 41 | super(type, name, false); 42 | value = new ArrayList(); 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | @Override 47 | public List getValue() { 48 | return value; 49 | } 50 | 51 | @SuppressWarnings("unchecked") 52 | @Override 53 | public void setValue(Object value) { 54 | Preconditions.checkNotNull(value); 55 | this.value = (List) value; 56 | } 57 | 58 | @Override 59 | public void serialize(ChannelBuffer buffer) { 60 | buffer.writeInt(value.size()); 61 | for (T v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | value.clear(); 69 | int size = buffer.readInt(); 70 | for (int i = 0; i < size; i++) { 71 | value.add(type.deserialize(buffer)); 72 | } 73 | } 74 | 75 | @Override 76 | public String getMd5String() { 77 | return String.format("%s %s\n", type, name); 78 | } 79 | 80 | @Override 81 | public String getJavaTypeName() { 82 | return String.format("java.util.List<%s>", type.getJavaTypeName()); 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "ListField<" + type + ", " + name + ">"; 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | final int prime = 31; 93 | int result = super.hashCode(); 94 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 95 | return result; 96 | } 97 | 98 | @SuppressWarnings("rawtypes") 99 | @Override 100 | public boolean equals(Object obj) { 101 | if (this == obj) 102 | return true; 103 | if (!super.equals(obj)) 104 | return false; 105 | if (getClass() != obj.getClass()) 106 | return false; 107 | ListField other = (ListField) obj; 108 | if (value == null) { 109 | if (other.value != null) 110 | return false; 111 | } else if (!value.equals(other.value)) 112 | return false; 113 | return true; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/LongArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class LongArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private long[] value; 33 | 34 | public static LongArrayField newVariable(FieldType type, String name, int size) { 35 | Preconditions.checkArgument(type.equals(PrimitiveFieldType.UINT32) 36 | || type.equals(PrimitiveFieldType.INT64) || type.equals(PrimitiveFieldType.UINT64)); 37 | return new LongArrayField(type, name, size); 38 | } 39 | 40 | private LongArrayField(FieldType type, String name, int size) { 41 | super(type, name, false); 42 | this.size = size; 43 | setValue(new long[Math.max(0, size)]); 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public long[] getValue() { 49 | return value; 50 | } 51 | 52 | @Override 53 | public void setValue(Object value) { 54 | Preconditions.checkArgument(size < 0 || ((long[]) value).length == size); 55 | this.value = (long[]) value; 56 | } 57 | 58 | @Override 59 | public void serialize(ChannelBuffer buffer) { 60 | if (size < 0) { 61 | buffer.writeInt(value.length); 62 | } 63 | for (long v : value) { 64 | type.serialize(v, buffer); 65 | } 66 | } 67 | 68 | @Override 69 | public void deserialize(ChannelBuffer buffer) { 70 | int currentSize = size; 71 | if (currentSize < 0) { 72 | currentSize = buffer.readInt(); 73 | } 74 | value = new long[currentSize]; 75 | for (int i = 0; i < currentSize; i++) { 76 | value[i] = buffer.readLong(); 77 | } 78 | } 79 | 80 | @Override 81 | public String getMd5String() { 82 | return String.format("%s %s\n", type, name); 83 | } 84 | 85 | @Override 86 | public String getJavaTypeName() { 87 | return type.getJavaTypeName() + "[]"; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return "LongArrayField<" + type + ", " + name + ">"; 93 | } 94 | 95 | @Override 96 | public int hashCode() { 97 | final int prime = 31; 98 | int result = super.hashCode(); 99 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 100 | return result; 101 | } 102 | 103 | @Override 104 | public boolean equals(Object obj) { 105 | if (this == obj) 106 | return true; 107 | if (!super.equals(obj)) 108 | return false; 109 | if (getClass() != obj.getClass()) 110 | return false; 111 | LongArrayField other = (LongArrayField) obj; 112 | if (value == null) { 113 | if (other.value != null) 114 | return false; 115 | } else if (!Arrays.equals(value, other.value)) 116 | return false; 117 | return true; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/ShortArrayField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class ShortArrayField extends Field { 29 | 30 | private final int size; 31 | 32 | private short[] value; 33 | 34 | public static ShortArrayField newVariable(FieldType type, String name, int size) { 35 | return new ShortArrayField(type, name, size); 36 | } 37 | 38 | private ShortArrayField(FieldType type, String name, int size) { 39 | super(type, name, false); 40 | this.size = size; 41 | setValue(new short[Math.max(0, size)]); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public short[] getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public void setValue(Object value) { 52 | Preconditions.checkArgument(size < 0 || ((short[]) value).length == size); 53 | this.value = (short[]) value; 54 | } 55 | 56 | @Override 57 | public void serialize(ChannelBuffer buffer) { 58 | if (size < 0) { 59 | buffer.writeInt(value.length); 60 | } 61 | for (short v : value) { 62 | type.serialize(v, buffer); 63 | } 64 | } 65 | 66 | @Override 67 | public void deserialize(ChannelBuffer buffer) { 68 | int currentSize = size; 69 | if (currentSize < 0) { 70 | currentSize = buffer.readInt(); 71 | } 72 | value = new short[currentSize]; 73 | for (int i = 0; i < currentSize; i++) { 74 | value[i] = buffer.readShort(); 75 | } 76 | } 77 | 78 | @Override 79 | public String getMd5String() { 80 | return String.format("%s %s\n", type, name); 81 | } 82 | 83 | @Override 84 | public String getJavaTypeName() { 85 | return type.getJavaTypeName() + "[]"; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "ShortArrayField<" + type + ", " + name + ">"; 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | final int prime = 31; 96 | int result = super.hashCode(); 97 | result = prime * result + ((value == null) ? 0 : Arrays.hashCode(value)); 98 | return result; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (this == obj) 104 | return true; 105 | if (!super.equals(obj)) 106 | return false; 107 | if (getClass() != obj.getClass()) 108 | return false; 109 | ShortArrayField other = (ShortArrayField) obj; 110 | if (value == null) { 111 | if (other.value != null) 112 | return false; 113 | } else if (!Arrays.equals(value, other.value)) 114 | return false; 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/field/ValueField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.field; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.jboss.netty.buffer.ChannelBuffer; 22 | 23 | /** 24 | * @author damonkohler@google.com (Damon Kohler) 25 | */ 26 | class ValueField extends Field { 27 | 28 | private T value; 29 | 30 | static ValueField newConstant(FieldType type, String name, T value) { 31 | return new ValueField(type, name, value, true); 32 | } 33 | 34 | static ValueField newVariable(FieldType type, String name) { 35 | return new ValueField(type, name, null, false); 36 | } 37 | 38 | private ValueField(FieldType type, String name, T value, boolean isConstant) { 39 | super(type, name, isConstant); 40 | this.value = value; 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public T getValue() { 46 | if (value == null) { 47 | setValue(type.getDefaultValue()); 48 | } 49 | return value; 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | @Override 54 | public void setValue(Object value) { 55 | Preconditions.checkNotNull(value); 56 | Preconditions.checkState(!isConstant); 57 | this.value = (T) value; 58 | } 59 | 60 | @Override 61 | public void serialize(ChannelBuffer buffer) { 62 | type.serialize(getValue(), buffer); 63 | } 64 | 65 | @Override 66 | public void deserialize(ChannelBuffer buffer) { 67 | Preconditions.checkState(!isConstant); 68 | setValue(type.deserialize(buffer)); 69 | } 70 | 71 | @Override 72 | public String getMd5String() { 73 | return String.format("%s %s\n", type, name); 74 | } 75 | 76 | @Override 77 | public String getJavaTypeName() { 78 | return type.getJavaTypeName(); 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "ValueField<" + type + ", " + name + ">"; 84 | } 85 | 86 | @Override 87 | public int hashCode() { 88 | final int prime = 31; 89 | int result = super.hashCode(); 90 | result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode()); 91 | return result; 92 | } 93 | 94 | @Override 95 | public boolean equals(Object obj) { 96 | if (this == obj) 97 | return true; 98 | if (!super.equals(obj)) 99 | return false; 100 | if (getClass() != obj.getClass()) 101 | return false; 102 | Field other = (Field) obj; 103 | if (getValue() == null) { 104 | if (other.getValue() != null) 105 | return false; 106 | } else if (!getValue().equals(other.getValue())) 107 | return false; 108 | return true; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides internal classes for representing messages. 19 | *

20 | * These classes should _not_ be used directly outside of the org.ros package. 21 | */ 22 | package org.ros.internal.message; -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceDefinitionFileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.definition.MessageDefinitionFileProvider; 20 | 21 | import org.apache.commons.io.filefilter.FileFilterUtils; 22 | import org.apache.commons.io.filefilter.IOFileFilter; 23 | import org.ros.internal.message.StringFileProvider; 24 | 25 | import java.io.File; 26 | import java.io.FileFilter; 27 | 28 | /** 29 | * @author damonkohler@google.com (Damon Kohler) 30 | */ 31 | public class ServiceDefinitionFileProvider extends MessageDefinitionFileProvider { 32 | 33 | private static final String PARENT = "srv"; 34 | private static final String SUFFIX = "srv"; 35 | 36 | private static StringFileProvider newStringFileProvider() { 37 | IOFileFilter extensionFilter = FileFilterUtils.suffixFileFilter(SUFFIX); 38 | IOFileFilter parentBaseNameFilter = FileFilterUtils.asFileFilter(new FileFilter() { 39 | @Override 40 | public boolean accept(File file) { 41 | return getParentBaseName(file.getAbsolutePath()).equals(PARENT); 42 | } 43 | }); 44 | IOFileFilter fileFilter = FileFilterUtils.andFileFilter(extensionFilter, parentBaseNameFilter); 45 | return new StringFileProvider(fileFilter); 46 | } 47 | 48 | public ServiceDefinitionFileProvider() { 49 | super(newStringFileProvider()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceDefinitionResourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import org.ros.internal.message.StringResourceProvider; 22 | import org.ros.message.MessageDefinitionProvider; 23 | import org.ros.message.MessageIdentifier; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * @author damonkohler@google.com (Damon Kohler) 29 | */ 30 | public class ServiceDefinitionResourceProvider implements MessageDefinitionProvider { 31 | 32 | private final StringResourceProvider stringResourceProvider; 33 | 34 | public ServiceDefinitionResourceProvider() { 35 | stringResourceProvider = new StringResourceProvider(); 36 | } 37 | 38 | private String serviceTypeToResourceName(String serviceType) { 39 | Preconditions.checkArgument(serviceType.contains("/"), "Service type must be fully qualified: " 40 | + serviceType); 41 | String[] packageAndType = serviceType.split("/", 2); 42 | return String.format("/%s/srv/%s.srv", packageAndType[0], packageAndType[1]); 43 | } 44 | 45 | @Override 46 | public String get(String serviceType) { 47 | return stringResourceProvider.get(serviceTypeToResourceName(serviceType)); 48 | } 49 | 50 | @Override 51 | public boolean has(String serviceType) { 52 | return stringResourceProvider.has(serviceTypeToResourceName(serviceType)); 53 | } 54 | 55 | public void add(String serviceType, String serviceDefinition) { 56 | stringResourceProvider.addStringToCache(serviceTypeToResourceName(serviceType), 57 | serviceDefinition); 58 | } 59 | 60 | @Override 61 | public Collection getPackages() { 62 | throw new UnsupportedOperationException(); 63 | } 64 | 65 | @Override 66 | public Collection getMessageIdentifiersByPackage(String pkg) { 67 | throw new UnsupportedOperationException(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceDescription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.definition.MessageDefinitionTupleParser; 20 | 21 | import org.ros.message.MessageDeclaration; 22 | import org.ros.message.MessageIdentifier; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * The description of a ROS service. 28 | * 29 | * @author damonkohler@google.com (Damon Kohler) 30 | */ 31 | public class ServiceDescription extends MessageDeclaration { 32 | 33 | private final String requestType; 34 | private final String requestDefinition; 35 | private final String responseType; 36 | private final String responseDefinition; 37 | private final String md5Checksum; 38 | 39 | public ServiceDescription(String type, String definition, String md5Checksum) { 40 | super(MessageIdentifier.of(type), definition); 41 | this.md5Checksum = md5Checksum; 42 | List requestAndResponse = MessageDefinitionTupleParser.parse(definition, 2); 43 | requestType = type + "Request"; 44 | responseType = type + "Response"; 45 | requestDefinition = requestAndResponse.get(0); 46 | responseDefinition = requestAndResponse.get(1); 47 | } 48 | 49 | public String getMd5Checksum() { 50 | return md5Checksum; 51 | } 52 | 53 | public String getRequestType() { 54 | return requestType; 55 | } 56 | 57 | public String getRequestDefinition() { 58 | return requestDefinition; 59 | } 60 | 61 | public String getResponseType() { 62 | return responseType; 63 | } 64 | 65 | public String getResponseDefinition() { 66 | return responseDefinition; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "ServiceDescription<" + getType() + ", " + md5Checksum + ">"; 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | final int prime = 31; 77 | int result = super.hashCode(); 78 | result = prime * result + ((md5Checksum == null) ? 0 : md5Checksum.hashCode()); 79 | return result; 80 | } 81 | 82 | @Override 83 | public boolean equals(Object obj) { 84 | if (this == obj) 85 | return true; 86 | if (!super.equals(obj)) 87 | return false; 88 | if (getClass() != obj.getClass()) 89 | return false; 90 | ServiceDescription other = (ServiceDescription) obj; 91 | if (md5Checksum == null) { 92 | if (other.md5Checksum != null) 93 | return false; 94 | } else if (!md5Checksum.equals(other.md5Checksum)) 95 | return false; 96 | return true; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceDescriptionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.Md5Generator; 20 | import org.ros.message.MessageDefinitionProvider; 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public class ServiceDescriptionFactory { 26 | 27 | private final MessageDefinitionProvider messageDefinitionProvider; 28 | private final Md5Generator md5Generator; 29 | 30 | public ServiceDescriptionFactory(MessageDefinitionProvider messageDefinitionProvider) { 31 | this.messageDefinitionProvider = messageDefinitionProvider; 32 | md5Generator = new Md5Generator(messageDefinitionProvider); 33 | } 34 | 35 | public ServiceDescription newFromType(String serviceType) { 36 | String serviceDefinition = messageDefinitionProvider.get(serviceType); 37 | String md5Checksum = md5Generator.generate(serviceType); 38 | return new ServiceDescription(serviceType, serviceDefinition, md5Checksum); 39 | } 40 | 41 | public boolean hasType(String serviceType) { 42 | return messageDefinitionProvider.has(serviceType); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceRequestMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.DefaultMessageFactory; 20 | import org.ros.internal.message.DefaultMessageInterfaceClassProvider; 21 | import org.ros.internal.message.MessageProxyFactory; 22 | import org.ros.message.MessageDeclaration; 23 | import org.ros.message.MessageDefinitionProvider; 24 | import org.ros.message.MessageFactory; 25 | 26 | /** 27 | * @author damonkohler@google.com (Damon Kohler) 28 | */ 29 | public class ServiceRequestMessageFactory implements MessageFactory { 30 | 31 | private final ServiceDescriptionFactory serviceDescriptionFactory; 32 | private final MessageFactory messageFactory; 33 | private final MessageProxyFactory messageProxyFactory; 34 | 35 | public ServiceRequestMessageFactory(MessageDefinitionProvider messageDefinitionProvider) { 36 | serviceDescriptionFactory = new ServiceDescriptionFactory(messageDefinitionProvider); 37 | messageFactory = new DefaultMessageFactory(messageDefinitionProvider); 38 | messageProxyFactory = 39 | new MessageProxyFactory(new DefaultMessageInterfaceClassProvider(), messageFactory); 40 | } 41 | 42 | @Override 43 | public T newFromType(String serviceType) { 44 | ServiceDescription serviceDescription = serviceDescriptionFactory.newFromType(serviceType); 45 | MessageDeclaration messageDeclaration = 46 | MessageDeclaration.of(serviceDescription.getRequestType(), 47 | serviceDescription.getRequestDefinition()); 48 | return messageProxyFactory.newMessageProxy(messageDeclaration); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceRequestMessageInterfaceClassProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.MessageInterfaceClassProvider; 20 | import org.ros.internal.message.RawMessage; 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public class ServiceRequestMessageInterfaceClassProvider implements MessageInterfaceClassProvider { 26 | 27 | @SuppressWarnings("unchecked") 28 | @Override 29 | public Class get(String messageType) { 30 | try { 31 | String className = messageType.replace("/", ".") + "$Request"; 32 | return (Class) getClass().getClassLoader().loadClass(className); 33 | } catch (ClassNotFoundException e) { 34 | return (Class) RawMessage.class; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceResponseMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.DefaultMessageFactory; 20 | import org.ros.internal.message.DefaultMessageInterfaceClassProvider; 21 | import org.ros.internal.message.MessageProxyFactory; 22 | import org.ros.message.MessageDeclaration; 23 | import org.ros.message.MessageDefinitionProvider; 24 | import org.ros.message.MessageFactory; 25 | 26 | /** 27 | * @author damonkohler@google.com (Damon Kohler) 28 | */ 29 | public class ServiceResponseMessageFactory implements MessageFactory { 30 | 31 | private final ServiceDescriptionFactory serviceDescriptionFactory; 32 | private final MessageFactory messageFactory; 33 | private final MessageProxyFactory messageProxyFactory; 34 | 35 | public ServiceResponseMessageFactory(MessageDefinitionProvider messageDefinitionProvider) { 36 | serviceDescriptionFactory = new ServiceDescriptionFactory(messageDefinitionProvider); 37 | messageFactory = new DefaultMessageFactory(messageDefinitionProvider); 38 | messageProxyFactory = 39 | new MessageProxyFactory(new DefaultMessageInterfaceClassProvider(), messageFactory); 40 | } 41 | 42 | @Override 43 | public T newFromType(String serviceType) { 44 | ServiceDescription serviceDescription = serviceDescriptionFactory.newFromType(serviceType); 45 | MessageDeclaration messageDeclaration = 46 | MessageDeclaration.of(serviceDescription.getResponseType(), 47 | serviceDescription.getResponseDefinition()); 48 | return messageProxyFactory.newMessageProxy(messageDeclaration); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/ServiceResponseMessageInterfaceClassProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.service; 18 | 19 | import org.ros.internal.message.MessageInterfaceClassProvider; 20 | import org.ros.internal.message.RawMessage; 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public class ServiceResponseMessageInterfaceClassProvider implements MessageInterfaceClassProvider { 26 | 27 | @SuppressWarnings("unchecked") 28 | @Override 29 | public Class get(String messageType) { 30 | try { 31 | String className = messageType.replace("/", ".") + "$Response"; 32 | return (Class) getClass().getClassLoader().loadClass(className); 33 | } catch (ClassNotFoundException e) { 34 | return (Class) RawMessage.class; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides internal classes for representing service messages. 19 | *

20 | * These classes should _not_ be used directly outside of the org.ros package. 21 | */ 22 | package org.ros.internal.message.service; -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/TopicDefinitionFileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.topic; 18 | 19 | import org.ros.internal.message.definition.MessageDefinitionFileProvider; 20 | 21 | import org.apache.commons.io.filefilter.FileFilterUtils; 22 | import org.apache.commons.io.filefilter.IOFileFilter; 23 | import org.ros.internal.message.StringFileProvider; 24 | 25 | import java.io.File; 26 | import java.io.FileFilter; 27 | 28 | /** 29 | * @author damonkohler@google.com (Damon Kohler) 30 | */ 31 | public class TopicDefinitionFileProvider extends MessageDefinitionFileProvider { 32 | 33 | private static final String PARENT = "msg"; 34 | private static final String SUFFIX = "msg"; 35 | 36 | private static StringFileProvider newStringFileProvider() { 37 | IOFileFilter extensionFilter = FileFilterUtils.suffixFileFilter(SUFFIX); 38 | IOFileFilter parentBaseNameFilter = FileFilterUtils.asFileFilter(new FileFilter() { 39 | @Override 40 | public boolean accept(File file) { 41 | return getParentBaseName(file.getAbsolutePath()).equals(PARENT); 42 | } 43 | }); 44 | IOFileFilter fileFilter = FileFilterUtils.andFileFilter(extensionFilter, parentBaseNameFilter); 45 | return new StringFileProvider(fileFilter); 46 | } 47 | 48 | public TopicDefinitionFileProvider() { 49 | super(newStringFileProvider()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/TopicDefinitionResourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.topic; 18 | 19 | import com.google.common.annotations.VisibleForTesting; 20 | 21 | import org.ros.internal.message.StringResourceProvider; 22 | import org.ros.message.MessageDefinitionProvider; 23 | import org.ros.message.MessageIdentifier; 24 | 25 | import java.util.Collection; 26 | 27 | /** 28 | * @author damonkohler@google.com (Damon Kohler) 29 | */ 30 | public class TopicDefinitionResourceProvider implements MessageDefinitionProvider { 31 | 32 | private final StringResourceProvider stringResourceProvider; 33 | 34 | public TopicDefinitionResourceProvider() { 35 | stringResourceProvider = new StringResourceProvider(); 36 | } 37 | 38 | private String topicTypeToResourceName(String topicType) { 39 | MessageIdentifier messageIdentifier = MessageIdentifier.of(topicType); 40 | return String.format("/%s/msg/%s.msg", messageIdentifier.getPackage(), 41 | messageIdentifier.getName()); 42 | } 43 | 44 | @Override 45 | public String get(String topicType) { 46 | return stringResourceProvider.get(topicTypeToResourceName(topicType)); 47 | } 48 | 49 | @Override 50 | public boolean has(String topicType) { 51 | return stringResourceProvider.has(topicTypeToResourceName(topicType)); 52 | } 53 | 54 | @VisibleForTesting 55 | public void add(String topicType, String topicDefinition) { 56 | stringResourceProvider.addStringToCache(topicTypeToResourceName(topicType), topicDefinition); 57 | } 58 | 59 | @Override 60 | public Collection getPackages() { 61 | throw new UnsupportedOperationException(); 62 | } 63 | 64 | @Override 65 | public Collection getMessageIdentifiersByPackage(String pkg) { 66 | throw new UnsupportedOperationException(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/TopicDescription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.topic; 18 | 19 | import org.ros.message.MessageDeclaration; 20 | import org.ros.message.MessageIdentifier; 21 | 22 | /** 23 | * The description of a ROS topic. 24 | * 25 | * @author damonkohler@google.com (Damon Kohler) 26 | */ 27 | public class TopicDescription extends MessageDeclaration { 28 | 29 | private final String md5Checksum; 30 | 31 | public TopicDescription(String type, String definition, String md5Checksum) { 32 | super(MessageIdentifier.of(type), definition); 33 | this.md5Checksum = md5Checksum; 34 | } 35 | 36 | public String getMd5Checksum() { 37 | return md5Checksum; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "TopicDescription<" + getType() + ", " + md5Checksum + ">"; 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | final int prime = 31; 48 | int result = super.hashCode(); 49 | result = prime * result + ((md5Checksum == null) ? 0 : md5Checksum.hashCode()); 50 | return result; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (this == obj) 56 | return true; 57 | if (!super.equals(obj)) 58 | return false; 59 | if (getClass() != obj.getClass()) 60 | return false; 61 | TopicDescription other = (TopicDescription) obj; 62 | if (md5Checksum == null) { 63 | if (other.md5Checksum != null) 64 | return false; 65 | } else if (!md5Checksum.equals(other.md5Checksum)) 66 | return false; 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/TopicDescriptionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.topic; 18 | 19 | import org.ros.internal.message.Md5Generator; 20 | import org.ros.message.MessageDefinitionProvider; 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public class TopicDescriptionFactory { 26 | 27 | private final MessageDefinitionProvider messageDefinitionProvider; 28 | private final Md5Generator md5Generator; 29 | 30 | public TopicDescriptionFactory(MessageDefinitionProvider messageDefinitionProvider) { 31 | this.messageDefinitionProvider = messageDefinitionProvider; 32 | md5Generator = new Md5Generator(messageDefinitionProvider); 33 | } 34 | 35 | public TopicDescription newFromType(String topicType) { 36 | String md5Checksum = md5Generator.generate(topicType); 37 | String topicDefinition = messageDefinitionProvider.get(topicType); 38 | return new TopicDescription(topicType, topicDefinition, md5Checksum); 39 | } 40 | 41 | public boolean hasType(String topicType) { 42 | return messageDefinitionProvider.has(topicType); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/TopicMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message.topic; 18 | 19 | import org.ros.internal.message.DefaultMessageFactory; 20 | import org.ros.message.MessageDefinitionProvider; 21 | 22 | /** 23 | * @author damonkohler@google.com (Damon Kohler) 24 | */ 25 | public class TopicMessageFactory extends DefaultMessageFactory { 26 | 27 | public TopicMessageFactory(MessageDefinitionProvider messageDefinitionProvider) { 28 | super(messageDefinitionProvider); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/internal/message/topic/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides internal classes for representing topic messages. 19 | *

20 | * These classes should _not_ be used directly outside of the org.ros package. 21 | */ 22 | package org.ros.internal.message.topic; -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | /** 22 | * An {@link MessageIdentifier} and definition pair from which all qualities of 23 | * the message uniquely identifiable by the {@link MessageIdentifier} can be 24 | * derived. 25 | * 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class MessageDeclaration { 29 | 30 | private final MessageIdentifier messageIdentifier; 31 | private final String definition; 32 | 33 | public static MessageDeclaration of(String type, String definition) { 34 | Preconditions.checkNotNull(type); 35 | Preconditions.checkNotNull(definition); 36 | return new MessageDeclaration(MessageIdentifier.of(type), definition); 37 | } 38 | 39 | /** 40 | * @param messageIdentifier 41 | * the {@link MessageIdentifier} 42 | * @param definition 43 | * the message definition 44 | */ 45 | public MessageDeclaration(MessageIdentifier messageIdentifier, String definition) { 46 | Preconditions.checkNotNull(messageIdentifier); 47 | Preconditions.checkNotNull(definition); 48 | this.messageIdentifier = messageIdentifier; 49 | this.definition = definition; 50 | } 51 | 52 | public MessageIdentifier getMessageIdentifier() { 53 | return messageIdentifier; 54 | } 55 | 56 | public String getType() { 57 | return messageIdentifier.getType(); 58 | } 59 | 60 | public String getPackage() { 61 | return messageIdentifier.getPackage(); 62 | } 63 | 64 | public String getName() { 65 | return messageIdentifier.getName(); 66 | } 67 | 68 | public String getDefinition() { 69 | Preconditions.checkNotNull(definition); 70 | return definition; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return String.format("MessageDeclaration<%s>", messageIdentifier.toString()); 76 | } 77 | 78 | @Override 79 | public int hashCode() { 80 | final int prime = 31; 81 | int result = 1; 82 | result = prime * result + ((definition == null) ? 0 : definition.hashCode()); 83 | result = prime * result + ((messageIdentifier == null) ? 0 : messageIdentifier.hashCode()); 84 | return result; 85 | } 86 | 87 | @Override 88 | public boolean equals(Object obj) { 89 | if (this == obj) 90 | return true; 91 | if (obj == null) 92 | return false; 93 | if (getClass() != obj.getClass()) 94 | return false; 95 | MessageDeclaration other = (MessageDeclaration) obj; 96 | if (definition == null) { 97 | if (other.definition != null) 98 | return false; 99 | } else if (!definition.equals(other.definition)) 100 | return false; 101 | if (messageIdentifier == null) { 102 | if (other.messageIdentifier != null) 103 | return false; 104 | } else if (!messageIdentifier.equals(other.messageIdentifier)) 105 | return false; 106 | return true; 107 | } 108 | } -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageDefinitionProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import java.util.Collection; 20 | 21 | /** 22 | * @author damonkohler@google.com (Damon Kohler) 23 | */ 24 | public interface MessageDefinitionProvider { 25 | 26 | /** 27 | * @param messageType 28 | * the type of message definition to provide 29 | * @return the message definition for the specified type 30 | */ 31 | String get(String messageType); 32 | 33 | /** 34 | * @param messageType 35 | * the type of message definition to provide 36 | * @return {@code true} if the definition for the specified type is available, 37 | * {@code false} otherwise 38 | */ 39 | boolean has(String messageType); 40 | 41 | Collection getPackages(); 42 | 43 | /** 44 | * @param pkg 45 | * the name of the package to filter on 46 | * @return the {@link MessageIdentifier}s for all messages defined in the 47 | * specified package 48 | */ 49 | Collection getMessageIdentifiersByPackage(String pkg); 50 | } 51 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | 21 | /** 22 | * @author damonkohler@google.com (Damon Kohler) 23 | * 24 | * @param 25 | * the type of message that this {@link MessageDeserializer} can 26 | * deserialize 27 | */ 28 | public interface MessageDeserializer { 29 | 30 | T deserialize(ChannelBuffer buffer); 31 | } 32 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | public interface MessageFactory { 23 | 24 | /** 25 | * @param messageType 26 | * the type of message to create 27 | * @return a new message 28 | */ 29 | T newFromType(String messageType); 30 | } 31 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageFactoryProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | public interface MessageFactoryProvider { 20 | 21 | MessageFactory get(MessageIdentifier messageIdentifier); 22 | 23 | boolean has(MessageIdentifier messageIdentifier); 24 | } 25 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | /** 20 | * A callback for asynchronous message-related operations. 21 | * 22 | * @author damonkohler@google.com (Damon Kohler) 23 | * 24 | * @param 25 | * the type of message expected 26 | */ 27 | public interface MessageListener { 28 | 29 | /** 30 | * Called when a new message arrives. 31 | * 32 | * @param message 33 | * the new message 34 | */ 35 | void onNewMessage(T message); 36 | } -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageSerializationFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | /** 20 | * @author damonkohler@google.com (Damon Kohler) 21 | */ 22 | public interface MessageSerializationFactory { 23 | 24 | /** 25 | * @param messageType 26 | * the type of message that the new {@link MessageSerializer} should 27 | * serialize 28 | * @return a new {@link MessageSerializer} for the provided message type 29 | */ 30 | MessageSerializer newMessageSerializer(String messageType); 31 | 32 | /** 33 | * @param messageType 34 | * the type of message that the new {@link MessageDeserializer} 35 | * should deserialize 36 | * @return a new {@link MessageDeserializer} for the provided message type 37 | */ 38 | MessageDeserializer newMessageDeserializer(String messageType); 39 | 40 | /** 41 | * @param serviceType 42 | * the type of service that the new {@link MessageSerializer} should 43 | * serialize requests for 44 | * @return a new {@link MessageSerializer} for requests to the provided 45 | * service type 46 | */ 47 | MessageSerializer newServiceRequestSerializer(String serviceType); 48 | 49 | /** 50 | * @param serviceType 51 | * the type of service that the new {@link MessageDeserializer} 52 | * should deserialize requests for 53 | * @return a new {@link MessageDeserializer} for requests to the provided 54 | * service type 55 | */ 56 | MessageDeserializer newServiceRequestDeserializer(String serviceType); 57 | 58 | /** 59 | * @param serviceType 60 | * the type of service that the new {@link MessageSerializer} should 61 | * serialize responses for 62 | * @return a new {@link MessageSerializer} for responses from the provided 63 | * service type 64 | */ 65 | MessageSerializer newServiceResponseSerializer(String serviceType); 66 | 67 | /** 68 | * @param serviceType 69 | * the type of service that the new {@link MessageDeserializer} 70 | * should deserialize responses for 71 | * @return a new {@link MessageDeserializer} for responses from the provided 72 | * service type 73 | */ 74 | MessageDeserializer newServiceResponseDeserializer(String serviceType); 75 | } 76 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/MessageSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import org.jboss.netty.buffer.ChannelBuffer; 20 | 21 | /** 22 | * @author damonkohler@google.com (Damon Kohler) 23 | * 24 | * @param 25 | * the type of message that the {@link MessageSerializer} can serialize 26 | */ 27 | public interface MessageSerializer { 28 | 29 | void serialize(T message, ChannelBuffer buffer); 30 | } 31 | -------------------------------------------------------------------------------- /message_generation/src/main/java/org/ros/message/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides the classes for representing messages. 19 | * 20 | * @see messages documentation 21 | */ 22 | package org.ros.message; -------------------------------------------------------------------------------- /message_generation/src/test/java/org/ros/internal/message/MessageInterfaceBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | import org.ros.internal.message.topic.TopicDefinitionResourceProvider; 24 | import org.ros.message.MessageDeclaration; 25 | import org.ros.message.MessageFactory; 26 | 27 | /** 28 | * @author damonkohler@google.com (Damon Kohler) 29 | */ 30 | public class MessageInterfaceBuilderTest { 31 | 32 | private TopicDefinitionResourceProvider topicDefinitionResourceProvider; 33 | private MessageFactory messageFactory; 34 | 35 | @Before 36 | public void before() { 37 | topicDefinitionResourceProvider = new TopicDefinitionResourceProvider(); 38 | messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider); 39 | } 40 | 41 | @Test 42 | public void testDuplicateFieldNames() { 43 | MessageInterfaceBuilder builder = new MessageInterfaceBuilder(); 44 | builder.setPackageName("foo"); 45 | builder.setInterfaceName("bar"); 46 | builder.setMessageDeclaration(MessageDeclaration.of("foo/bar", "int32 foo\nint32 Foo")); 47 | builder.setAddConstantsAndMethods(true); 48 | String result = builder.build(messageFactory); 49 | assertEquals("package foo;\n\n" 50 | + "public interface bar extends org.ros.internal.message.Message {\n" 51 | + " static final java.lang.String _TYPE = \"foo/bar\";\n" 52 | + " static final java.lang.String _DEFINITION = \"int32 foo\\nint32 Foo\";\n" 53 | + " int getFoo();\n" + " void setFoo(int value);\n" + "}\n", result); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /message_generation/src/test/java/org/ros/internal/message/ServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.internal.message; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | import org.ros.internal.message.service.ServiceDefinitionResourceProvider; 22 | import org.ros.internal.message.service.ServiceRequestMessageFactory; 23 | import org.ros.internal.message.service.ServiceResponseMessageFactory; 24 | 25 | /** 26 | * @author damonkohler@google.com (Damon Kohler) 27 | */ 28 | public class ServiceTest { 29 | 30 | private ServiceDefinitionResourceProvider serviceDefinitionResourceProvider; 31 | private ServiceRequestMessageFactory serviceRequestMessageFactory; 32 | private ServiceResponseMessageFactory serviceResponseMessageFactory; 33 | 34 | @Before 35 | public void setUp() { 36 | serviceDefinitionResourceProvider = new ServiceDefinitionResourceProvider(); 37 | serviceDefinitionResourceProvider.add("foo/Echo", "string data\n---\nstring data"); 38 | serviceRequestMessageFactory = 39 | new ServiceRequestMessageFactory(serviceDefinitionResourceProvider); 40 | serviceResponseMessageFactory = 41 | new ServiceResponseMessageFactory(serviceDefinitionResourceProvider); 42 | } 43 | 44 | @Test 45 | public void testCreateEchoService() { 46 | RawMessage request = serviceRequestMessageFactory.newFromType("foo/Echo"); 47 | RawMessage response = serviceResponseMessageFactory.newFromType("foo/Echo"); 48 | request.setString("data", "Hello, ROS!"); 49 | response.setString("data", "Hello, ROS!"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /message_generation/src/test/java/org/ros/message/DurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author kwc@willowgarage.com (Ken Conley) 28 | */ 29 | public class DurationTest { 30 | 31 | @Before 32 | public void setUp() { 33 | } 34 | 35 | @Test 36 | public void testConstructor() { 37 | // Test no args constructor. 38 | Duration t = new Duration(); 39 | assertEquals(0, t.nsecs); 40 | assertEquals(0, t.secs); 41 | 42 | // Test secs/nsecs constructor with no normalization. 43 | t = new Duration(1, 2); 44 | assertEquals(1, t.secs); 45 | assertEquals(2, t.nsecs); 46 | 47 | // Test secs/nsecs constructor with normalization. 48 | t = new Duration(2, -1); 49 | assertEquals(1, t.secs); 50 | assertEquals(1000000000 - 1, t.nsecs); 51 | 52 | t = new Duration(2, 1000000000 + 2); 53 | assertEquals(3, t.secs); 54 | assertEquals(2, t.nsecs); 55 | } 56 | 57 | @Test 58 | public void testNormalize() { 59 | Duration d = new Duration(0, 0); 60 | d.secs = 1; 61 | d.nsecs = 1000000000; 62 | d.normalize(); 63 | assertEquals(2, d.secs); 64 | assertEquals(0, d.nsecs); 65 | 66 | d.secs = 1; 67 | d.nsecs = -1; 68 | d.normalize(); 69 | assertEquals(0, d.secs); 70 | assertEquals(1000000000-1, d.nsecs); 71 | } 72 | 73 | @Test 74 | public void testIsZero() { 75 | assertTrue(new Duration(0, 0).isZero()); 76 | assertFalse(new Duration(1, 0).isZero()); 77 | assertFalse(new Duration(0, 1).isZero()); 78 | } 79 | 80 | @Test 81 | public void testComparable() { 82 | assertEquals(0, new Duration(0, 0).compareTo(new Duration(0, 0))); 83 | assertEquals(0, new Duration(1, 0).compareTo(new Duration(1, 0))); 84 | 85 | assertTrue(new Duration(0, 0).compareTo(new Duration(0, -1)) > 0); 86 | assertTrue(new Duration(0, -1).compareTo(new Duration(0, 0)) < 0); 87 | 88 | assertTrue(new Duration(0, 0).compareTo(new Duration(-1, 0)) > 0); 89 | assertTrue(new Duration(-1, 0).compareTo(new Duration(0, 0)) < 0); 90 | 91 | assertTrue(new Duration(1, 0).compareTo(new Duration(0, 0)) > 0); 92 | assertTrue(new Duration(0, 0).compareTo(new Duration(1, 0)) < 0); 93 | 94 | assertTrue(new Duration(0, 1).compareTo(new Duration(0, 0)) > 0); 95 | assertTrue(new Duration(0, 0).compareTo(new Duration(0, 1)) < 0); 96 | } 97 | } -------------------------------------------------------------------------------- /message_generation/src/test/java/org/ros/message/TimeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.ros.message; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author kwc@willowgarage.com (Ken Conley) 28 | */ 29 | public class TimeTest { 30 | 31 | @Before 32 | public void setUp() { 33 | } 34 | 35 | @Test 36 | public void testConstructor() { 37 | // Test no args constructor. 38 | Time t = new Time(); 39 | assertEquals(0, t.nsecs); 40 | assertEquals(0, t.secs); 41 | 42 | // Test secs/nsecs constructor with no normalization. 43 | t = new Time(1, 2); 44 | assertEquals(1, t.secs); 45 | assertEquals(2, t.nsecs); 46 | 47 | // Test secs/nsecs constructor with normalization. 48 | t = new Time(2, -1); 49 | assertEquals(1, t.secs); 50 | assertEquals(1000000000 - 1, t.nsecs); 51 | 52 | t = new Time(2, 1000000000 + 2); 53 | assertEquals(3, t.secs); 54 | assertEquals(2, t.nsecs); 55 | } 56 | 57 | @Test 58 | public void testFromMillis() { 59 | assertEquals(new Time(0, 0), Time.fromMillis(0)); 60 | assertEquals(new Time(0, 1000000), Time.fromMillis(1)); 61 | assertEquals(new Time(1, 0), Time.fromMillis(1000)); 62 | assertEquals(new Time(10, 0), Time.fromMillis(10000)); 63 | assertEquals(new Time(1, 1000000), Time.fromMillis(1001)); 64 | assertEquals(new Time(1, 11000000), Time.fromMillis(1011)); 65 | } 66 | 67 | @Test 68 | public void testNormalize() { 69 | Time t = new Time(0, 0); 70 | t.secs = 1; 71 | t.nsecs = 1000000000; 72 | t.normalize(); 73 | assertEquals(2, t.secs); 74 | assertEquals(0, t.nsecs); 75 | 76 | t.secs = 1; 77 | t.nsecs = -1; 78 | t.normalize(); 79 | assertEquals(0, t.secs); 80 | assertEquals(1000000000 - 1, t.nsecs); 81 | } 82 | 83 | @Test 84 | public void testIsZero() { 85 | assertTrue(new Time(0, 0).isZero()); 86 | assertFalse(new Time(1, 0).isZero()); 87 | assertFalse(new Time(0, 1).isZero()); 88 | } 89 | 90 | @Test 91 | public void testComparable() { 92 | assertEquals(0, new Time(0, 0).compareTo(new Time(0, 0))); 93 | assertEquals(0, new Time(1, 1).compareTo(new Time(1, 1))); 94 | assertTrue(new Time(0, 1).compareTo(new Time(0, 0)) > 0); 95 | 96 | assertEquals(-1, new Time(0, 0).compareTo(new Time(0, 1))); 97 | assertTrue(new Time(0, 0).compareTo(new Time(0, 1)) < 0); 98 | assertTrue(new Time(1, 0).compareTo(new Time(0, 0)) > 0); 99 | assertTrue(new Time(0, 0).compareTo(new Time(1, 0)) < 0); 100 | 101 | } 102 | } -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Point.msg: -------------------------------------------------------------------------------- 1 | # This contains the position of a point in free space 2 | float64 x 3 | float64 y 4 | float64 z 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Point32.msg: -------------------------------------------------------------------------------- 1 | # This contains the position of a point in free space(with 32 bits of precision). 2 | # It is recommeded to use Point wherever possible instead of Point32. 3 | # 4 | # This recommendation is to promote interoperability. 5 | # 6 | # This message is designed to take up less space when sending 7 | # lots of points at once, as in the case of a PointCloud. 8 | 9 | float32 x 10 | float32 y 11 | float32 z -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PointStamped.msg: -------------------------------------------------------------------------------- 1 | # This represents a Point with reference coordinate frame and timestamp 2 | Header header 3 | Point point 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Polygon.msg: -------------------------------------------------------------------------------- 1 | #A specification of a polygon where the first and last points are assumed to be connected 2 | Point32[] points 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PolygonStamped.msg: -------------------------------------------------------------------------------- 1 | # This represents a Polygon with reference coordinate frame and timestamp 2 | Header header 3 | Polygon polygon 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Pose.msg: -------------------------------------------------------------------------------- 1 | # A representation of pose in free space, composed of postion and orientation. 2 | Point position 3 | Quaternion orientation 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Pose2D.msg: -------------------------------------------------------------------------------- 1 | # This expresses a position and orientation on a 2D manifold. 2 | 3 | float64 x 4 | float64 y 5 | float64 theta -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PoseArray.msg: -------------------------------------------------------------------------------- 1 | # An array of poses with a header for global reference. 2 | 3 | Header header 4 | 5 | Pose[] poses 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PoseStamped.msg: -------------------------------------------------------------------------------- 1 | # A Pose with reference coordinate frame and timestamp 2 | Header header 3 | Pose pose 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PoseWithCovariance.msg: -------------------------------------------------------------------------------- 1 | # This represents a pose in free space with uncertainty. 2 | 3 | Pose pose 4 | 5 | # Row-major representation of the 6x6 covariance matrix 6 | # The orientation parameters use a fixed-axis representation. 7 | # In order, the parameters are: 8 | # (x, y, z, rotation about X axis, rotation about Y axis, rotation about Z axis) 9 | float64[36] covariance 10 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/PoseWithCovarianceStamped.msg: -------------------------------------------------------------------------------- 1 | # This expresses an estimated pose with a reference coordinate frame and timestamp 2 | 3 | Header header 4 | PoseWithCovariance pose 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Quaternion.msg: -------------------------------------------------------------------------------- 1 | # This represents an orientation in free space in quaternion form. 2 | 3 | float64 x 4 | float64 y 5 | float64 z 6 | float64 w 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/QuaternionStamped.msg: -------------------------------------------------------------------------------- 1 | # This represents an orientation with reference coordinate frame and timestamp. 2 | 3 | Header header 4 | Quaternion quaternion 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Transform.msg: -------------------------------------------------------------------------------- 1 | # This represents the transform between two coordinate frames in free space. 2 | 3 | Vector3 translation 4 | Quaternion rotation 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/TransformStamped.msg: -------------------------------------------------------------------------------- 1 | # This expresses a transform from coordinate frame header.frame_id 2 | # to the coordinate frame child_frame_id 3 | # 4 | # This message is mostly used by the 5 | # tf package. 6 | # See its documentation for more information. 7 | 8 | Header header 9 | string child_frame_id # the frame id of the child frame 10 | Transform transform 11 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Twist.msg: -------------------------------------------------------------------------------- 1 | # This expresses velocity in free space broken into its linear and angular parts. 2 | Vector3 linear 3 | Vector3 angular 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/TwistStamped.msg: -------------------------------------------------------------------------------- 1 | # A twist with reference coordinate frame and timestamp 2 | Header header 3 | Twist twist 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/TwistWithCovariance.msg: -------------------------------------------------------------------------------- 1 | # This expresses velocity in free space with uncertainty. 2 | 3 | Twist twist 4 | 5 | # Row-major representation of the 6x6 covariance matrix 6 | # The orientation parameters use a fixed-axis representation. 7 | # In order, the parameters are: 8 | # (x, y, z, rotation about X axis, rotation about Y axis, rotation about Z axis) 9 | float64[36] covariance 10 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/TwistWithCovarianceStamped.msg: -------------------------------------------------------------------------------- 1 | # This represents an estimated twist with reference coordinate frame and timestamp. 2 | Header header 3 | TwistWithCovariance twist 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Vector3.msg: -------------------------------------------------------------------------------- 1 | # This represents a vector in free space. 2 | 3 | float64 x 4 | float64 y 5 | float64 z -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Vector3Stamped.msg: -------------------------------------------------------------------------------- 1 | # This represents a Vector3 with reference coordinate frame and timestamp 2 | Header header 3 | Vector3 vector 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/Wrench.msg: -------------------------------------------------------------------------------- 1 | # This represents force in free space, separated into 2 | # its linear and angular parts. 3 | Vector3 force 4 | Vector3 torque 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/geometry_msgs/msg/WrenchStamped.msg: -------------------------------------------------------------------------------- 1 | # A wrench with reference coordinate frame and timestamp 2 | Header header 3 | Wrench wrench 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/action/GetMap.action: -------------------------------------------------------------------------------- 1 | # Get the map as a nav_msgs/OccupancyGrid 2 | --- 3 | nav_msgs/OccupancyGrid map 4 | --- 5 | # no feedback -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapAction.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | 3 | GetMapActionGoal action_goal 4 | GetMapActionResult action_result 5 | GetMapActionFeedback action_feedback 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapActionFeedback.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | 3 | Header header 4 | actionlib_msgs/GoalStatus status 5 | GetMapFeedback feedback 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapActionGoal.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | 3 | Header header 4 | actionlib_msgs/GoalID goal_id 5 | GetMapGoal goal 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapActionResult.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | 3 | Header header 4 | actionlib_msgs/GoalStatus status 5 | GetMapResult result 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapFeedback.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | # no feedback 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapGoal.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | # Get the map as a nav_msgs/OccupancyGrid 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GetMapResult.msg: -------------------------------------------------------------------------------- 1 | # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== 2 | nav_msgs/OccupancyGrid map 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/GridCells.msg: -------------------------------------------------------------------------------- 1 | #an array of cells in a 2D grid 2 | Header header 3 | float32 cell_width 4 | float32 cell_height 5 | geometry_msgs/Point[] cells 6 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/MapMetaData.msg: -------------------------------------------------------------------------------- 1 | # This hold basic information about the characterists of the OccupancyGrid 2 | 3 | # The time at which the map was loaded 4 | time map_load_time 5 | # The map resolution [m/cell] 6 | float32 resolution 7 | # Map width [cells] 8 | uint32 width 9 | # Map height [cells] 10 | uint32 height 11 | # The origin of the map [m, m, rad]. This is the real-world pose of the 12 | # cell (0,0) in the map. 13 | geometry_msgs/Pose origin -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/OccupancyGrid.msg: -------------------------------------------------------------------------------- 1 | # This represents a 2-D grid map, in which each cell represents the probability of 2 | # occupancy. 3 | 4 | Header header 5 | 6 | #MetaData for the map 7 | MapMetaData info 8 | 9 | # The map data, in row-major order, starting with (0,0). Occupancy 10 | # probabilities are in the range [0,100]. Unknown is -1. 11 | int8[] data 12 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/Odometry.msg: -------------------------------------------------------------------------------- 1 | # This represents an estimate of a position and velocity in free space. 2 | # The pose in this message should be specified in the coordinate frame given by header.frame_id. 3 | # The twist in this message should be specified in the coordinate frame given by the child_frame_id 4 | Header header 5 | string child_frame_id 6 | geometry_msgs/PoseWithCovariance pose 7 | geometry_msgs/TwistWithCovariance twist 8 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/msg/Path.msg: -------------------------------------------------------------------------------- 1 | #An array of poses that represents a Path for a robot to follow 2 | Header header 3 | geometry_msgs/PoseStamped[] poses 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/srv/GetMap.srv: -------------------------------------------------------------------------------- 1 | # Get the map as a nav_msgs/OccupancyGrid 2 | --- 3 | nav_msgs/OccupancyGrid map 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/nav_msgs/srv/GetPlan.srv: -------------------------------------------------------------------------------- 1 | # Get a plan from the current position to the goal Pose 2 | 3 | # The start pose for the plan 4 | geometry_msgs/PoseStamped start 5 | 6 | # The final pose of the goal position 7 | geometry_msgs/PoseStamped goal 8 | 9 | # If the goal is obstructed, how many meters the planner can 10 | # relax the constraint in x and y before failing. 11 | float32 tolerance 12 | --- 13 | nav_msgs/Path plan 14 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Bool.msg: -------------------------------------------------------------------------------- 1 | bool data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Byte.msg: -------------------------------------------------------------------------------- 1 | byte data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/ByteMultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | byte[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Char.msg: -------------------------------------------------------------------------------- 1 | char data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/ColorRGBA.msg: -------------------------------------------------------------------------------- 1 | float32 r 2 | float32 g 3 | float32 b 4 | float32 a 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Duration.msg: -------------------------------------------------------------------------------- 1 | duration data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Empty.msg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rosjava/rosjava_bootstrap/e971dff6284e406067df4c7aa04843ec20c9be54/message_generation/src/test/resources/std_msgs/msg/Empty.msg -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Float32.msg: -------------------------------------------------------------------------------- 1 | float32 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Float32MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | float32[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Float64.msg: -------------------------------------------------------------------------------- 1 | float64 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Float64MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | float64[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Header.msg: -------------------------------------------------------------------------------- 1 | # Standard metadata for higher-level stamped data types. 2 | # This is generally used to communicate timestamped data 3 | # in a particular coordinate frame. 4 | # 5 | # sequence ID: consecutively increasing ID 6 | uint32 seq 7 | #Two-integer timestamp that is expressed as: 8 | # * stamp.secs: seconds (stamp_secs) since epoch 9 | # * stamp.nsecs: nanoseconds since stamp_secs 10 | # time-handling sugar is provided by the client library 11 | time stamp 12 | #Frame this data is associated with 13 | # 0: no frame 14 | # 1: global frame 15 | string frame_id 16 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int16.msg: -------------------------------------------------------------------------------- 1 | int16 data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int16MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | int16[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int32.msg: -------------------------------------------------------------------------------- 1 | int32 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int32MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | int32[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int64.msg: -------------------------------------------------------------------------------- 1 | int64 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int64MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | int64[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int8.msg: -------------------------------------------------------------------------------- 1 | int8 data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Int8MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | int8[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/MultiArrayDimension.msg: -------------------------------------------------------------------------------- 1 | string label # label of given dimension 2 | uint32 size # size of given dimension (in type units) 3 | uint32 stride # stride of given dimension -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/MultiArrayLayout.msg: -------------------------------------------------------------------------------- 1 | # The multiarray declares a generic multi-dimensional array of a 2 | # particular data type. Dimensions are ordered from outer most 3 | # to inner most. 4 | 5 | MultiArrayDimension[] dim # Array of dimension properties 6 | uint32 data_offset # padding bytes at front of data 7 | 8 | # Accessors should ALWAYS be written in terms of dimension stride 9 | # and specified outer-most dimension first. 10 | # 11 | # multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k] 12 | # 13 | # A standard, 3-channel 640x480 image with interleaved color channels 14 | # would be specified as: 15 | # 16 | # dim[0].label = "height" 17 | # dim[0].size = 480 18 | # dim[0].stride = 3*640*480 = 921600 (note dim[0] stride is just size of image) 19 | # dim[1].label = "width" 20 | # dim[1].size = 640 21 | # dim[1].stride = 3*640 = 1920 22 | # dim[2].label = "channel" 23 | # dim[2].size = 3 24 | # dim[2].stride = 3 25 | # 26 | # multiarray(i,j,k) refers to the ith row, jth column, and kth channel. -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/String.msg: -------------------------------------------------------------------------------- 1 | string data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/Time.msg: -------------------------------------------------------------------------------- 1 | time data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt16.msg: -------------------------------------------------------------------------------- 1 | uint16 data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt16MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | uint16[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt32.msg: -------------------------------------------------------------------------------- 1 | uint32 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt32MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | uint32[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt64.msg: -------------------------------------------------------------------------------- 1 | uint64 data -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt64MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | uint64[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt8.msg: -------------------------------------------------------------------------------- 1 | uint8 data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_msgs/msg/UInt8MultiArray.msg: -------------------------------------------------------------------------------- 1 | # Please look at the MultiArrayLayout message definition for 2 | # documentation on all multiarrays. 3 | 4 | MultiArrayLayout layout # specification of data layout 5 | uint8[] data # array of data 6 | 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/std_srvs/srv/Empty.srv: -------------------------------------------------------------------------------- 1 | --- -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/ArrayVal.msg: -------------------------------------------------------------------------------- 1 | Val[] vals 2 | #Val[10] vals_fixed 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/Composite.msg: -------------------------------------------------------------------------------- 1 | # composite message. required for testing import calculation in generators 2 | CompositeA a 3 | CompositeB b 4 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/CompositeA.msg: -------------------------------------------------------------------------------- 1 | # This represents an orientation in free space in quaternion form. 2 | 3 | float64 x 4 | float64 y 5 | float64 z 6 | float64 w 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/CompositeB.msg: -------------------------------------------------------------------------------- 1 | # copy of geometry_msgs/Point for testing 2 | float64 x 3 | float64 y 4 | float64 z 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/EmbedTest.msg: -------------------------------------------------------------------------------- 1 | std_msgs/String str1 2 | std_msgs/Int32 int1 3 | std_msgs/Int32[] ints 4 | Val val 5 | Val[] vals 6 | ArrayVal[] arrayval 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/Floats.msg: -------------------------------------------------------------------------------- 1 | # exact copy of rospy_tutorials/Floats, used for testing 2 | float32[] data 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/HeaderHeaderVal.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | HeaderVal val -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/HeaderVal.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | string val -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/PythonKeyword.msg: -------------------------------------------------------------------------------- 1 | int32 yield 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestArrays.msg: -------------------------------------------------------------------------------- 1 | # caller_id of most recent node to send this message 2 | string caller_id 3 | # caller_id of the original node to send this message 4 | string orig_caller_id 5 | 6 | int32[] int32_array 7 | float32[] float32_array 8 | time[] time_array 9 | TestString[] test_string_array 10 | # TODO: array of arrays 11 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestConstants.msg: -------------------------------------------------------------------------------- 1 | float32 A=-123.0 2 | float32 B=124.0 3 | float64 C=125.0 4 | int32 X=123 5 | int32 Y=-123 6 | uint32 Z=124 7 | string FOO=foo 8 | string SINGLEQUOTE='hi 9 | string DOUBLEQUOTE="hello" there 10 | string MULTIQUOTE="hello" 'goodbye' 11 | string EXAMPLE="#comments" are ignored, and leading and trailing whitespace removed 12 | string WHITESPACE= strip 13 | string EMPTY= 14 | bool TRUE=1 15 | bool FALSE=0 -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestFixedArray.msg: -------------------------------------------------------------------------------- 1 | float32[1] f32_1 2 | float32[3] f32_3 3 | float64[1] f64_1 4 | float64[3] f64_3 5 | int8[1] i8_1 6 | int8[3] i8_3 7 | uint8[1] u8_1 8 | uint8[3] u8_3 9 | int32[1] i32_1 10 | int32[3] i32_3 11 | uint32[1] u32_1 12 | uint32[3] u32_3 13 | string[1] s_1 14 | string[3] s_3 15 | bool[1] b_1 16 | bool[3] b_3 -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestHeader.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | # caller_id of most recent node to send this message 4 | string caller_id 5 | # caller_id of the original node to send this message 6 | string orig_caller_id 7 | 8 | byte auto_header # autoset header on response 9 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestPrimitives.msg: -------------------------------------------------------------------------------- 1 | # Integration test message of all primitive types 2 | 3 | # caller_id of most recent node to send this message 4 | string caller_id 5 | # caller_id of the original node to send this message 6 | string orig_caller_id 7 | 8 | string str 9 | byte b 10 | int16 int16 11 | int32 int32 12 | int64 int64 13 | char c 14 | uint16 uint16 15 | uint32 uint32 16 | uint64 uint64 17 | float32 float32 18 | float64 float64 19 | time t 20 | duration d 21 | 22 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TestString.msg: -------------------------------------------------------------------------------- 1 | # Integration test message 2 | # caller_id of most recent node to send this message 3 | string caller_id 4 | # caller_id of the original node to send this message 5 | string orig_caller_id 6 | string data 7 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TransitiveImport.msg: -------------------------------------------------------------------------------- 1 | # Bug #2133/2139: EmbedTest uses std_msgs, so TransitiveImport needs it as well 2 | EmbedTest data -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TransitiveMsg1.msg: -------------------------------------------------------------------------------- 1 | TransitiveMsg2 msg2 2 | 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/TransitiveMsg2.msg: -------------------------------------------------------------------------------- 1 | test_msgs/Composite data 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/msg/Val.msg: -------------------------------------------------------------------------------- 1 | string val -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/AddTwoInts.srv: -------------------------------------------------------------------------------- 1 | int64 a 2 | int64 b 3 | --- 4 | int64 sum 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/ConstantsMultiplex.srv: -------------------------------------------------------------------------------- 1 | byte BYTE_X=0 2 | byte BYTE_Y=15 3 | byte BYTE_Z=5 4 | int32 INT32_X=0 5 | int32 INT32_Y=-12345678 6 | int32 INT32_Z=12345678 7 | uint32 UINT32_X=0 8 | uint32 UINT32_Y=12345678 9 | uint32 UINT32_Z=1 10 | float32 FLOAT32_X=0.0 11 | float32 FLOAT32_Y=-3.14159 12 | float32 FLOAT32_Z=12345.78 13 | byte SELECT_X=1 14 | byte SELECT_Y=2 15 | byte SELECT_Z=3 16 | byte selection 17 | --- 18 | # test response constants as well 19 | byte CONFIRM_X=1 20 | byte CONFIRM_Y=2 21 | byte CONFIRM_Z=3 22 | byte select_confirm 23 | byte ret_byte 24 | int32 ret_int32 25 | uint32 ret_uint32 26 | float32 ret_float32 -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/EmptyReqSrv.srv: -------------------------------------------------------------------------------- 1 | --- 2 | int32 fake_secret 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/EmptyRespSrv.srv: -------------------------------------------------------------------------------- 1 | int32 fake_secret 2 | --- 3 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/EmptySrv.srv: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/ListReturn.srv: -------------------------------------------------------------------------------- 1 | # test case for having single list return value 2 | int32 a 3 | int32 b 4 | int32 c 5 | int32 d 6 | --- 7 | int32[] abcd 8 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/MultipleAddTwoInts.srv: -------------------------------------------------------------------------------- 1 | # test case for having multiple return values 2 | int32 a 3 | int32 b 4 | int32 c 5 | int32 d 6 | --- 7 | int32 ab 8 | int32 cd -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/StringString.srv: -------------------------------------------------------------------------------- 1 | std_msgs/String str 2 | Val str2 3 | --- 4 | std_msgs/String str 5 | -------------------------------------------------------------------------------- /message_generation/src/test/resources/test_msgs/srv/TransitiveSrv.srv: -------------------------------------------------------------------------------- 1 | test_msgs/TransitiveMsg1 msg 2 | --- 3 | int32 a 4 | 5 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | rosjava_bootstrap 4 | 0.3.3 5 | 6 | Bootstrap utilities for rosjava builds. 7 | 8 | http://ros.org/wiki/rosjava_bootstrap 9 | Daniel Stonier 10 | Daniel Stonier 11 | Damon Kohler 12 | Apache 2.0 13 | catkin 14 | rosjava_build_tools 15 | rosjava_build_tools 16 | 17 | 18 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | include 'gradle_plugins' 18 | include 'message_generation' --------------------------------------------------------------------------------