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
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
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
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
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
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 | Collectiontrue
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