commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9162 - gnuradio/branches/features/experimental-gui


From: jcorgan
Subject: [Commit-gnuradio] r9162 - gnuradio/branches/features/experimental-gui
Date: Sun, 3 Aug 2008 11:44:19 -0600 (MDT)

Author: jcorgan
Date: 2008-08-03 11:44:19 -0600 (Sun, 03 Aug 2008)
New Revision: 9162

Added:
   gnuradio/branches/features/experimental-gui/msgq_publisher.py
Modified:
   gnuradio/branches/features/experimental-gui/const_top_block.py
   gnuradio/branches/features/experimental-gui/fft_top_block.py
   gnuradio/branches/features/experimental-gui/todo.txt
Log:
Refactored bg threads into msgq_publisher

Modified: gnuradio/branches/features/experimental-gui/const_top_block.py
===================================================================
--- gnuradio/branches/features/experimental-gui/const_top_block.py      
2008-08-03 17:16:07 UTC (rev 9161)
+++ gnuradio/branches/features/experimental-gui/const_top_block.py      
2008-08-03 17:44:19 UTC (rev 9162)
@@ -22,34 +22,10 @@
 
 from gnuradio import gr, blks2
 from pubsub import pubsub
+from msgq_publisher import msgq_publisher
 import const_streamer
 import simple_usrp
-import threading
 
-class _const_thread(threading.Thread):
-    """
-    This background thread simply reads constellation frames from the
-    message queue and sets the top block 'fft' property to their string
-    representation. External code can add one or more listeners to
-    this property to receive notification when an constellationframe
-    comes in.
-    """
-    def __init__(self, msgq, tb):
-       threading.Thread.__init__(self)
-        self._msgq = msgq
-        self._tb = tb
-        self._keep_running = True
-       self.setDaemon(1)
-
-    def run(self):
-       while self._keep_running:
-           msg = self._msgq.delete_head()
-           self._tb['const'] = msg.to_string()
-
-    def stop(self):
-        self._keep_running = False
-
-
 class const_top_block(gr.top_block, pubsub):
     """!
     GNU Radio top block to create a stream of constellation points at a 
@@ -137,7 +113,7 @@
         self.proxy('gain_omega', self._const)
         self.publish('queue', lambda : self._msgq)
 
-       self._thread = _const_thread(self._msgq, self)
+       self._thread = msgq_publisher(self._msgq, self, 'const')
         
     def _set_decim(self, decim):
         self._u['decim'] = decim
@@ -148,9 +124,6 @@
        This method gets called by the external GUI or other code to start the 
top block
        operation.
        """
-       # Start the queue runner background thread
-       self._thread.start()
-
        # Using gr.top_block.start() here keeps Python's SIGINT handler active,
        # and we agree to handle SIGINT in our code if needed.  We must also 
call
        # gr.top_block.stop() and .wait() to properly shut down GNU Radio
@@ -161,7 +134,7 @@
        This method gets called to shutdown the top block.  It stops the 
background
        thread, then calls stop() and wait() on the top block.
        """
-        self._thread.stop()
+        del self._thread
         self.stop()
        self.wait()
 

Modified: gnuradio/branches/features/experimental-gui/fft_top_block.py
===================================================================
--- gnuradio/branches/features/experimental-gui/fft_top_block.py        
2008-08-03 17:16:07 UTC (rev 9161)
+++ gnuradio/branches/features/experimental-gui/fft_top_block.py        
2008-08-03 17:44:19 UTC (rev 9162)
@@ -27,33 +27,10 @@
 
 from gnuradio import gr
 from pubsub import pubsub
-import threading
+from msgq_publisher import msgq_publisher
 import simple_usrp
 import logpwrfft
 
-class _fft_thread(threading.Thread):
-    """
-    This background thread simply reads FFT frames from the message
-    queue and sets the top block 'fft' property to their string
-    representation. External code can add one or more listeners to
-    this property to receive notification when an FFT frame comes in.
-    """
-    def __init__(self, msgq, tb):
-       threading.Thread.__init__(self)
-        self._msgq = msgq
-        self._tb = tb
-        self._keep_running = True
-       self.setDaemon(1)
-
-    def run(self):
-       while self._keep_running:
-           msg = self._msgq.delete_head()
-           self._tb['fft'] = msg.to_string()
-
-    def stop(self):
-        self._keep_running = False
-
-
 class fft_top_block(gr.top_block, pubsub):
     """!
     GNU Radio top block to create a stream of FFT frames at a particular
@@ -140,7 +117,7 @@
         """
         Create update thread.  Updates property 'fft' at desired frame rate
         """
-       self._thread = _fft_thread(self._msgq, self)
+       self._thread = msgq_publisher(self._msgq, self, 'fft')
 
     def _set_decim(self, decim):
         """!
@@ -155,9 +132,6 @@
        This method gets called by the external GUI or other code to start the 
top block
        operation.
        """
-       # Start the queue runner background thread
-       self._thread.start()
-
        # Using gr.top_block.start() here keeps Python's SIGINT handler active,
        # and we agree to handle SIGINT in our code if needed.  We must also 
call
        # gr.top_block.stop() and .wait() to properly shut down GNU Radio
@@ -168,7 +142,7 @@
        This method gets called to shutdown the top block.  It stops the 
background
        thread, then calls stop() and wait() on the top block.
        """
-        self._thread.stop()
+        del self._thread
         self.stop()
        self.wait()
 

Added: gnuradio/branches/features/experimental-gui/msgq_publisher.py
===================================================================
--- gnuradio/branches/features/experimental-gui/msgq_publisher.py               
                (rev 0)
+++ gnuradio/branches/features/experimental-gui/msgq_publisher.py       
2008-08-03 17:44:19 UTC (rev 9162)
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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 3, or (at your option)
+# any later version.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+"""
+Publishes gr.msg_queue entries as a pubsub property
+"""
+
+import threading
+
+class msgq_publisher(threading.Thread):
+    """
+    This thread reads messages off the supplied message queue, then
+    sets the supplied property key to the string representation of
+    the message.
+    """
+    def __init__(self, msgq, p, key):
+       threading.Thread.__init__(self)
+        self._msgq = msgq
+        self._p = p
+       self._key = key
+        self._keep_running = True
+       self.setDaemon(1)
+       self.start()
+       
+    def run(self):
+       while self._keep_running:
+           msg = self._msgq.delete_head()
+           self._p[self._key] = msg.to_string()
+
+    def __del__(self):
+       self._keep_running = False

Modified: gnuradio/branches/features/experimental-gui/todo.txt
===================================================================
--- gnuradio/branches/features/experimental-gui/todo.txt        2008-08-03 
17:16:07 UTC (rev 9161)
+++ gnuradio/branches/features/experimental-gui/todo.txt        2008-08-03 
17:44:19 UTC (rev 9162)
@@ -6,7 +6,6 @@
 -constsink: replace mpsk recv with costas + clock recovery
 -give numbersink the treatment
 -run expand on all files (sorry tabs)
--refactor msgq_publisher
 -update fft_top_block to subscribe to 'sample_rate' on self._u
 -update *sink.py to use new controller-aware top blocks instead of internal 
and/or blks2 ones
 -fix grc_scopesink_test.py 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]