Go to the documentation of this file.00001 from rosbridge_library.capability import Capability
00002 from advertise_service import ReceivedResponses
00003 from rosbridge_library.internal import ros_loader, message_conversion
00004
00005
00006 try:
00007 import ujson as json
00008 except ImportError:
00009 try:
00010 import simplejson as json
00011 except ImportError:
00012 import json
00013
00014
00015
00016 class ServiceResponse(Capability):
00017
00018
00019
00020
00021 opcode_service_response = "service_response"
00022 response_list = ReceivedResponses().list
00023
00024 def __init__(self, protocol):
00025 self.protocol = protocol
00026 Capability.__init__(self, protocol)
00027
00028 protocol.register_operation(self.opcode_service_response, self.service_response)
00029
00030
00031 def service_response(self, message):
00032
00033
00034
00035
00036
00037 request = self.protocol.request_list[message["request_id"]]
00038
00039
00040 service_module = request["service_module"]
00041 service_type = request["service_type"]
00042
00043
00044 inst = ros_loader.get_service_response_instance(service_module+"/"+service_type)
00045
00046
00047 message_conversion.populate_instance(message["data"], inst)
00048
00049
00050 self.response_list[message["request_id"]] = inst
00051
00052
00053 def finish(self):
00054 self.protocol.unregister_operation("service_response")
00055
00056
00057
00058
00059
00060