def put(self, cmdIndex, value=None): if self.simpleLog: logger.log(MINOR_INFO, "Queue : put %s in %s" % (get_command_name(cmdIndex), getTraceCallStack())) else: logger.log(MINOR_INFO, "Queue : put %s, %s in %s" % (get_command_name(cmdIndex), str(value), getTraceCallStack())) # must send queue date to tuple type self.queue.put((cmdIndex, value))
def send(self, sendCmd, sendValue=None): if self.simpleLog: logger.log(MINOR_INFO, "Pipe : Send %s in %s" % (get_command_name(sendCmd), getTraceCallStack())) else: logger.log(MINOR_INFO, "Pipe : Send %s, %s in %s" % (get_command_name(sendCmd), str(sendValue), getTraceCallStack())) # must send queue date to tuple type self.pipe.send((sendCmd, sendValue))
def get(self): # receive value must be tuple type cmdAndValue = self.queue.get(self) if self.simpleLog: logger.log(MINOR_INFO, "Queue : get %s in %s" % (get_command_name(cmdAndValue[0]), getTraceCallStack())) else: logger.log(MINOR_INFO, "Queue : get %s, %s in %s" % ( get_command_name(cmdAndValue[0]), str(cmdAndValue[1]), getTraceCallStack())) return cmdAndValue
def recv(self): """must be a tuple type""" cmdAndValue = self.pipe.recv() if self.simpleLog: logger.log(MINOR_INFO, "Pipe : Recv %s in %s" % (get_command_name(cmdAndValue[0]), getTraceCallStack())) else: logger.log(MINOR_INFO, "Pipe : Recv %s, %s in %s" % ( get_command_name(cmdAndValue[0]), str(cmdAndValue[1]), getTraceCallStack())) return cmdAndValue
def compile(self, shaderType, shader_code): """ :param shaderType: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER :param shader_code: string """ if shader_code == "" or shader_code is None: return None try: # Compile shaders shader = glCreateShader(shaderType) glShaderSource(shader, shader_code) glCompileShader(shader) compile_status = glGetShaderiv(shader, GL_COMPILE_STATUS) if compile_status != 1: infoLogs = glGetShaderInfoLog(shader) if infoLogs: if type(infoLogs) == bytes: infoLogs = infoLogs.decode("utf-8") infoLogs = ("GL_COMPILE_STATUS : %d\n" % compile_status) + infoLogs shader_code_lines = shader_code.split('\n') infoLogs = infoLogs.split('\n') for i, infoLog in enumerate(infoLogs): error_line = re.match('\d\((\d+)\) : error', infoLog) if error_line is not None: # show prev 3 lines error_line = int(error_line.groups()[0]) - 1 for num in range(max(0, error_line - 3), error_line): infoLogs[i] += "\n\t %s" % ( shader_code_lines[num]) # show last line infoLogs[i] += "\n\t--> %s" % ( shader_code_lines[error_line]) infoLogs = "\n".join(infoLogs) self.compile_message = "\n".join( [self.compile_message, infoLogs]) logger.error("%s %s shader compile error.\n%s" % (self.name, shaderType.name, infoLogs)) else: # complete logger.log( Logger.MINOR_INFO, "Complete %s %s compile." % (self.name, shaderType.name)) return shader except BaseException: logger.error(traceback.format_exc()) return None
def SendAndRecv(self, sendCmd, sendValue, checkRecvCmd, checkReceiveValue): # send message - must be a tuple type self.pipe.send((sendCmd, sendValue)) # wait recv message - must be a tuple type recv, value = self.pipe.recv() if self.simpleLog: logger.log( MINOR_INFO, "Pipe : Send %s and Recv %s in %s" % (get_command_name(sendCmd), get_command_name(recv), getTraceCallStack())) else: logger.log( MINOR_INFO, "Pipe : Send %s, %s and Recv %s, %s in %s" % (get_command_name(sendCmd), str(sendValue), get_command_name(recv), str(value), getTraceCallStack())) # check receive correct command and value if recv != checkRecvCmd or (checkReceiveValue is not None and checkReceiveValue != value): if self.simpleLog: logger.log( MINOR_INFO, "Pipe : RecvFailed %s and Send %s in %s" % (get_command_name(recv), COMMAND.FAIL, getTraceCallStack())) else: logger.log( MINOR_INFO, "Pipe : RecvFailed %s, %s and Send %s, %s in %s" % (get_command_name(recv), str(value), COMMAND.FAIL, "None", getTraceCallStack())) logger.error("ERROR : Received %s not %s" % (recv, checkRecvCmd)) raise BaseException("Pipe receive error.") return value
def RecvAndSend(self, checkRecvCmd, checkReceiveValue, sendCmd, sendValue): # wait recv message - must be a tuple type recv, value = self.pipe.recv() if recv == checkRecvCmd and (checkReceiveValue is None or checkReceiveValue == value): # receive succesfull - send message, must be a tuple type self.pipe.send((sendCmd, sendValue)) if self.simpleLog: logger.log(MINOR_INFO, "Pipe : Recv %s and Send %s in %s" % ( get_command_name(recv), get_command_name(sendCmd), getTraceCallStack())) else: logger.log(MINOR_INFO, "Pipe : Recv %s, %s and Send %s, %s in %s" % ( get_command_name(recv), str(value), get_command_name(sendCmd), str(sendValue), getTraceCallStack())) # return received value return value else: self.pipe.send((COMMAND.FAIL, None)) if self.simpleLog: logger.log(MINOR_INFO, "Pipe : RecvFailed %s and Send %s in %s" % ( get_command_name(recv), COMMAND.FAIL, getTraceCallStack())) else: logger.log(MINOR_INFO, "Pipe : RecvFailed %s, %s and Send %s, %s in %s" % ( get_command_name(recv), str(value), COMMAND.FAIL, "None", getTraceCallStack())) logger.error("ERROR : Received %s not %s" % (recv, checkRecvCmd)) raise BaseException("Pipe receive error.")