Example #1
0
func requestTopic(publisher_uri, caller_id, topic string, response_data interface{}) error {
	fmt.Printf("  talking to publisher '%s'\n", publisher_uri)

	pub_rpc := xmlrpc.NewClient(publisher_uri)

	tcpros_string := "TCPROS"
	tcpros := make([]xmlrpc.Value, 1)
	tcpros[0] = xmlrpc.Value{String: &tcpros_string}

	protocols := make([]xmlrpc.Value, 1)
	protocols[0] = xmlrpc.Value{Array: &tcpros}

	params := make([]xmlrpc.Param, 3)
	params[0] = xmlrpc.Param{xmlrpc.Value{String: &caller_id}}
	params[1] = xmlrpc.Param{xmlrpc.Value{String: &topic}}
	params[2] = xmlrpc.Param{xmlrpc.Value{Array: &protocols}}

	return pub_rpc.Call("requestTopic", params, response_data)
}
Example #2
0
func Subscribe(node_name, topic_name, type_name string,
	channel interface{}) (*TcpRosSubscriber, error) {

	rpc_client := xmlrpc.NewClient("http://localhost:11311")

	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}

	msg_port := 11317
	msg_uri := fmt.Sprintf("http://%s:%d", hostname, msg_port)

	var response2 xmlrpc.MethodResponse
	err = rpc_client.CallStrings("registerSubscriber",
		[]string{node_name, topic_name, type_name, msg_uri},
		&response2)
	if err != nil {
		return nil, err
	}

	var sub TcpRosSubscriber

	array := *response2.Params[0].Val.Array
	code := *array[0].Int
	status := *array[1].String
	fmt.Printf("got response code: %d, status '%s'\n", code, status)
	pub_ptr := array[2].Array
	if pub_ptr == nil {
		// No publishers yet.  TODO: implement updatePublishers() xmlrpc call.
		return &sub, nil
	}
	publishers := *pub_ptr
	caller_id := node_name
	for i := range publishers {
		publisher_uri := *publishers[i].String
		var response xmlrpc.MethodResponse
		err := requestTopic(publisher_uri, caller_id, "/chatter", &response)
		if err != nil {
			fmt.Printf(" error from requestTopic: %v\n", err)
			continue
		}
		fmt.Printf("response to requestTopic():\n")
		response.Params[0].Val.Print()
		fmt.Printf("woot\n")
		array := response.Params[0].Val.GetArray()
		code, _ := array[0].GetInt()
		status, _ := array[1].GetString()
		fmt.Printf(" requestTopic got response code: %d, status '%s'\n", code, status)
		protocol := array[2].GetArray()
		protocol_name, _ := protocol[0].GetString()
		host, _ := protocol[1].GetString()
		port, _ := protocol[2].GetInt()
		fmt.Printf("  protocol %s %s %d\n", protocol_name, host, port)
		publisher := new(publisherConnection)
		publisher.host = host
		publisher.port = port
		publisher.recvr_node_name = node_name
		publisher.topic_name = topic_name
		publisher.type_name = type_name
		sub.publishers = append(sub.publishers, publisher)
		go publisher.read(channel)
	}
	return &sub, nil
}