admin_app_interface.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_qt_gui/license/LICENSE
00005 #
00006 import rospy
00007 import rocon_python_comms
00008 
00009 import concert_msgs.msg as concert_msgs
00010 import rocon_std_msgs.msg as rocon_std_msgs
00011 
00012 from concert_msgs.srv import EnableService
00013 from concert_msgs.srv import UpdateServiceConfig
00014 
00015 from rocon_python_comms.exceptions import NotFoundException
00016 ##############################################################################
00017 # Graph
00018 ##############################################################################
00019 
00020 
00021 class AdminAppInterface(object):
00022 
00023     def __init__(self):
00024         self._event_callback = None
00025         self.full_params_path = ""
00026         self.service_list = {}
00027         self.ros_subscribers = {}
00028         self.ros_services = {}
00029 
00030     def _init_admin_app_interface(self):
00031         self._init_ros_subscriber()
00032         self._init_ros_service()
00033 
00034     def _init_ros_subscriber(self):
00035         try:
00036             subscriber_topic_name = rocon_python_comms.find_topic('concert_msgs/Services', timeout=rospy.rostime.Duration(5.0), unique=True)
00037             self.ros_subscribers['service_list'] = rospy.Subscriber(subscriber_topic_name, concert_msgs.Services, self.update_service_list)
00038         except NotFoundException as e:
00039             raise e
00040 
00041     def _init_ros_service(self):
00042         try:
00043             enable_service = rocon_python_comms.find_service('concert_msgs/EnableService', timeout=rospy.rostime.Duration(5.0), unique=True)
00044             self.ros_services['enable_service'] = rospy.ServiceProxy(enable_service, EnableService)
00045             update_service_config = rocon_python_comms.find_service('concert_msgs/UpdateServiceConfig', timeout=rospy.rostime.Duration(5.0), unique=True)
00046             self.ros_services['update_service_config'] = rospy.ServiceProxy(update_service_config, UpdateServiceConfig)
00047         except NotFoundException as e:
00048             raise e
00049 
00050     def _reg_event_callback(self, func):
00051         self._event_callback = func
00052 
00053     def eable_service(self, srv_name):
00054         # todo
00055         call_result = self.ros_services['enable_service'](srv_name, True)
00056         return call_result.success, call_result.error_message
00057 
00058     def disable_service(self, srv_name):
00059         # todo
00060         call_result = self.ros_services['enable_service'](srv_name, False)
00061         return call_result.success, call_result.error_message
00062 
00063     def update_service_config(self, srv_profile):
00064         # todo
00065         call_result = self.ros_services['update_service_config'](srv_profile)
00066         return (call_result.success, call_result.error_message)
00067 
00068     def get_srv_parameters(self, parameters_detail):
00069         params = None
00070         params = {}
00071         for param in parameters_detail:
00072             params[param.key] = param.value
00073         return params
00074 
00075     def set_srv_parameters(self, srv_name, param_data):
00076         result = False
00077         message = ""
00078         try:
00079             srv_profile_msg = concert_msgs.ServiceProfile()
00080             srv_profile_msg.name = srv_name
00081             parameter_detail = []
00082             for key in param_data.keys():
00083                 parameter = rocon_std_msgs.KeyValue(key, param_data[key])
00084                 parameter_detail.append(parameter)
00085             srv_profile_msg.parameters_detail = parameter_detail
00086             (result, message) = self.update_service_config(srv_profile_msg)
00087         except Exception, e:
00088             rospy.loginfo(e)
00089             message = str(e)            
00090             result = False
00091         return (result, message)
00092 
00093     def update_service_list(self, data):
00094 
00095         self.service_list = {}
00096         for k in data.services:
00097             service_name = k.name
00098             self.service_list[service_name] = {}
00099             self.service_list[service_name]['name'] = service_name
00100             self.service_list[service_name]['resource_name'] = k.resource_name
00101             self.service_list[service_name]['description'] = k.description
00102 
00103             self.service_list[service_name]['author'] = k.author
00104             self.service_list[service_name]['priority'] = k.priority
00105             self.service_list[service_name]['launcher_type'] = k.launcher_type
00106             self.service_list[service_name]['launcher'] = k.launcher
00107             self.service_list[service_name]['interactions'] = k.interactions
00108             self.service_list[service_name]['parameters'] = k.parameters
00109             self.service_list[service_name]['parameters_detail'] = k.parameters_detail
00110             self.service_list[service_name]['uuid'] = k.uuid
00111             self.service_list[service_name]['status'] = k.status
00112             self.service_list[service_name]['enabled'] = k.enabled
00113 
00114             # html
00115             service_context = "<html>"
00116             for key in self.service_list[service_name].keys():
00117                 service_context += "<p><b>" + key + ": </b>" + str(self.service_list[service_name][key]) + "</p>"
00118             service_context += "</html>"
00119             self.service_list[service_name]['context'] = service_context
00120 
00121         if self._event_callback != None:
00122             self._event_callback()


concert_admin_app
Author(s): Daniel Stonier, Donguk Lee
autogenerated on Fri Feb 12 2016 02:49:54