root/experimental/components/rc2007_gui/WorkModule.py @ 4857

Revision 4857, 3.1 KB (checked in by DrewCormier, 6 years ago)

changing variable names in voice buffer. adding a method for sending text data

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 USRP_Commander_GUI.
9
10OSSIE USRP_Commander_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 USRP_Commander_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 USRP_Commander_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
28#!/usr/bin/env python
29import threading
30
31class WorkClass:
32    """This class provides a place for the main processing of the
33    component to reside."""
34
35    def __init__(self, rc2007_gui_ref):
36        '''Initialization.  Sets a reference to parent. 
37        Initializes the buffer.  Starts the Process data
38        thread, which waits for data to be added to the buffer'''
39
40        self.rc2007_gui_ref = rc2007_gui_ref
41       
42        self.voice_data_queue = []
43        self.voice_data_queue_lock = threading.Lock()
44        self.voice_data_signal = threading.Event()
45
46        self.is_running = True
47
48        self.process_thread = threading.Thread(target=self.Process)
49        self.process_thread.start()
50       
51    def __del__(self):
52        '''Destructor'''
53        pass
54       
55    def AddVoiceData(self, data):
56        '''Generally called by parent.  Adds data to a buffer.
57        The Process() method will wait for this buffer to be set.
58        '''
59        self.voice_data_queue_lock.acquire()
60        self.voice_data_queue.insert(0, data)
61        self.voice_data_queue_lock.release()
62        self.voice_data_signal.set()
63   
64    def SendTextData(self,data)
65        # TODO: pack/depack
66        # add meta data
67        self.rc2007_gui_ref_outPort0_servant.send_data(data)
68       
69    def Release(self):
70        self.is_running = False
71        self.data_signal.set()
72               
73    def Process(self):
74        while self.is_running:
75            self.data_signal.wait()  # wait for data to be aded to the
76                                     # buffer in self.AddVoiceData()
77            while len(self.data_queue) > 0:
78                # get the data from the buffer:
79                self.data_queue_lock.acquire()
80                new_data = self.data_queue.pop()
81                self.data_queue_lock.release()
82                               
83                # forwarding voice data:
84                if self.rc2007_gui_ref.talk_flag:
85                    if self.rc2007_gui_ref.outPort0_active:
86                        # TODO: send voice metadata
87                        self.rc2007_gui_ref.outPort0_servant.send_data(data)   
88
89            self.data_signal.clear()  # done reading the buffer
90                               
91
Note: See TracBrowser for help on using the browser.