{
d_impl->dump();
}
-
-bool
-gr_top_block::is_running()
-{
- return d_impl->is_running();
-}
/* -*- c++ -*- */
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* Displays flattened flowgraph edges and block connectivity
*/
void dump();
-
- /*!
- * Returns true if flowgraph is running
- */
- bool is_running();
};
#endif /* INCLUDED_GR_TOP_BLOCK_H */
/* -*- c++ -*- */
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
void run();
void lock();
void unlock() throw (std::runtime_error);
- bool is_running();
void dump();
};
std::cout << "start: entered " << this << std::endl;
if (d_running)
- throw std::runtime_error("top block already running or wait() not called after previous stop()");
+ throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()");
+
+ if (d_lock_count > 0)
+ throw std::runtime_error("top_block::start: can't call start with flow graph locked");
// Create new flat flow graph by flattening hierarchy
d_ffg = d_owner->flatten();
// Execute scheduler threads
start_threads();
+ d_running = true;
}
gr_top_block_impl::unlock()
{
omni_mutex_lock lock(d_reconf);
- if (d_lock_count <= 0)
+ if (d_lock_count <= 0){
+ d_lock_count = 0; // fix it, then complain
throw std::runtime_error("unpaired unlock() call");
+ }
d_lock_count--;
if (GR_TOP_BLOCK_IMPL_DEBUG)
std::cout << "restart: entered" << std::endl;
if (!d_running)
- throw std::runtime_error("top block is not running");
+ return; // nothing to do
// Stop scheduler threads and wait for completion
stop();
d_ffg = new_ffg;
start_threads();
+ d_running = true;
}
void
virtual void wait() = 0;
// Lock the top block to allow reconfiguration
- virtual void lock();
+ void lock();
// Unlock the top block at end of reconfiguration
- virtual void unlock();
+ void unlock();
// Dump the flowgraph to stdout
void dump();
-
- // Return true if flowgraph is running
- bool is_running() const { return d_running; }
protected:
int d_lock_count;
virtual void start_threads() = 0;
- virtual void restart();
/*!
* Make a vector of gr_block from a vector of gr_basic_block
*/
static gr_block_vector_t make_gr_block_vector(gr_basic_block_vector_t blocks);
+private:
+ void restart();
};
#endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */
std::cout << "start_threads: starting " << thread << std::endl;
thread->start();
}
-
- d_running = true;
}
/*
# self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
def _configure_graph (self, type):
- was_running = self.is_running ()
- if was_running:
- self.stop ()
- self.disconnect_all ()
- if type == gr.GR_SIN_WAVE:
- self.connect (self.siggen, self.u)
- # self.connect (self.siggen, self.file_sink)
- self.siggen.set_waveform (type)
- self.src = self.siggen
- elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
- self.connect (self.noisegen, self.u)
- self.noisegen.set_type (type)
- self.src = self.noisegen
- elif type == gr.GR_CONST_WAVE:
- self.connect (self.vecgen, self.u)
- self.src = self.vecgen
- else:
- raise ValueError, type
- if was_running:
- self.start ()
+ try:
+ self.lock()
+ self.disconnect_all ()
+ if type == gr.GR_SIN_WAVE:
+ self.connect (self.siggen, self.u)
+ # self.connect (self.siggen, self.file_sink)
+ self.siggen.set_waveform (type)
+ self.src = self.siggen
+ elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+ self.connect (self.noisegen, self.u)
+ self.noisegen.set_type (type)
+ self.src = self.noisegen
+ elif type == gr.GR_CONST_WAVE:
+ self.connect (self.vecgen, self.u)
+ self.src = self.vecgen
+ else:
+ raise ValueError, type
+ finally:
+ self.unlock()
def set_freq(self, target_freq):
"""
# self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
def _configure_graph (self, type):
- was_running = self.is_running ()
- if was_running:
- self.stop ()
- self.disconnect_all ()
- if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
- self.connect (self.siggen, self.u)
- # self.connect (self.siggen, self.file_sink)
- self.siggen.set_waveform (type)
- self.src = self.siggen
- elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
- self.connect (self.noisegen, self.u)
- self.noisegen.set_type (type)
- self.src = self.noisegen
- else:
- raise ValueError, type
- if was_running:
- self.start ()
+ try:
+ self.lock()
+ self.disconnect_all ()
+ if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
+ self.connect (self.siggen, self.u)
+ # self.connect (self.siggen, self.file_sink)
+ self.siggen.set_waveform (type)
+ self.src = self.siggen
+ elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+ self.connect (self.noisegen, self.u)
+ self.noisegen.set_type (type)
+ self.src = self.noisegen
+ else:
+ raise ValueError, type
+ finally:
+ self.unlock()
def set_freq(self, target_freq):
"""