Changeset 3899
- Timestamp:
- 05/24/07 12:09:38 (6 years ago)
- Location:
- WaveDev/trunk/WaveDev/wavedev/generate/templates/py_comp
- Files:
-
- 2 modified
-
_sampleComp.py (modified) (1 diff)
-
genStructure.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
WaveDev/trunk/WaveDev/wavedev/generate/templates/py_comp/_sampleComp.py
r3898 r3899 67 67 __DATA_IN_CLASS_DEFS__ 68 68 69 __DATA_OUT_CLASS_DEFS__ 69 70 70 #------------------------------------------------------------------71 # dataOut_complexShort_i class definition72 #------------------------------------------------------------------73 class dataOut_complexShort_i(CF__POA.Port):74 def __init__(self, parent, name):75 self.parent = parent76 self.outPorts = {}77 self.name = name78 79 self.data_buffer = []80 self.data_event = threading.Event()81 self.data_buffer_lock = threading.Lock()82 83 self.is_running = True84 self.process_thread = threading.Thread(target = self.Process)85 self.process_thread.start()86 87 def connectPort(self, connection, connectionId):88 port = connection._narrow(standardInterfaces__POA.complexShort)89 self.outPorts[str(connectionId)] = port90 self.parent.outPort0_active = True91 92 def disconnectPort(self, connectionId):93 self.outPorts.pop(str(connectionId))94 if len(self.outPorts)==0:95 self.parent.outPort0_active = False96 97 def releasePort(self):98 # shut down the Process thread99 self.is_running = False100 self.data_event.set()101 102 def send_data(self, I, Q):103 self.data_buffer_lock.acquire()104 self.data_buffer.insert(0, (I,Q))105 self.data_buffer_lock.release()106 self.data_event.set()107 108 def Process(self):109 while self.is_running:110 self.data_event.wait()111 while len(self.data_buffer) > 0:112 self.data_buffer_lock.acquire()113 new_data = self.data_buffer.pop()114 self.data_buffer_lock.release()115 116 for port in self.outPorts.values():117 port.pushPacket(new_data[0], new_data[1])118 119 if (self.parent.outPort1_active):120 self.parent.outPort1_servant.send_timing_message(self.parent.naming_service_name, self.name, "pushPacket", "end", len(new_data[0]))121 122 else:123 self.data_event.clear()124 71 125 72 #------------------------------------------------------------------ -
WaveDev/trunk/WaveDev/wavedev/generate/templates/py_comp/genStructure.py
r3898 r3899 131 131 self.writeDataInClassDefs(output,comp) 132 132 continue 133 if l_out.find("__DATA_OUT_CLASS_DEFS__") != -1: 134 self.writeDataOutClassDefs(output,comp) 135 continue 133 136 output.write(l_out) #if none of the continue statements have been executed 134 137 … … 186 189 for p in comp.ports: 187 190 if p.type == "Uses": 188 ts = " "*8 + 'self.outPort' + str(outCount) + '_servant = dataOut_' + p.interface + '_i(self, "' + p.name + '")\n'191 ts = " "*8 + 'self.outPort' + str(outCount) + '_servant = dataOut_' + p.interface.name + '_i(self, "' + p.name + '")\n' 189 192 ts = ts + " "*8 + 'self.outPort' + str(outCount) + '_var = self.outPort' + str(outCount) + '_servant._this()\n' 190 193 ts = ts + " "*8 + 'self.outPort' + str(outCount) + '_active = False\n\n' … … 266 269 #------------------------------------------------------------------------------------ 267 270 def writeDataInClassDefs(self,output,comp): 271 '''Generates the code for the in port class definitions''' 272 268 273 def_types_written = " " #keeps track of the interface names that have been written already so that a certain interface (e.g., complexShort) does not get defined more than once 274 269 275 for p in comp.ports: 270 276 if p.type == "Provides" and def_types_written.find(p.interface.name) == -1: … … 284 290 285 291 def_types_written = def_types_written + p.interface.name 292 #------------------------------------------------------------------------------------ 293 294 295 #------------------------------------------------------------------------------------ 296 def writeDataOutClassDefs(self,output,comp): 297 '''generates the code for the out port class definitions''' 298 #TODO: test this method 299 def_types_written = " " #keeps track of the interface names that have been written already so that a certain interface (e.g., complexShort) does not get defined more than once 300 out_port_count = -1 301 302 for p in comp.ports: 303 out_port_count = out_port_count + 1 304 if p.type == "Uses" and def_types_written.find(p.interface.name) == -1: 305 ts = "#------------------------------------------------------------------\n" 306 ts = ts + "# dataOut_complexShort_i class definition\n" 307 ts = ts + "#------------------------------------------------------------------\n" 308 ts = ts + "class dataOut_" + p.interface.name + "_i(CF__POA.Port):\n" 309 output.write(ts) 310 311 #create the __init__ method 312 ts = " "*4 + "def __init__(self, parent, name):\n\ 313 self.parent = parent\n\ 314 self.outPorts = {}\n\ 315 self.name = name\n\ 316 \n\ 317 self.data_buffer = []\n\ 318 self.data_event = threading.Event()\n\ 319 self.data_buffer_lock = threading.Lock()\n\ 320 \n\ 321 self.is_running = True\n\ 322 self.process_thread = threading.Thread(target = self.Process)\n\ 323 self.process_thread.start()\n\n" 324 output.write(ts) 325 326 #create connectPort method 327 ts = " "*4 + "def connectPort(self, connection, connectionId):\n" 328 ts = ts + " "*8 + "port = connection._narrow(" + p.interface.nameSpace + "__POA." + p.interface.name + ")\n" 329 ts = ts + " "*8 + "self.outPorts[str(connectionId)] = port\n" 330 ts = ts + " "*8 + "self.parent.outPort" + str(out_port_count) + "_active = True\n\n" 331 output.write(ts) 332 333 #create disconnectPort method 334 ts = " "*4 + "def disconnectPort(self, connectionId):\n\ 335 self.outPorts.pop(str(connectionId))\n\ 336 if len(self.outPorts)==0:\n\ 337 self.parent.outPort0_active = False\n\n" 338 output.write(ts) 339 340 #create releasePort method 341 ts = " "*4 + "def releasePort(self):\n\ 342 # shut down the Process thread\n\ 343 self.is_running = False\n\ 344 self.data_event.set()\n\n" 345 output.write(ts) 346 347 #create send_data method 348 ts = " "*4 + "# WARNING: I and Q may have to be changed depending on what data you are receiving (e.g., bytesIn for realChar)\n\ 349 def send_data(self, I, Q):\n\ 350 self.data_buffer_lock.acquire()\n\ 351 self.data_buffer.insert(0, (I,Q))\n\ 352 self.data_buffer_lock.release()\n\ 353 self.data_event.set()\n\n" 354 output.write(ts) 355 356 #create Process method 357 ts = " "*4 + "def Process(self):\n\ 358 while self.is_running:\n\ 359 self.data_event.wait()\n\ 360 while len(self.data_buffer) > 0:\n\ 361 self.data_buffer_lock.acquire()\n\ 362 new_data = self.data_buffer.pop()\n\ 363 self.data_buffer_lock.release()\n\ 364 \n\ 365 for port in self.outPorts.values():\n\ 366 port.pushPacket(new_data[0], new_data[1])\n\ 367 \n\ 368 self.data_event.clear()\n\n" 369 output.write(ts) 370 371 #TODO: add code for timing support 372 373 def_types_written = def_types_written + p.interface.name 286 374 #------------------------------------------------------------------------------------ 287 375