#! /usr/bin/env python ''' /**************************************************************************** Copyright 2007 Virginia Polytechnic Institute and State University This file is part of the OSSIE USRP_Commander_GUI. OSSIE USRP_Commander_GUI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OSSIE USRP_Commander_GUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OSSIE USRP_Commander_GUI; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ****************************************************************************/ ''' #!/usr/bin/env python import threading class WorkClass: """This class provides a place for the main processing of the component to reside.""" def __init__(self, rc2007_gui_ref): '''Initialization. Sets a reference to parent. Initializes the buffer. Starts the Process data thread, which waits for data to be added to the buffer''' self.rc2007_gui_ref = rc2007_gui_ref self.voice_data_queue = [] self.voice_data_queue_lock = threading.Lock() self.voice_data_signal = threading.Event() self.is_running = True self.process_thread = threading.Thread(target=self.Process) self.process_thread.start() def __del__(self): '''Destructor''' pass def AddVoiceData(self, data): '''Generally called by parent. Adds data to a buffer. The Process() method will wait for this buffer to be set. ''' self.voice_data_queue_lock.acquire() self.voice_data_queue.insert(0, data) self.voice_data_queue_lock.release() self.voice_data_signal.set() def SendTextData(self,data) # TODO: pack/depack # add meta data self.rc2007_gui_ref_outPort0_servant.send_data(data) def Release(self): self.is_running = False self.data_signal.set() def Process(self): while self.is_running: self.data_signal.wait() # wait for data to be aded to the # buffer in self.AddVoiceData() while len(self.data_queue) > 0: # get the data from the buffer: self.data_queue_lock.acquire() new_data = self.data_queue.pop() self.data_queue_lock.release() # forwarding voice data: if self.rc2007_gui_ref.talk_flag: if self.rc2007_gui_ref.outPort0_active: # TODO: send voice metadata self.rc2007_gui_ref.outPort0_servant.send_data(data) self.data_signal.clear() # done reading the buffer