Exemplo n.º 1
0
class HMMRepROSServer(object):
    """This class provides a service for all requests specified in
    'qsrrep_lib.rep_io.available_services'. The service name will be the key
    of the entry."""
    def __init__(self, name):
        """
        :param name: The name of the node
        """
        rospy.logdebug("[" + rospy.get_name() + "]: " + "Starting ")
        self._lib = ProbRepLib()
        self.services = {}
        for namespace, services in ServiceManager.available_services.items():
            # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services'
            # Passing the key of the dict entry to the service to identify the right function to call
            for i, service in enumerate(services):
                # The outer lambda function creates a new scope for the inner lambda function
                # This is necessary to preserve the value of k, otherwise it will have the same value for all services
                # x will be substituded by the service request
                rospy.logdebug("[" + rospy.get_name() + "]: " +
                               "Creating service: [" + namespace + "][" +
                               service + "]")
                self.services[service] = rospy.Service(
                    "~" + namespace + "/" + service, QSRProbRep,
                    (lambda a, b: lambda x: self.callback(x, a, b))(namespace,
                                                                    service))
                rospy.logdebug("[" + rospy.get_name() + "]: " + "Created")
        rospy.logdebug("[" + rospy.get_name() + "]: " + "Done")

    def callback(self, req, rep, srv_type):
        r = ServiceManager.available_services[rep][srv_type][0](
            **json.loads(req.data))
        rr = self._lib.request(r)
        dat = rr.get()
        ans = QSRProbRepResponse(data=dat)
        return ans
class HMMRepROSServer(object):
    """This class provides a service for all requests specified in
    'qsrrep_lib.rep_io.available_services'. The service name will be the key
    of the entry."""
    def __init__(self, name):
        """
        :param name: The name of the node
        """
        rospy.loginfo("Starting %s" % name)
        self._hmm_lib = ProbRepLib()
        self._hmm_lib.print_hmms_available()
        self.services = {}
        # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services'
        # Passing the key of the dict entry to the service to identify the right function to call
        for i, k in enumerate(available_services.keys()):
            # The outer lambda function creates a new scope for the inner lambda function
            # This is necessary to preserve the value of k, otherwise it will have the same value for all services
            # x will be substituded by the service request
            self.services[k] = rospy.Service(
                "~" + k, QSRProbRep,
                (lambda b: lambda x: self.callback(x, b))(k))

    def callback(self, req, srv_type):
        r = available_services[srv_type][0](qsr_type=req.qsr_type,
                                            **json.loads(req.data))
        return QSRProbRepResponse(qsr_type=req.qsr_type,
                                  data=self._hmm_lib.request(r).get())
class HMMRepROSServer(object):
    """This class provides a service for all requests specified in
    'qsrrep_lib.rep_io.available_services'. The service name will be the key
    of the entry."""

    def __init__(self, name):
        """
        :param name: The name of the node
        """
        rospy.logdebug( "[" + rospy.get_name() + "]: " + "Starting " )
        self._lib = ProbRepLib()
        self.services = {}
        for namespace, services in ServiceManager.available_services.items():
            # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services'
            # Passing the key of the dict entry to the service to identify the right function to call
            for i, service in enumerate(services):
                # The outer lambda function creates a new scope for the inner lambda function
                # This is necessary to preserve the value of k, otherwise it will have the same value for all services
                # x will be substituded by the service request
                rospy.logdebug( "[" + rospy.get_name() + "]: " + "Creating service: ["+namespace+"]["+service+"]" )
                self.services[service] = rospy.Service("~"+namespace+"/"+service, QSRProbRep, (lambda a,b: lambda x: self.callback(x, a, b))(namespace,service))
                rospy.logdebug( "[" + rospy.get_name() + "]: " + "Created" )
        rospy.logdebug( "[" + rospy.get_name() + "]: " + "Done" )

    def callback(self, req, rep, srv_type):
        r = ServiceManager.available_services[rep][srv_type][0](**json.loads(req.data))
        rr = self._lib.request(r)
        dat = rr.get()
        ans = QSRProbRepResponse(data=dat)
        return ans
class HMMRepROSServer(object):
    """This class provides a service for all requests specified in
    'qsrrep_lib.rep_io.available_services'. The service name will be the key
    of the entry."""

    def __init__(self, name):
        """
        :param name: The name of the node
        """
        rospy.loginfo("Starting %s" % name)
        self._hmm_lib = ProbRepLib()
        self._hmm_lib.print_hmms_available()
        self.services = {}
        # Automatically creating a service for all the entries in 'qsrrep_lib.rep_io.available_services'
        # Passing the key of the dict entry to the service to identify the right function to call
        for i, k in enumerate(available_services.keys()):
            # The outer lambda function creates a new scope for the inner lambda function
            # This is necessary to preserve the value of k, otherwise it will have the same value for all services
            # x will be substituded by the service request
            self.services[k] = rospy.Service("~"+k, QSRProbRep, (lambda b: lambda x: self.callback(x, b))(k))

    def callback(self, req, srv_type):
        r = available_services[srv_type][0](qsr_type=req.qsr_type, **json.loads(req.data))
        return QSRProbRepResponse(qsr_type=req.qsr_type, data=self._hmm_lib.request(r).get())