23
23
import org .ros .exception .RosMessageRuntimeException ;
24
24
import org .ros .internal .message .definition .MessageDefinitionProviderChain ;
25
25
import org .ros .internal .message .definition .MessageDefinitionTupleParser ;
26
+ import org .ros .internal .message .action .ActionDefinitionFileProvider ;
26
27
import org .ros .internal .message .service .ServiceDefinitionFileProvider ;
27
28
import org .ros .internal .message .topic .TopicDefinitionFileProvider ;
28
29
import org .ros .message .MessageDeclaration ;
@@ -42,6 +43,7 @@ public class GenerateInterfaces {
42
43
43
44
private final TopicDefinitionFileProvider topicDefinitionFileProvider ;
44
45
private final ServiceDefinitionFileProvider serviceDefinitionFileProvider ;
46
+ private final ActionDefinitionFileProvider actionDefinitionFileProvider ;
45
47
private final MessageDefinitionProviderChain messageDefinitionProviderChain ;
46
48
private final MessageFactory messageFactory ;
47
49
static private final String ROS_PACKAGE_PATH = "ROS_PACKAGE_PATH" ;
@@ -52,6 +54,8 @@ public GenerateInterfaces() {
52
54
messageDefinitionProviderChain .addMessageDefinitionProvider (topicDefinitionFileProvider );
53
55
serviceDefinitionFileProvider = new ServiceDefinitionFileProvider ();
54
56
messageDefinitionProviderChain .addMessageDefinitionProvider (serviceDefinitionFileProvider );
57
+ actionDefinitionFileProvider = new ActionDefinitionFileProvider ();
58
+ messageDefinitionProviderChain .addMessageDefinitionProvider (actionDefinitionFileProvider );
55
59
messageFactory = new DefaultMessageFactory (messageDefinitionProviderChain );
56
60
}
57
61
@@ -110,15 +114,58 @@ private void writeServiceInterfaces(File outputDirectory, Collection<String> pac
110
114
MessageDeclaration .of (serviceType .getType (), definition );
111
115
writeInterface (serviceDeclaration , outputDirectory , false );
112
116
List <String > requestAndResponse = MessageDefinitionTupleParser .parse (definition , 2 );
117
+
113
118
MessageDeclaration requestDeclaration =
114
119
MessageDeclaration .of (serviceType .getType () + "Request" , requestAndResponse .get (0 ));
115
120
MessageDeclaration responseDeclaration =
116
121
MessageDeclaration .of (serviceType .getType () + "Response" , requestAndResponse .get (1 ));
122
+
117
123
writeInterface (requestDeclaration , outputDirectory , true );
118
124
writeInterface (responseDeclaration , outputDirectory , true );
119
125
}
120
126
}
121
127
128
+ /**
129
+ * @param packages
130
+ * a list of packages containing the topic types to generate
131
+ * interfaces for
132
+ * @param outputDirectory
133
+ * the directory to write the generated interfaces to
134
+ * @throws IOException
135
+ */
136
+ private void writeActionInterfaces (File outputDirectory , Collection <String > packages )
137
+ throws IOException {
138
+ Collection <MessageIdentifier > actionTypes = Sets .newHashSet ();
139
+ if (packages .size () == 0 ) {
140
+ packages = actionDefinitionFileProvider .getPackages ();
141
+ }
142
+ for (String pkg : packages ) {
143
+ Collection <MessageIdentifier > messageIdentifiers =
144
+ actionDefinitionFileProvider .getMessageIdentifiersByPackage (pkg );
145
+ if (messageIdentifiers != null ) {
146
+ actionTypes .addAll (messageIdentifiers );
147
+ }
148
+ }
149
+ for (MessageIdentifier actionType : actionTypes ) {
150
+ String definition = messageDefinitionProviderChain .get (actionType .getType ());
151
+ MessageDeclaration actionDeclaration =
152
+ MessageDeclaration .of (actionType .getType (), definition );
153
+ writeInterface (actionDeclaration , outputDirectory , false );
154
+ List <String > goalResultAndFeedback = MessageDefinitionTupleParser .parse (definition , 3 );
155
+
156
+ MessageDeclaration goalDeclaration =
157
+ MessageDeclaration .of (actionType .getType () + "Goal" , goalResultAndFeedback .get (0 ));
158
+ MessageDeclaration resultDeclaration =
159
+ MessageDeclaration .of (actionType .getType () + "Response" , goalResultAndFeedback .get (1 ));
160
+ MessageDeclaration feedbackDeclaration =
161
+ MessageDeclaration .of (actionType .getType () + "Feedback" , goalResultAndFeedback .get (2 ));
162
+
163
+ writeInterface (goalDeclaration , outputDirectory , true );
164
+ writeInterface (resultDeclaration , outputDirectory , true );
165
+ writeInterface (feedbackDeclaration , outputDirectory , true );
166
+ }
167
+ }
168
+
122
169
private void writeInterface (MessageDeclaration messageDeclaration , File outputDirectory ,
123
170
boolean addConstantsAndMethods ) {
124
171
MessageInterfaceBuilder builder = new MessageInterfaceBuilder ();
@@ -142,12 +189,15 @@ public void generate(File outputDirectory, Collection<String> packages,
142
189
for (File directory : packagePath ) {
143
190
topicDefinitionFileProvider .addDirectory (directory );
144
191
serviceDefinitionFileProvider .addDirectory (directory );
192
+ actionDefinitionFileProvider .addDirectory (directory );
145
193
}
146
194
topicDefinitionFileProvider .update ();
147
195
serviceDefinitionFileProvider .update ();
196
+ actionDefinitionFileProvider .update ();
148
197
try {
149
198
writeTopicInterfaces (outputDirectory , packages );
150
199
writeServiceInterfaces (outputDirectory , packages );
200
+ writeActionInterfaces (outputDirectory , packages );
151
201
} catch (IOException e ) {
152
202
throw new RosMessageRuntimeException (e );
153
203
}
@@ -158,6 +208,7 @@ public static void main(String[] args) {
158
208
if (arguments .size () == 0 ) {
159
209
arguments .add ("." );
160
210
}
211
+
161
212
String rosPackagePath = System .getenv (ROS_PACKAGE_PATH );
162
213
// Overwrite with a supplied package path if specified (--package-path=)
163
214
for (ListIterator <String > iter = arguments .listIterator (); iter .hasNext (); ) {
@@ -168,13 +219,15 @@ public static void main(String[] args) {
168
219
break ;
169
220
}
170
221
}
222
+
171
223
Collection <File > packagePath = Lists .newArrayList ();
172
224
for (String path : rosPackagePath .split (File .pathSeparator )) {
173
225
File packageDirectory = new File (path );
174
226
if (packageDirectory .exists ()) {
175
227
packagePath .add (packageDirectory );
176
228
}
177
229
}
230
+
178
231
GenerateInterfaces generateInterfaces = new GenerateInterfaces ();
179
232
File outputDirectory = new File (arguments .remove (0 ));
180
233
generateInterfaces .generate (outputDirectory , arguments , packagePath );
0 commit comments