Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-03-03 Thread Marcus Müller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Activecat,

the constructor of a block must have been called before the block has
been connect()ed; so there's no way a flowgraph is already running
when your block's constructor is called.

Greetings,
Marcus

On 03.03.2014 06:53, Activecat wrote:
 Dear Sir, Thank you very much.
 
 What if, we want to stop the flow graph in the constructor of a
 block?
 
 In work() we can just return -1. But in constructor, what value
 should be returned, also -1  ?
 
 Regards, Activecat
 
 
 On Sun, Feb 2, 2014 at 9:05 PM, Martin Braun
 martin.br...@ettus.com wrote:
 
 On 01.02.2014 13:51, Activecat wrote:
 
 But the function stop() fails to work. The flow graph continue
 executing infinitely...
 
 Question: How to stop the flow graph when this-d_complete ==
 true ?
 
 
 Return -1 (or WORK_DONE) in your work() function.
 
 MB
 
 
 ___ Discuss-gnuradio
 mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 
 ___ Discuss-gnuradio
 mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTFEqdAAoJEAFxB7BbsDrLv84H/jghxvQXY6VcZPvRXs1BKmxp
Odr8p/ICE9rpcz21M6M0ILxqhKaOp5vlaG/n6UMM2fFU+Cf7RQQkFrVsEBcqUcGg
sgYjE+PmTuIbn6xg6mupAJdN1iVsztH+5qU/71SPxJjfwpnJjsJrzzGlQC6JhGIr
fPHDG5DLAS11Q8USSFAc5Y7vXI57rskCZ3/Qq1j+dTl5pgNLSzsccb4AmVBy2dCB
7mM1PIxAuTJgaeXbk85BEnhkwdI4HQzOS7phg53ChYIWMKs+WCsjk0weUNMj2VZt
rXdd137xZjkfPHyGJ73spjhJ7OHUW8NeQaNxauI8Uf45S6jnNFFx/vzD1EEgIV8=
=vI+z
-END PGP SIGNATURE-

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-03-03 Thread Activecat
Dear Marcus,

Says, the constructor performed some basic checking on the constructor
arguments, then had found some fatal error (says, division by zero) and
decided to ban the flowgraph from being executed.

A workaround is to get the constructor to set a class variable to false,
says,
d_valid = false;

then in the work() it will check this d_valid as follows:

int work()
{
if ( ! d_valid )
   return -1
.
.  (other stuff as usual)
}


But isn't there a better way to do this ..?
(to ban the flowgraph from being executed within the constructor)

Please advise, thanks.

Regards,
Activecat



On Mon, Mar 3, 2014 at 5:25 PM, Marcus Müller mar...@hostalia.de wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Activecat,

 the constructor of a block must have been called before the block has
 been connect()ed; so there's no way a flowgraph is already running
 when your block's constructor is called.

 Greetings,
 Marcus

 On 03.03.2014 06:53, Activecat wrote:
  Dear Sir, Thank you very much.
 
  What if, we want to stop the flow graph in the constructor of a
  block?
 
  In work() we can just return -1. But in constructor, what value
  should be returned, also -1  ?
 
  Regards, Activecat
 
 
  On Sun, Feb 2, 2014 at 9:05 PM, Martin Braun
  martin.br...@ettus.com wrote:
 
  On 01.02.2014 13:51, Activecat wrote:
 
  But the function stop() fails to work. The flow graph continue
  executing infinitely...
 
  Question: How to stop the flow graph when this-d_complete ==
  true ?
 
 
  Return -1 (or WORK_DONE) in your work() function.
 
  MB
 
 
  ___ Discuss-gnuradio
  mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 
  ___ Discuss-gnuradio
  mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1
 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

 iQEcBAEBAgAGBQJTFEqdAAoJEAFxB7BbsDrLv84H/jghxvQXY6VcZPvRXs1BKmxp
 Odr8p/ICE9rpcz21M6M0ILxqhKaOp5vlaG/n6UMM2fFU+Cf7RQQkFrVsEBcqUcGg
 sgYjE+PmTuIbn6xg6mupAJdN1iVsztH+5qU/71SPxJjfwpnJjsJrzzGlQC6JhGIr
 fPHDG5DLAS11Q8USSFAc5Y7vXI57rskCZ3/Qq1j+dTl5pgNLSzsccb4AmVBy2dCB
 7mM1PIxAuTJgaeXbk85BEnhkwdI4HQzOS7phg53ChYIWMKs+WCsjk0weUNMj2VZt
 rXdd137xZjkfPHyGJ73spjhJ7OHUW8NeQaNxauI8Uf45S6jnNFFx/vzD1EEgIV8=
 =vI+z
 -END PGP SIGNATURE-

 ___
 Discuss-gnuradio mailing list
 Discuss-gnuradio@gnu.org
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-03-03 Thread Miklos Maroti
Dear Activecat,

Throw an exception. It will kill the application.

Miklos

On Mon, Mar 3, 2014 at 11:57 AM, Activecat active...@gmail.com wrote:
 Dear Marcus,

 Says, the constructor performed some basic checking on the constructor
 arguments, then had found some fatal error (says, division by zero) and
 decided to ban the flowgraph from being executed.

 A workaround is to get the constructor to set a class variable to false,
 says,
 d_valid = false;

 then in the work() it will check this d_valid as follows:

 int work()
 {
 if ( ! d_valid )
return -1
 .
 .  (other stuff as usual)
 }


 But isn't there a better way to do this ..?
 (to ban the flowgraph from being executed within the constructor)

 Please advise, thanks.

 Regards,
 Activecat



 On Mon, Mar 3, 2014 at 5:25 PM, Marcus Müller mar...@hostalia.de wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Activecat,

 the constructor of a block must have been called before the block has
 been connect()ed; so there's no way a flowgraph is already running
 when your block's constructor is called.

 Greetings,
 Marcus

 On 03.03.2014 06:53, Activecat wrote:
  Dear Sir, Thank you very much.
 
  What if, we want to stop the flow graph in the constructor of a
  block?
 
  In work() we can just return -1. But in constructor, what value
  should be returned, also -1  ?
 
  Regards, Activecat
 
 
  On Sun, Feb 2, 2014 at 9:05 PM, Martin Braun
  martin.br...@ettus.com wrote:
 
  On 01.02.2014 13:51, Activecat wrote:
 
  But the function stop() fails to work. The flow graph continue
  executing infinitely...
 
  Question: How to stop the flow graph when this-d_complete ==
  true ?
 
 
  Return -1 (or WORK_DONE) in your work() function.
 
  MB
 
 
  ___ Discuss-gnuradio
  mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 
  ___ Discuss-gnuradio
  mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1
 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

 iQEcBAEBAgAGBQJTFEqdAAoJEAFxB7BbsDrLv84H/jghxvQXY6VcZPvRXs1BKmxp
 Odr8p/ICE9rpcz21M6M0ILxqhKaOp5vlaG/n6UMM2fFU+Cf7RQQkFrVsEBcqUcGg
 sgYjE+PmTuIbn6xg6mupAJdN1iVsztH+5qU/71SPxJjfwpnJjsJrzzGlQC6JhGIr
 fPHDG5DLAS11Q8USSFAc5Y7vXI57rskCZ3/Qq1j+dTl5pgNLSzsccb4AmVBy2dCB
 7mM1PIxAuTJgaeXbk85BEnhkwdI4HQzOS7phg53ChYIWMKs+WCsjk0weUNMj2VZt
 rXdd137xZjkfPHyGJ73spjhJ7OHUW8NeQaNxauI8Uf45S6jnNFFx/vzD1EEgIV8=
 =vI+z
 -END PGP SIGNATURE-

 ___
 Discuss-gnuradio mailing list
 Discuss-gnuradio@gnu.org
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio



 ___
 Discuss-gnuradio mailing list
 Discuss-gnuradio@gnu.org
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-03-03 Thread Marcus Müller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Activecat,

as Miklos wrote: Let your Constructor throw an exception.
For a little detail on that, refer to
http://www.parashift.com/c++-faq-lite/ctors-can-throw.html .
You can surround your block construction with a try{}catch-clause, and
handle your error, so your application may deal with that gracefully
(instead of just dying).

Another common method of dealing with stuff like this is, if you
really have complex constructor arguments and might need to check if
they make sense in multiple places
- - let your class have a static method validate_arguments(...) that
returns true or false,
- - let your c'tor call that and throw an exception when it's false, and
- - use that unbound method (that is calling
activecats_class::validate_arguments() rather than calling
instance_of_that_class.validate_arguments()) from wherever you want to
calculate arguments.

Greetings,
Marcus

On 03.03.2014 12:02, Miklos Maroti wrote:
 Dear Activecat,
 
 Throw an exception. It will kill the application.
 
 Miklos
 
 On Mon, Mar 3, 2014 at 11:57 AM, Activecat active...@gmail.com
 wrote:
 Dear Marcus,
 
 Says, the constructor performed some basic checking on the
 constructor arguments, then had found some fatal error (says,
 division by zero) and decided to ban the flowgraph from being
 executed.
 
 A workaround is to get the constructor to set a class variable to
 false, says, d_valid = false;
 
 then in the work() it will check this d_valid as follows:
 
 int work() { if ( ! d_valid ) return -1 . .
 (other stuff as usual) }
 
 
 But isn't there a better way to do this ..? (to ban the flowgraph
 from being executed within the constructor)
 
 Please advise, thanks.
 
 Regards, Activecat
 
 
 
 On Mon, Mar 3, 2014 at 5:25 PM, Marcus Müller
 mar...@hostalia.de wrote:
 
 Activecat,
 
 the constructor of a block must have been called before the block
 has been connect()ed; so there's no way a flowgraph is already
 running when your block's constructor is called.
 
 Greetings, Marcus
 
 On 03.03.2014 06:53, Activecat wrote:
 Dear Sir, Thank you very much.
 
 What if, we want to stop the flow graph in the constructor
 of a block?
 
 In work() we can just return -1. But in constructor, what
 value should be returned, also -1  ?
 
 Regards, Activecat
 
 
 On Sun, Feb 2, 2014 at 9:05 PM, Martin Braun 
 martin.br...@ettus.com wrote:
 
 On 01.02.2014 13:51, Activecat wrote:
 
 But the function stop() fails to work. The flow graph
 continue executing infinitely...
 
 Question: How to stop the flow graph when
 this-d_complete == true ?
 
 
 Return -1 (or WORK_DONE) in your work() function.
 
 MB
 
 
 ___
 Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 
 ___
 Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 ___ 
 Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 ___ Discuss-gnuradio
 mailing list Discuss-gnuradio@gnu.org 
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTFGmXAAoJEAFxB7BbsDrLOLAIAJUgbhHeABDD9bDgCjJYRIhu
VzbVgZPo0bnPVfNGkojrO5wRTSzjHbCqQFkKbl4JCPLK6+IPq/9mL+iDffPQ9Aic
IGZLhq/ep8LwfiDjjh6D6BNQYmHqa6hRLPkHBzETmKqvBK5258b86IgedJNIDJF7
+qfVZWQsi3FDUyGSD6fVRHOUkfKT3naR0FqhipxtMRWFprBRrovMV23IqbVMdDQv
WfxeWyNoJMpYjXPT+S/pt7h9kxKUbcZK4aOWwuhnwmTahFcfcx+GCIc54UQHegVR
/WvOD1LNiYIXLJg6wEssN783OXbMqzWTaTl0+CFf6NWO4jQQFaAtoiUk3+EjXIQ=
=9pRp
-END PGP SIGNATURE-

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-03-03 Thread Activecat
Dear gurus,
I got it, thank you very much !

Regards,
Activecat


On Mon, Mar 3, 2014 at 9:11 PM, Martin Braun martin.br...@ettus.com wrote:

 On 03/03/2014 12:37 PM, Marcus Müller wrote:
  Hi Activecat,
 
  as Miklos wrote: Let your Constructor throw an exception.
  For a little detail on that, refer to
  http://www.parashift.com/c++-faq-lite/ctors-can-throw.html .
  You can surround your block construction with a try{}catch-clause, and
  handle your error, so your application may deal with that gracefully
  (instead of just dying).

 Also, grep for throw in the impl files for an example, we do that a lot
 in GNU Radio.

 M

  Another common method of dealing with stuff like this is, if you
  really have complex constructor arguments and might need to check if
  they make sense in multiple places
  - let your class have a static method validate_arguments(...) that
  returns true or false,
  - let your c'tor call that and throw an exception when it's false, and
  - use that unbound method (that is calling
  activecats_class::validate_arguments() rather than calling
  instance_of_that_class.validate_arguments()) from wherever you want to
  calculate arguments.
 
  Greetings,
  Marcus
 
  On 03.03.2014 12:02, Miklos Maroti wrote:
  Dear Activecat,
 
  Throw an exception. It will kill the application.
 
  Miklos
 
  On Mon, Mar 3, 2014 at 11:57 AM, Activecat active...@gmail.com
  wrote:
  Dear Marcus,
 
  Says, the constructor performed some basic checking on the
  constructor arguments, then had found some fatal error (says,
  division by zero) and decided to ban the flowgraph from being
  executed.
 
  A workaround is to get the constructor to set a class variable to
  false, says, d_valid = false;
 
  then in the work() it will check this d_valid as follows:
 
  int work() { if ( ! d_valid ) return -1 . .
  (other stuff as usual) }
 
 
  But isn't there a better way to do this ..? (to ban the flowgraph
  from being executed within the constructor)
 
  Please advise, thanks.
 
  Regards, Activecat
 
 
 
  On Mon, Mar 3, 2014 at 5:25 PM, Marcus Müller
  mar...@hostalia.de wrote:
 
  Activecat,
 
  the constructor of a block must have been called before the block
  has been connect()ed; so there's no way a flowgraph is already
  running when your block's constructor is called.
 
  Greetings, Marcus
 
  On 03.03.2014 06:53, Activecat wrote:
  Dear Sir, Thank you very much.
 
  What if, we want to stop the flow graph in the constructor
  of a block?
 
  In work() we can just return -1. But in constructor, what
  value should be returned, also -1  ?
 
  Regards, Activecat
 
 
  On Sun, Feb 2, 2014 at 9:05 PM, Martin Braun
  martin.br...@ettus.com wrote:
 
  On 01.02.2014 13:51, Activecat wrote:
 
  But the function stop() fails to work. The flow graph
  continue executing infinitely...
 
  Question: How to stop the flow graph when
  this-d_complete == true ?
 
 
  Return -1 (or WORK_DONE) in your work() function.
 
  MB
 
 
  ___
  Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
 
  ___
  Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
  ___
  Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
 
  ___ Discuss-gnuradio
  mailing list Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 
 
  ___
  Discuss-gnuradio mailing list
  Discuss-gnuradio@gnu.org
  https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
 


 ___
 Discuss-gnuradio mailing list
 Discuss-gnuradio@gnu.org
 https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Re: [Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-02-02 Thread Martin Braun

On 01.02.2014 13:51, Activecat wrote:

But the function stop() fails to work. The flow graph continue executing
infinitely...

Question:
How to stop the flow graph when this-d_complete == true ?


Return -1 (or WORK_DONE) in your work() function.

MB


___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


[Discuss-gnuradio] Unable to stop the flow graph after calling stop()

2014-02-01 Thread Activecat
Dear guru,

I am trying to create a block similar to Vector Source.
My objective is to stop the flow graph when the vector has sent out all its
elements.
(This is equivalent to Repeat: No in Vector Source)

But the function stop() fails to work. The flow graph continue executing
infinitely...

Question:
How to stop the flow graph when this-d_complete == true ?

Below is my code in file: lib/integer_source_impl.cc



#include gr_io_signature.h
#include integer_source_impl.h

namespace gr {
  namespace activecat {

integer_source::sptr
integer_source::make(const std::vector int data, bool repeat)
{ return gnuradio::get_initial_sptr (new integer_source_impl( data,
repeat )); }

// private constructor
integer_source_impl::integer_source_impl( const std::vector int
data, bool repeat)
  : gr_sync_block(integer_source,
  gr_make_io_signature( 0, 0, 0 ),
  gr_make_io_signature( 1, 1, sizeof(int))),
d_data( data ),
d_repeat( repeat ),
d_count( 0 ),
d_completed( false )
{ }

// virtual destructor
integer_source_impl::~integer_source_impl()
{ }

int
integer_source_impl::work(int noutput_items,
  gr_vector_const_void_star input_items,
  gr_vector_void_star output_items)
{
if ( d_completed )
{
std::cout  Have completed one cycle!  std::endl;
stop();
return 0;
}

int *out = (int *) output_items[0];

int size = d_data.size();
for (int i=0; i  noutput_items; i++)
{
out[i] = d_data[ d_count ];
d_count++;
if ( d_count = size )
d_count = 0;
}
d_completed = true;

// Tell runtime system how many output items we produced.
return noutput_items;
}


  } /* namespace activecat */
} /* namespace gr */
___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio