23
23
import org .ros .internal .transport .ConnectionHeader ;
24
24
import org .ros .internal .transport .ConnectionHeaderFields ;
25
25
import org .ros .namespace .GraphName ;
26
+ import org .ros .node .topic .TransportHints ;
26
27
27
28
import java .util .List ;
28
29
import java .util .Map ;
@@ -36,6 +37,7 @@ public class TopicDeclaration {
36
37
37
38
private final TopicIdentifier topicIdentifier ;
38
39
private final TopicDescription topicDescription ;
40
+ private final TransportHints transportHints ;
39
41
40
42
/**
41
43
* @param header
@@ -49,19 +51,26 @@ public static TopicDeclaration newFromHeader(Map<String, String> header) {
49
51
String definition = header .get (ConnectionHeaderFields .MESSAGE_DEFINITION );
50
52
String md5Checksum = header .get (ConnectionHeaderFields .MD5_CHECKSUM );
51
53
TopicDescription topicDescription = new TopicDescription (type , definition , md5Checksum );
52
- return new TopicDeclaration (new TopicIdentifier (name ), topicDescription );
54
+ boolean tcpNoDelay = "1" .equals (header .get (ConnectionHeaderFields .TCP_NODELAY ));
55
+ return new TopicDeclaration (new TopicIdentifier (name ), topicDescription , new TransportHints (tcpNoDelay ));
53
56
}
54
57
55
58
public static TopicDeclaration newFromTopicName (GraphName topicName ,
56
- TopicDescription topicDescription ) {
57
- return new TopicDeclaration (new TopicIdentifier (topicName ), topicDescription );
59
+ TopicDescription topicDescription , TransportHints transportHints ) {
60
+ return new TopicDeclaration (new TopicIdentifier (topicName ), topicDescription , transportHints );
58
61
}
59
62
60
- public TopicDeclaration (TopicIdentifier topicIdentifier , TopicDescription topicDescription ) {
63
+ public TopicDeclaration (TopicIdentifier topicIdentifier , TopicDescription topicDescription , TransportHints transportHints ) {
61
64
Preconditions .checkNotNull (topicIdentifier );
62
65
Preconditions .checkNotNull (topicDescription );
63
66
this .topicIdentifier = topicIdentifier ;
64
67
this .topicDescription = topicDescription ;
68
+
69
+ if (transportHints != null ) {
70
+ this .transportHints = transportHints ;
71
+ } else {
72
+ this .transportHints = new TransportHints ();
73
+ }
65
74
}
66
75
67
76
public TopicIdentifier getIdentifier () {
@@ -84,6 +93,7 @@ public ConnectionHeader toConnectionHeader() {
84
93
topicDescription .getDefinition ());
85
94
connectionHeader .addField (ConnectionHeaderFields .MD5_CHECKSUM ,
86
95
topicDescription .getMd5Checksum ());
96
+ connectionHeader .addField (ConnectionHeaderFields .TCP_NODELAY , transportHints .getTcpNoDelay () ? "1" : "0" );
87
97
return connectionHeader ;
88
98
}
89
99
0 commit comments