def _check_parameters(self, parameter_list, type_list): """ Checks that every parameter in the parameter list corresponds to the type in type_list. Then returns an array with the string conversion of each value. Parameters ---------- parameter_list: list The parameters to check and convert type_list: list List of types for each parameter Returns ------- parameter_string_list : list List of string conversions of each parameter """ parameter_string_list = [] for i, parameter in enumerate(parameter_list): if not isinstance(parameter, type_list[i]): raise GstcError( "%s TypeError: parameter %i: expected %s, '%s found" % (inspect.stack()[1].function, i, type_list[i], type(parameter)), GstcErrorCode.GSTC_MALFORMED) if type_list[i] == str: parameter_string_list += [parameter] elif type_list[i] == bool: if parameter: parameter_string_list += ['true'] else: parameter_string_list += ['false'] else: parameter_string_list += [str(parameter)] return parameter_string_list
def _send_cmd_line(self, cmd_line): """ Send a command using an abstract IPC and wait for the response. Parameters ---------- cmd_line : string list Command to be send Raises ------ GstdError Error is triggered when Gstd IPC fails GstcError Error is triggered when the Gstd python client fails internally Returns ------- result : dictionary Response from the IPC """ try: cmd = cmd_line[0] jresult = self._ipc.send(cmd_line, timeout=self._timeout) result = json.loads(jresult) if result['code'] != GstcErrorCode.GSTC_OK.value: self._logger.error('%s error: %s' % (cmd, result['description'])) raise GstdError(result['description'], result['code']) return result except ConnectionRefusedError as e: raise GstcError("Failed to communicate with Gstd", GstcErrorCode.GSTC_UNREACHABLE)\ from e except TypeError as e: raise GstcError('GstClient bad command', GstcErrorCode.GSTC_TYPE_ERROR) from e except BufferError as e: raise GstcError('GstClient received a response bigger ' + 'than the maximum size allowed', GstcErrorCode.GSTC_RECV_ERROR) from e except TimeoutError as e: raise GstcError('GstClient time out ocurred', GstcErrorCode.GSTC_BUS_TIMEOUT) from e
def ping_gstd(self): """ Test if Gstd responds in the configured address and port Raises ------ GstcError Error is triggered when GstClient fails GstdError Error is triggered when Gstd IPC fails """ self._logger.info('Sending ping to Gstd') try: jresult = self._ipc.send(['list_pipelines'], timeout=1) # Verify correct data format result = json.loads(jresult) if ('description' in result and result['description'] != 'Success'): raise GstdError(result['description'], result['code']) except json.JSONDecodeError as e: err_msg = 'Gstd corrupted response' self._logger.error(err_msg) raise GstcError(err_msg, GstcErrorCode.GSTC_MALFORMED) from e except ConnectionRefusedError as e: err_msg = 'Error contacting Gstd' self._logger.error(err_msg) raise GstcError(err_msg, GstcErrorCode.GSTC_UNREACHABLE) from e except BufferError as e: raise GstcError('GstClient received a buffer bigger ' + 'than the maximum size allowed', GstcErrorCode.GSTC_RECV_ERROR) from e except TimeoutError as e: raise GstcError('GstClient time out ocurred', GstcErrorCode.GSTC_TIMEOUT) from e