当前位置: 首页>>代码示例>>Python>>正文


Python Server.get_available_services方法代码示例

本文整理汇总了Python中jsonrpclib.Server.get_available_services方法的典型用法代码示例。如果您正苦于以下问题:Python Server.get_available_services方法的具体用法?Python Server.get_available_services怎么用?Python Server.get_available_services使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonrpclib.Server的用法示例。


在下文中一共展示了Server.get_available_services方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RVI

# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import get_available_services [as 别名]
class RVI(SimpleJSONRPCServer):
    # address is either localhost or the ip address of self.
    # 0.0.0.0 should work to listen to all addresses, but haven't been tested
    # Port is either a fixed port (integer) or a tuple with a start and stop
    # port that should be used as a random interval to pick the port from
    def __init__(self, rvi_node_url, address='localhost', port=(20001,59999)):
        if isinstance(port, tuple) == True:
            (start_port, stop_port) = port
            self.rvi_port = random.randint(start_port, stop_port)
        else:
            self.rvi_port = port

        self.rvi_address = address
        SimpleJSONRPCServer.__init__(self,addr=((self.rvi_address, self.rvi_port)), logRequests=False)
        self.rvi_client = Server(rvi_node_url)
        self.serve_thread = False
        self.registered_services = dict()
        
    # Set the callback to invoke when RVI reports that one or more new 
    # services are available for invocation somewhere in the network.
    # Arguments will be an array of fully qualified service available.
    def set_services_available_callback(self, function):
        self.register_function(function, 'services_available')
        
    # Set the callback to invoke when RVI reports that one or more previously
    # available services are no longer available for invocation
    #
    # Arguments will be an array of fully qualified service names no longer available.
    def set_services_unavailable_callback(self, function):
        self.register_function(function, 'services_unavailable')
        
    def get_available_services(self):
        # We need at least one dummy argument for the RPC to go
        # through on the RVI side.
        res = self.rvi_client.get_available_services(1)
        return res['services']

    # Register a service in this python program that should
    # be reached from the rest of the network.
    #
    # service_name is the local service name ('/my_stuff/set_fan_speed')
    #
    # function is a python function reference to invoke when an
    # JSON-RPC call for service_nameis received from RVI.
    #
    # This function will return the fully qualified name of the registered service.
    #
    # Thus, if you call:
    #
    #    register_service('/my_stuff/set_fan_speed', set_fan_speed)
    #
    # you will get back the fully qualified service name assigned:
    #
    #    "jlr.com/vin/YV1TS32G54F123456/my_stuff/set_fan_speed"
    #
    # This is the globally accessible name for the service that can be used anywhere
    # in an RVI network to access your service.
    #
    def register_service(self, service_name, function):
        # Add a prefixing slash if necessary
        if service_name[0] != '/':
            service_name = '/' + service_name

        # Register service_name within SimpleJSONRPCServer so that
        # when it gets invoked with the given URL suffic, it will call 'function'.
        #
        # I.e. when self.url() + service_name gets called by the RVI node, we
        # will dispatch that call to 'function'.
        #
        self.register_function(function, service_name)

        # Register the service name with the RVI node so that we get called
        # at the URL we are listening on (self.url()).
        #
        res = self.rvi_client.register_service(service=service_name, network_address=self.url())
        
        # Check if we have a thread going
        if self.serve_thread == False:
            self.start_serve_thread()
            
        full_service_name = res['service']
        self.registered_services[service_name] = full_service_name

        # Return the fully qualified service name
        return res['service']

    # Unregister a service 
    #  Unregisters a service previously registered with register_service
    #  The provided 'service_name' is identical to that provided tgo
    #  retister_service()
    #
    def unregister_service(self, service_name):

        if service_name[0] != '/':
            service_name = '/' + service_name

        # Check that the service has been previously registered
        # If not just return
        if service_name not in self.registered_services:
            return False
#.........这里部分代码省略.........
开发者ID:jochenschneider,项目名称:rvi_core,代码行数:103,代码来源:rvilib.py


注:本文中的jsonrpclib.Server.get_available_services方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。