root/experimental/components/rc2007_gui/port_impl.py @ 4884

Revision 4884, 3.4 KB (checked in by DrewCormier, 6 years ago)

additional support of metadata in workmodule

Line 
1'''
2/****************************************************************************
3
4Copyright 2007 Virginia Polytechnic Institute and State University
5
6This file is part of the OSSIE USRP_Commander_GUI.
7
8OSSIE USRP_Commander_GUI is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13OSSIE USRP_Commander_GUI is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with OSSIE USRP_Commander_GUI; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22****************************************************************************/
23
24'''
25
26
27import standardInterfaces__POA
28import customInterfaces__POA
29import CF__POA
30import threading
31
32
33#------------------------------------------------------------------
34# dataIn_realChar_metadata_i class definition
35#------------------------------------------------------------------
36# from radio
37class dataIn_realChar_metadata_i(standardInterfaces__POA.realChar):
38    def __init__(self, parent, name):
39        self.parent = parent
40        self.name = name
41
42    def pushPacket(self, data, metadata):
43        self.parent.rx_work_mod.AddMetaData(data, metadata)
44
45
46
47#------------------------------------------------------------------
48# dataOut_realChar_metadata_i class definition
49#------------------------------------------------------------------
50# to radio
51class dataOut_realChar_metadata_i(CF__POA.Port):
52    def __init__(self, parent, name):
53        self.parent = parent
54        self.outPorts = {}
55        self.name = name
56       
57        self.data_buffer = []
58        self.data_event = threading.Event()
59        self.data_buffer_lock = threading.Lock()
60       
61        self.is_running = True
62        self.process_thread = threading.Thread(target = self.Process)
63        self.process_thread.start()
64
65    def connectPort(self, connection, connectionId):
66        port = connection._narrow(standardInterfaces__POA.realChar)
67        self.outPorts[str(connectionId)] = port
68        self.parent.to_radio_port_active = True
69
70    def disconnectPort(self, connectionId):
71        self.outPorts.pop(str(connectionId))
72        if len(self.outPorts)==0:
73            self.parent.to_radio_port_active = False
74
75    def releasePort(self):
76        # shut down the Process thread
77        self.is_running = False
78        self.data_event.set()
79
80    def send_data(self, data, metadata):
81        self.data_buffer_lock.acquire()
82        self.data_buffer.insert(0, data, metadata)
83        self.data_buffer_lock.release()
84        self.data_event.set()
85
86    def Process(self):
87        while self.is_running:
88
89            self.data_event.wait()
90
91            while len(self.data_buffer) > 0:
92                self.data_buffer_lock.acquire()
93                # get data and metadata from the stack
94                (data, metadata) = self.data_buffer.pop()
95                self.data_buffer_lock.release()
96               
97                # send the data to all outPort connections
98                for port in self.outPorts.values():
99                    port.pushPacket(data, metadata)
100           
101                self.data_event.clear()
102
103
Note: See TracBrowser for help on using the browser.