コード例 #1
0
ファイル: Smeshalist.py プロジェクト: CharlieBr/Smeshalist
def getInstance(portNumber, hardReset):
    """Return instance of Smeshalist class. Tool is using port of given number to connect to main window. hardReset flag indicates if data should be reset in Core"""
    global port
    port = portNumber
    dataPackage = structs_pb2.DataPackage()
    dataPackages.append(dataPackage)

    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send
        sock.settimeout(2)
        message = structs_pb2.MessageInfo()
        if hardReset == True:
            message.type = structs_pb2.MessageInfo.HARD_RESET
        else:
            message.type = structs_pb2.MessageInfo.NO_RESET
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

        # Receive acknowledge
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        if reply.type != structs_pb2.MessageInfo.ACK:
            sock.close()
            exit()
    except socket.timeout as e:
        raise CoreNotRunningException(e)
    finally:
        sock.close()
コード例 #2
0
def flushBuffer():
  

    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send 
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.DATA
        bytesToSend =  message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))	


        # Receive acknowledge
        print 'waiting to receive'
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        while reply.type == structs_pb2.MessageInfo.ACK and len(dataPackages) > 0:

            dataPackage = dataPackages.pop(0)            
            dataToSend = dataPackage.SerializeToString()
            header = structs_pb2.Header()
            header.sizeOfData = sys.getsizeof(dataToSend)

            if len(dataPackages) == 0:
                header.endOfData = True
            else: 
                header.endOfData = False

            toSendHeader = header.SerializeToString()
            sent = sock.sendto(toSendHeader, (IPAdress, port))
            sent = sock.sendto(dataToSend, (IPAdress, port))
            
            # Receive acknowledge
            print 'waiting to receive2'
            data, addr = sock.recvfrom(10)
            reply.ParseFromString(data)                        

    finally:
        print 'closing socket'
        global structuresRemaining 
        structuresRemaining = numberOfStructuresToSend
        dataPackage = structs_pb2.DataPackage()
        dataPackages.append(dataPackage)
        sock.close()
コード例 #3
0
ファイル: Smeshalist.py プロジェクト: CharlieBr/Smeshalist
def flushBuffer():
    """Send all structures stored in buffer to main window"""
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.settimeout(2)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.DATA
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

        # Receive acknowledge
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        while reply.type == structs_pb2.MessageInfo.ACK and len(
                dataPackages) > 0:

            dataPackage = dataPackages.pop(0)
            dataToSend = dataPackage.SerializeToString()
            header = structs_pb2.Header()
            header.sizeOfData = sys.getsizeof(dataToSend)

            if len(dataPackages) == 0:
                header.endOfData = True
            else:
                header.endOfData = False

            toSendHeader = header.SerializeToString()
            sent = sock.sendto(toSendHeader, (IPAdress, port))
            sent = sock.sendto(dataToSend, (IPAdress, port))

            # Receive acknowledge
            data, addr = sock.recvfrom(10)
            reply.ParseFromString(data)

    except socket.timeout as e:
        raise CoreNotRunningException(e)
    finally:
        global structuresRemaining
        structuresRemaining = numberOfStructuresToSend
        dataPackage = structs_pb2.DataPackage()
        dataPackages.append(dataPackage)
        sock.close()
コード例 #4
0
def render():
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.RENDER
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

    finally:
        print 'closing socket'
        sock.close()
コード例 #5
0
def clean():
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.CLEAN
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

        # Receive acknowledge
        print 'waiting to receive'
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        if reply.type != structs_pb2.MessageInfo.ACK:
            sock.close()
            exit()

    finally:
        print 'closing socket'
        sock.close()
コード例 #6
0
ファイル: Smeshalist.py プロジェクト: CharlieBr/Smeshalist
def breakpoint():
    """Interrupts algorithm execution until proper option will be chosen in Smeshalist Manager window.
    In case continue option has been chosen algorithm is continued otherwise program is terminated."""
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.BREAKPOINT
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

        # Receive acknowledge
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        if reply.type == structs_pb2.MessageInfo.REJECTED:
            sock.close()
            exit()

    finally:
        sock.close()
コード例 #7
0
ファイル: Smeshalist.py プロジェクト: CharlieBr/Smeshalist
def clean():
    """Method forces deleting all data from data structure tree in main window without affecting taken snapshots."""
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.settimeout(2)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.CLEAN
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

        # Receive acknowledge
        data, addr = sock.recvfrom(10)
        reply = structs_pb2.MessageInfo()
        reply.ParseFromString(data)

        if reply.type != structs_pb2.MessageInfo.ACK:
            sock.close()
            exit()

    except socket.timeout as e:
        raise CoreNotRunningException(e)
    finally:
        sock.close()
コード例 #8
0
ファイル: Smeshalist.py プロジェクト: CharlieBr/Smeshalist
def render():
    """Method forces rendering sent structures in main window in case Dynamic rendering is turned off in Smeshalist Manager window."""
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.settimeout(2)
        # Send
        message = structs_pb2.MessageInfo()
        message.type = structs_pb2.MessageInfo.RENDER
        bytesToSend = message.SerializeToString()
        sent = sock.sendto(bytesToSend, (IPAdress, port))

    except socket.timeout as e:
        raise CoreNotRunningException(e)
    finally:
        sock.close()