| 103 | | #------------------------------------------------------------------ |
| 104 | | # dataOut_complexShort_i class definition |
| 105 | | #------------------------------------------------------------------ |
| 106 | | class dataOut_complexShort_i(CF__POA.Port): |
| 107 | | def __init__(self, parent, name): |
| 108 | | self.parent = parent |
| 109 | | self.outPorts = {} |
| 110 | | self.name = name |
| 111 | | |
| 112 | | self.data_buffer = [] |
| 113 | | self.data_event = threading.Event() |
| 114 | | self.data_buffer_lock = threading.Lock() |
| 115 | | |
| 116 | | self.is_running = True |
| 117 | | self.process_thread = threading.Thread(target = self.Process) |
| 118 | | self.process_thread.start() |
| 119 | | |
| 120 | | def connectPort(self, connection, connectionId): |
| 121 | | port = connection._narrow(standardInterfaces__POA.complexShort) |
| 122 | | self.outPorts[str(connectionId)] = port |
| 123 | | self.parent.outPort0_active = True |
| 124 | | |
| 125 | | def disconnectPort(self, connectionId): |
| 126 | | self.outPorts.pop(str(connectionId)) |
| 127 | | if len(self.outPorts)==0: |
| 128 | | self.parent.outPort0_active = False |
| 129 | | |
| 130 | | def releasePort(self): |
| 131 | | # shut down the Process thread |
| 132 | | self.is_running = False |
| 133 | | self.data_event.set() |
| 134 | | |
| 135 | | def send_data(self, I, Q): |
| 136 | | self.data_buffer_lock.acquire() |
| 137 | | self.data_buffer.insert(0, (I,Q)) |
| 138 | | self.data_buffer_lock.release() |
| 139 | | self.data_event.set() |
| 140 | | |
| 141 | | def Process(self): |
| 142 | | while self.is_running: |
| 143 | | self.data_event.wait() |
| 144 | | while len(self.data_buffer) > 0: |
| 145 | | self.data_buffer_lock.acquire() |
| 146 | | new_data = self.data_buffer.pop() |
| 147 | | self.data_buffer_lock.release() |
| 148 | | |
| 149 | | for port in self.outPorts.values(): |
| 150 | | port.pushPacket(new_data[0], new_data[1]) |
| 151 | | |
| 152 | | if (self.parent.outPort1_active): |
| 153 | | self.parent.outPort1_servant.send_timing_message(self.parent.naming_service_name, self.name, "pushPacket", "end", len(new_data[0])) |
| 154 | | |
| 155 | | else: |
| 156 | | self.data_event.clear() |