MCPcopy Create free account
hub / github.com/akio/rosgo / requestTopic

Method requestTopic

ros/node.go:294–329  ·  view source on GitHub ↗
(callerId string, topic string, protocols []interface{})

Source from the content-addressed store, hash-verified

292}
293
294func (node *defaultNode) requestTopic(callerId string, topic string, protocols []interface{}) (interface{}, error) {
295 node.logger.Debugf("Slave API requestTopic(%s, %s, ...) called.", callerId, topic)
296 var code int32
297 var message string
298 var value interface{}
299 if pub, ok := node.publishers[topic]; !ok {
300 node.logger.Debug("requestTopic() called with not publishing topic.")
301 code = 0
302 message = "No such topic"
303 value = nil
304 } else {
305 selectedProtocol := make([]interface{}, 0)
306 for _, v := range protocols {
307 protocolParams := v.([]interface{})
308 protocolName := protocolParams[0].(string)
309 if protocolName == "TCPROS" {
310 node.logger.Debug("TCPROS requested")
311 selectedProtocol = append(selectedProtocol, "TCPROS")
312 host, portStr := pub.hostAndPort()
313 p, err := strconv.ParseInt(portStr, 10, 32)
314 if err != nil {
315 return nil, err
316 }
317 port := int(p)
318 selectedProtocol = append(selectedProtocol, host)
319 selectedProtocol = append(selectedProtocol, port)
320 break
321 }
322 }
323 node.logger.Debug(selectedProtocol)
324 code = 1
325 message = "Success"
326 value = selectedProtocol
327 }
328 return buildRosApiResult(code, message, value), nil
329}
330
331func (node *defaultNode) NewPublisher(topic string, msgType MessageType) Publisher {
332 name := node.nameResolver.remap(topic)

Callers 1

newDefaultNodeFunction · 0.80

Calls 4

buildRosApiResultFunction · 0.85
hostAndPortMethod · 0.80
DebugfMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected