in leda_python/deviceMbus.py [0:0]
def _callServices(self, interface):
@dbus.service.method(interface, in_signature='ss', out_signature='s')
def callServices(self, methodName, inMsg):
_logger.debug("callServices(cloud_id:%s) in params: method: %s, args: %s", self.cloud_id, methodName, inMsg)
codeInfoDict = {
exception.LEDA_SUCCESS: 'successfully',
exception.LEDA_ERROR_INVAILD_PARAM: 'invalid params',
exception.LEDA_ERROR_FAILED: 'exec failed',
exception.LEDA_ERROR_TIMEOUT: 'timeout',
exception.LEDA_ERROR_NOT_SUPPORT: 'not support',
exception.LEDA_ERROR_PROPERTY_NOT_EXIST: 'property not exist',
exception.LEDA_ERROR_PROPERTY_READ_ONLY: 'property read only',
exception.LEDA_ERROR_PROPERTY_WRITE_ONLY: 'property write only',
exception.LEDA_ERROR_SERVICE_NOT_EXIST: 'service not exist',
exception.LEDA_ERROR_SERVICE_INPUT_PARAM: 'invalid service input params'
}
try:
inArgs = json.loads(inMsg)["params"]
if (methodName == "get"):
code, retInfo = self.callback_funs.getProperties(inArgs)
if (False == isinstance(retInfo, dict) or (False == isinstance(code, int))):
_logger.warning("get(cloud_id:%s) return args type is invalid: %s", self.cloud_id,
type(retInfo))
retDict = {
"code": exception.LEDA_ERROR_INVAILD_PARAM, # params invalid
"message": "get(cloud_id:%s) return args type is invalid: %s" % (
self.cloud_id, type(retInfo)),
"params": {}
}
_logger.debug("get(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, ensure_ascii = False)
if (exception.LEDA_SUCCESS != code):
retDict = {
"code": exception.LEDA_ERROR_FAILED,
"message": "get(cloud_id:%s) exec failed" % (self.cloud_id),
"params": {}
}
_logger.debug("get(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, ensure_ascii = False)
retDict = {
"code": code,
"message": codeInfoDict[code],
"params": retInfo
}
_logger.debug("get(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, cls=json_coder.Json_Encoder, ensure_ascii = False)
elif (methodName == "set"):
code, retInfo = self.callback_funs.setProperties(inArgs)
if (False == isinstance(retInfo, dict) or (False == isinstance(code, int))):
_logger.warning("set(cloud_id:%s) return args type is invalid: %s", self.cloud_id,
type(retInfo))
retDict = {
"code": exception.LEDA_ERROR_INVAILD_PARAM, # params invalid
"message": "set(cloud_id:%s) return args type is invalid: %s" % (
self.cloud_id, type(retInfo)),
"params": {}
}
_logger.debug("set(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, ensure_ascii = False)
if (exception.LEDA_SUCCESS != code):
retDict = {
"code": exception.LEDA_ERROR_FAILED,
"message": "set(cloud_id:%s) exec failed" % (self.cloud_id),
"params": {}
}
_logger.debug("set(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, ensure_ascii = False)
retDict = {
"code": code,
"message": codeInfoDict[code],
"params": {}
}
_logger.debug("set(cloud_id:%s): retMsg: %s", self.cloud_id, retDict)
return json.dumps(retDict, ensure_ascii = False)
else:
code, output = self.callback_funs.callService(methodName, inArgs)
if ((False == isinstance(code, int)) or (False == isinstance(output, dict))):
_logger.warning("callService(cloud_id:%s) return args type is invalid", self.cloud_id)
retDict = {
"code": exception.LEDA_ERROR_INVAILD_PARAM, # params invalid
"message": "callService(cloud_id:%s) return args type is invalid" % (self.cloud_id),
"params": {
"code": exception.LEDA_ERROR_INVAILD_PARAM,
"message": "callService(cloud_id:%s) return args type is invalid" % (self.cloud_id),
"data": {}
}
}
_logger.debug("callServices(cloud_id:%s): %s retMsg: %s", self.cloud_id, methodName, retDict)
return json.dumps(retDict, ensure_ascii = False)
if (exception.LEDA_SUCCESS != code):
retDict = {
"code": exception.LEDA_ERROR_FAILED,
"message": "callService(cloud_id:%s) exec failed" % (self.cloud_id),
"params": {
"code": exception.LEDA_ERROR_FAILED,
"message": "callService(cloud_id:%s) exec failed" % (self.cloud_id),
"data": {}
}
}
_logger.debug("callServices(cloud_id:%s): %s retMsg: %s", self.cloud_id, methodName,
retDict)
return json.dumps(retDict, ensure_ascii = False)
data = output
except(AttributeError, ValueError, TypeError, KeyError) as err:
_logger.exception('Err')
_logger.warning('%s', err)
retDict = {
"code": exception.LEDA_ERROR_INVAILD_PARAM, # params invalid
"message": "%s" % (err),
"params": {}
}
_logger.debug("callServices(cloud_id:%s): %s retMsg: %s", self.cloud_id, methodName, retDict)
return json.dumps(retDict, ensure_ascii = False)
except:
_logger.exception("Err")
retDict = {
"code": exception.LEDA_ERROR_FAILED, # params invalid
"message": "unkonwn error",
"params": {}
}
_logger.warning("callServices(cloud_id:%s): %s retMsg: %s", self.cloud_id, methodName, retDict)
return json.dumps(retDict, ensure_ascii = False)
retDict = {
"code": exception.LEDA_SUCCESS,
"message": "successfully",
"params": {
"code": code,
"message": codeInfoDict[code],
"data": data
}
}
_logger.debug("callServices(cloud_id:%s): %s retMsg: %s", self.cloud_id, methodName, retDict)
return json.dumps(retDict, ensure_ascii = False)
return callServices