Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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)
            if glGetShaderiv(shader, GL_COMPILE_STATUS) != 1 or True:
                infoLogs = glGetShaderInfoLog(shader)
                if infoLogs:
                    shader_code_lines = shader_code.split('\n')
                    if type(infoLogs) == bytes:
                        infoLogs = infoLogs.decode("utf-8")

                    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)
                    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:
            logger.error(traceback.format_exc())
        return None
Exemplo n.º 7
0
    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.")