root/experimental/components/rc2007_gui/rc2007_gui.py @ 4809

Revision 4809, 8.9 KB (checked in by DrewCormier, 7 years ago)

wrong class name

  • Property svn:executable set to *
Line 
1#! /usr/bin/env python
2
3'''
4/****************************************************************************
5
6Copyright 2007 Virginia Polytechnic Institute and State University
7
8This file is part of the OSSIE rc2007_gui.
9
10OSSIE rc2007_gui is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15OSSIE rc2007_gui is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with OSSIE rc2007_gui; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24****************************************************************************/
25
26'''
27
28from omniORB import CORBA
29from omniORB import URI
30import CosNaming
31import CF, CF__POA
32import standardInterfaces__POA
33import customInterfaces__POA
34import sys
35
36import threading
37import time        # primarily availble for time.sleep() statements
38
39import wx          # gui stuff
40import wx_inits    # my frame init code: specific to this application
41import WorkModule
42
43#-------------------------------------------------------------
44# rc2007_gui_i class definition (main component class)
45#-------------------------------------------------------------
46class rc2007_gui_i(CF__POA.Resource):
47    def __init__(self, prnt_orb, uuid, label, poa):
48        CF._objref_Resource.__init__(self._this())
49        print "rc2007_gui_i __init__: " + label
50        self.naming_service_name = label
51        self.poa = poa
52
53        self.prnt_orb = prnt_orb
54
55        self.inPort0_servant = dataIn_complexShort_i(self, "gui_sound_in")
56        self.inPort0_var = self.inPort0_servant._this()
57
58        self.outPort0_servant = dataOut_complexShort_i(self, "gui_sound_out")
59        self.outPort0_var = self.outPort0_servant._this()
60        self.outPort0_active = False
61
62        self.WorkModule_created = False
63        self.talk_flag = False
64
65        self.propertySet = []
66        self.work_mod = None
67       
68    def start(self):
69        print "rc2007_gui start called"
70       
71    def stop(self):
72        print "rc2007_gui stop called"
73       
74    def getPort(self, id):
75        if str(id) == "gui_sound_in":
76            return self.inPort0_var
77        if str(id) == "gui_sound_out":
78            return self.outPort0_var
79       
80        return None  #port not found in available ports list
81       
82    def initialize(self):
83        print "rc2007_gui initialize called"
84   
85    def configure(self, props):
86        ''' The configure method is called twice by the framework:
87        once to read the default properties in the component.prf
88        file, and once to read the component instance properties
89        storred in the waveform.sad file.  This method should be
90        called before the start method.  This method is where
91        the properties are read in by the component. 
92        '''
93
94        print "rc2007_gui configure called"
95       
96        # make sure that only one WorkModule thread is started,
97        # even if configure method is called more than once   
98        if not self.WorkModule_created:
99            self.work_mod = WorkModule.WorkClass(self, buffer_size)
100            self.WorkModule_created = True   
101
102
103    def query(self, props):
104        return self.propertySet
105   
106    def releaseObject(self):
107        # release the main work module
108        self.work_mod.Release()
109       
110        # release the main process threads for the ports
111        self.outPort0_servant.releasePort()
112               
113        # deactivate the ports
114        iid0 = self.poa.reference_to_id(self.inPort0_var)
115        oid0 = self.poa.reference_to_id(self.outPort0_var)
116
117        self.poa.deactivate_object(iid0)
118        self.poa.deactivate_object(oid0)
119
120
121#------------------------------------------------------------------
122# dataIn_complexShort_i class definition
123#------------------------------------------------------------------
124class dataIn_complexShort_i(standardInterfaces__POA.complexShort):
125    def __init__(self, parent, name):
126        self.parent = parent
127        self.name = name
128
129    def pushPacket(self, I, Q):
130        self.parent.work_mod.AddData(I, Q)
131
132
133#------------------------------------------------------------------
134# dataOut_complexShort_i class definition
135#------------------------------------------------------------------
136class dataOut_complexShort_i(CF__POA.Port):
137    def __init__(self, parent, name):
138        self.parent = parent
139        self.outPorts = {}
140        self.name = name
141       
142        self.data_buffer = []
143        self.data_event = threading.Event()
144        self.data_buffer_lock = threading.Lock()
145       
146        self.is_running = True
147        self.process_thread = threading.Thread(target = self.Process)
148        self.process_thread.start()
149
150    def connectPort(self, connection, connectionId):
151        port = connection._narrow(standardInterfaces__POA.complexShort)
152        self.outPorts[str(connectionId)] = port
153        self.parent.outPort0_active = True
154
155    def disconnectPort(self, connectionId):
156        self.outPorts.pop(str(connectionId))
157        if len(self.outPorts)==0:
158            self.parent.outPort0_active = False
159
160    def releasePort(self):
161        # shut down the Process thread
162        self.is_running = False
163        self.data_event.set()
164
165    def send_data(self, I, Q):
166        self.data_buffer_lock.acquire()
167        self.data_buffer.insert(0, (I,Q))
168        self.data_buffer_lock.release()
169        self.data_event.set()
170
171    def Process(self):
172        while self.is_running:
173            self.data_event.wait()
174            if self.talk_flag:
175                self.data_buffer_lock.acquire()
176                new_data = self.data_buffer.pop()
177                self.data_buffer_lock.release()
178               
179                for port in self.outPorts.values():
180                    port.pushPacket(new_data[0], new_data[1])
181           
182            # if the push to talk button is not depressed, don't do anything
183            # with the data, even if it is there
184            # alternatively, if the button is down, i just sent the packet
185            self.data_event.clear()
186
187            # TODO: make sure the buffer is empty
188
189
190#-------------------------------------------------------------------
191# ORB_Init class definition
192#-------------------------------------------------------------------
193class ORB_Init:
194    """Takes care of initializing the ORB and bind the object"""
195   
196    def __init__(self, uuid, label):
197        # initialize the orb
198        self.orb = CORBA.ORB_init()
199       
200       
201
202def ORB_start_fun():
203        orb_ref = orb
204
205        # get the POA
206        obj_poa = orb_ref.orb.resolve_initial_references("RootPOA")
207        poaManager = obj_poa._get_the_POAManager()
208        poaManager.activate()
209       
210        ns_obj = orb_ref.orb.resolve_initial_references("NameService")
211        rootContext = ns_obj._narrow(CosNaming.NamingContext)
212       
213        # create the main component object
214        orb_ref.USRP_Commander_GUI_Obj = USRP_Commander_GUI_i(orb_ref,
215                                                              uuid,
216                                                              label,
217                                                              obj_poa)
218        USRP_Commander_GUI_var = orb_ref.USRP_Commander_GUI_Obj._this()
219       
220        name = URI.stringToName(label)
221        rootContext.rebind(name, USRP_Commander_GUI_var)
222
223
224        orb_ref.orb.run()
225
226
227#-------------------------------------------------------------------
228# wx.App for the GUI
229#-------------------------------------------------------------------
230class App(wx.App):
231    def OnInit(self):
232        self.frame = wx_inits.MainFrame()
233        self.frame.Show()
234        self.SetTopWindow(self.frame)
235
236        return True
237
238
239class my_threads:
240    def __init__(self):
241
242        # start the orb that has already been initialized in a thread
243        self.orb_thread = threading.Thread(target=ORB_start_fun)
244        self.orb_thread.start()
245
246        self.app_thread = threading.Thread(target=app.MainLoop)
247        self.app_thread.start()
248
249       
250#-------------------------------------------------------------------
251# Code run when this file is executed
252#-------------------------------------------------------------------
253if __name__ == "__main__":
254    if len(sys.argv) != 3:
255        print sys.argv[0] + " <id> <usage name> "
256   
257    uuid = str(sys.argv[1])
258    label = str(sys.argv[2])
259   
260    print "Identifier - " + uuid + "  Label - " + label
261   
262    # initialize the orb, but do not start it
263    orb = ORB_Init(uuid, label)
264   
265    # initialize the wx stuff
266    app = App()
267
268    # now that orb and app exist, I can start them
269    # note that they must be created first so that they can reference
270    # each other when they start
271    threads_running = my_threads()
272
Note: See TracBrowser for help on using the browser.