def rpc(method):
@wraps(method)<EOL>def rpc_wrapper(*args, **kwargs):<EOL><INDENT>controller_instance = args[<NUM_LIT:0>]<EOL>if not isinstance(controller_instance, RemoteControllerDeamon):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>call_from_server = os.getpid() == controller_instance.get_pid()<EOL>logger.debug("<STR_LIT>", method.__name__, '<STR_LIT>' if call_from_server else '<STR_LIT>')<EOL>if call_from_server:<EOL><INDENT>return method(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>url = "<STR_LIT>".format(controller_instance.host, controller_instance.port)<EOL>headers = {'<STR_LIT>': '<STR_LIT:application/json>'}<EOL>payload = {<EOL>"<STR_LIT>": method.__name__,<EOL>"<STR_LIT>": kwargs,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:id>": <NUM_LIT:0>,<EOL>}<EOL>try:<EOL><INDENT>response = requests.post(url, data=json.dumps(payload), headers=headers).json()<EOL>if '<STR_LIT:result>' in response:<EOL><INDENT>return response['<STR_LIT:result>']<EOL><DEDENT>else:<EOL><INDENT>logger.error("<STR_LIT>", json.dumps(response, indent=<NUM_LIT:4>))<EOL>return "<STR_LIT>".format(response['<STR_LIT:error>']['<STR_LIT:message>'])<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError as e:<EOL><INDENT>logger.error("<STR_LIT>", e, args, kwargs)<EOL>return None<EOL><DEDENT><DEDENT><DEDENT>rpc_wrapper.registered_for_rpc = method<EOL>return rpc_wrapper<EOL>
Decorator function for register method for RPC.
Must be used a RemoteControllerDeamon (-derived) class method!