Re: g_idle_add() clarification

2015-01-20 Thread Paul Davis
On Tue, Jan 20, 2015 at 7:55 PM, Ian Chapman  wrote:

> Thanks Chris,
> I think that not only is my code broken my idea on how to do what I
> want is broken.  I must fix that before I start on the code.
>
> My starting point was two button, scan off and scan on in glade.  Scan
> on sets a flag and it scans til the off button is pressed.  So the off
> button could not be pressed til end-of-scan, a situation commonly known as
> a deadly embrace in hardware design.  After that g_idle_add() was pointed
> out to me and I've been innovating rather blindly ever since.
>
> I interpreted g_idle_add() as inserting Scanning() into the main loop
> and if Scanning returned FALSE it was removed from the main loop.  So I
> guess I'm not understanding the following explanation of
> guint g_idle_add(GSourceFunc function, gpointer data); :-
>

it is worse than this. you don't understand the difference between naming a
function and calling a function. consider the following code:

gboolean foo() { return FALSE; }
foo; /* names foo */
foo(); /* calls foo */

g_idle_add (foo, NULL); /* adds foo to the idle part of the main event loop
*/
g_idle_add (foo(), NULL); /* calls foo and adds its return value, FALSE
(aka 0 or NULL) to the idle loop */
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_idle_add() clarification

2015-01-20 Thread Ian Chapman

Thanks Chris,
I think that not only is my code broken my idea on how to do what I 
want is broken.  I must fix that before I start on the code.


My starting point was two button, scan off and scan on in glade.  
Scan on sets a flag and it scans til the off button is pressed.  So the 
off button could not be pressed til end-of-scan, a situation commonly 
known as a deadly embrace in hardware design.  After that g_idle_add() 
was pointed out to me and I've been innovating rather blindly ever since.


I interpreted g_idle_add() as inserting Scanning() into the main 
loop and if Scanning returned FALSE it was removed from the main loop.  
So I guess I'm not understanding the following explanation of

guint g_idle_add(GSourceFunc function, gpointer data); :-

Adds a function to be called whenever there are no higher priority 
events pending to the default main loop.  The function is given the 
default idle priority, G_PRIORITY_DEFAULT_IDLE. If the fRegards 
Ian.unction returns FALSE it is automatically removed from the list of 
event sources and will not be called again.
This internally creates a main loop source using g_idle_source_new() and 
attaches it to the main loop context using g_source_attach(). You can do 
these steps manually if you need greater control.

Parameters
function,  function to call
data, data to pass to function .

Also Chris you indicated that maybe g_idle_add() should not be in a 
callback.  Maybe it should be in main() after gtk_widget_show (window);  
I'm stuck for the moment not understanding.


Richard's suggestion improved things but my code and idea is still 
broken on exiting Scanning()


Regards Ian.

On 01/20/2015 04:57 PM, Chris Vine wrote:

On Tue, 20 Jan 2015 16:47:27 -0500
Ian Chapman  wrote:

Thanks for your reply Richard.
Yes, I know that.  I thought Scanning() was a lower level than the
gtk window and thus the StartScan_active() would exit before the
mainloop would add Scanning() and then only execute Scanning() when
nothing else (signals) was active.

I was also asking about the GLib-CRITICAL stuff on exiting
Scanning().  Ian.

On 01/20/2015 03:34 PM, richard boaz wrote:

hi,

you are calling the function Scanning() in the g_idle_add() call.g_idle_add()

richard

On Tue, Jan 20, 2015 at 3:23 PM, Ian Chapman mailto:ichap...@videotron.ca>> wrote:

 Hi all,

 Sorry to bother but I'm lost with the workings of

 guint g_idle_add ()

 My code is as
 follows

 extern "C"

 void on_StartScan_activate() //from gtk menu item

 { printf("Start Scan Activated. \n");

 scan_on_fg =1;

 Scanning_lvl = g_idle_add((GSourceFunc) Scanning(), (gpointer)
0);g_idle_add()
g_idle_add()
 printf("Exiting StartScan.\n");  //main.cpp, Line 129

 return; }

 I get to Scanning() okay but I don't exit
on_StartScan_activeat() until I exit Scanning() (not what I
expected).

 Worse still when I step through Scanning as I exit I get

 (gdb) next

 (main:24011): GLib-CRITICAL **: g_idle_add_full: assertion
 `function != NULL' failed

 on_StartScan_activate () at main.cpp:129

 (gdb) next

 Exiting StartScan.


 guint Scanning(void)
g_idle_add()
 {

 while(1 == scan_on_fg)

 { //Bean counting with rest of GUI in control, I hoped. }

 return(FALSE); //Remove this thread.

 }


 Regards Ian.

What Richard is telling you is that your code is broken.  Fix that
before dealing with warnings.  The point is that your broken code is
doing what the warning is telling you about - passing a FALSE value
(which equates here to NULL here), as returned by Scanning(), to the
function pointer argument of g_idle_add().

You have other problems.  You are passing a callback to g_idle_add()
which does not have the correct signature and surpressing this failure
by a cast.  (Why?.)  Fix that as well and see what warnings are left
over.

Chris
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list



___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_idle_add() clarification

2015-01-20 Thread Chris Vine
On Tue, 20 Jan 2015 16:47:27 -0500
Ian Chapman  wrote:
> Thanks for your reply Richard.
> Yes, I know that.  I thought Scanning() was a lower level than the
> gtk window and thus the StartScan_active() would exit before the
> mainloop would add Scanning() and then only execute Scanning() when
> nothing else (signals) was active.
> 
> I was also asking about the GLib-CRITICAL stuff on exiting
> Scanning().  Ian.
> 
> On 01/20/2015 03:34 PM, richard boaz wrote:
> > hi,
> >
> > you are calling the function Scanning() in the g_idle_add() call.
> >
> > richard
> >
> > On Tue, Jan 20, 2015 at 3:23 PM, Ian Chapman  > > wrote:
> >
> > Hi all,
> >
> > Sorry to bother but I'm lost with the workings of
> >
> > guint g_idle_add ()
> >
> > My code is as
> > follows
> >
> > extern "C"
> >
> > void on_StartScan_activate() //from gtk menu item
> >
> > { printf("Start Scan Activated. \n");
> >
> > scan_on_fg =1;
> >
> > Scanning_lvl = g_idle_add((GSourceFunc) Scanning(), (gpointer)
> > 0);
> >
> > printf("Exiting StartScan.\n");  //main.cpp, Line 129
> >
> > return; }
> >
> > I get to Scanning() okay but I don't exit
> > on_StartScan_activeat() until I exit Scanning() (not what I
> > expected).
> >
> > Worse still when I step through Scanning as I exit I get
> >
> > (gdb) next
> >
> > (main:24011): GLib-CRITICAL **: g_idle_add_full: assertion
> > `function != NULL' failed
> >
> > on_StartScan_activate () at main.cpp:129
> >
> > (gdb) next
> >
> > Exiting StartScan.
> >
> >
> > guint Scanning(void)
> >
> > {
> >
> > while(1 == scan_on_fg)
> >
> > { //Bean counting with rest of GUI in control, I hoped. }
> >
> > return(FALSE); //Remove this thread.
> >
> > }
> >
> >
> > Regards Ian.

What Richard is telling you is that your code is broken.  Fix that
before dealing with warnings.  The point is that your broken code is
doing what the warning is telling you about - passing a FALSE value
(which equates here to NULL here), as returned by Scanning(), to the
function pointer argument of g_idle_add().

You have other problems.  You are passing a callback to g_idle_add()
which does not have the correct signature and surpressing this failure
by a cast.  (Why?.)  Fix that as well and see what warnings are left
over.

Chris
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_idle_add() clarification

2015-01-20 Thread richard boaz
hi,

Scanning() is being called as part of g_idle_add().  Scanning() returns
FALSE, which = NULL in C, so your call to g_idle_add() at execution time
resolves to:

g_idle_add((GSourceFunc) 0, (gpointer) 0);

this clearly won't work.

rewrite as:

Scanning_lvl = g_idle_add((GSourceFunc) Scanning, (gpointer) 0);

and make sure Scanning() is declared somewhere beforehand.

and then see if you don't get a different execution result.

r-


On Tue, Jan 20, 2015 at 4:47 PM, Ian Chapman  wrote:

>  Thanks for your reply Richard.
> Yes, I know that.  I thought Scanning() was a lower level than the gtk
> window and thus the StartScan_active() would exit before the mainloop would
> add Scanning() and then only execute Scanning() when nothing else (signals)
> was active.
>
> I was also asking about the GLib-CRITICAL stuff on exiting Scanning().
> Ian.
>
>
> On 01/20/2015 03:34 PM, richard boaz wrote:
>
>  hi,
>
> you are calling the function Scanning() in the g_idle_add() call.
>
>  richard
>
> On Tue, Jan 20, 2015 at 3:23 PM, Ian Chapman 
> wrote:
>
>>  Hi all,
>>
>> Sorry to bother but I'm lost with the workings of
>>
>> guint g_idle_add ()
>>
>> My code is as
>> follows
>>
>> extern "C"
>>
>> void on_StartScan_activate() //from gtk menu item
>>
>> { printf("Start Scan Activated. \n");
>>
>> scan_on_fg =1;
>>
>> Scanning_lvl = g_idle_add((GSourceFunc) Scanning(), (gpointer) 0);
>>
>> printf("Exiting StartScan.\n");  //main.cpp, Line 129
>>
>> return; }
>>
>> I get to Scanning() okay but I don't exit on_StartScan_activeat() until I
>> exit Scanning() (not what I expected).
>>
>> Worse still when I step through Scanning as I exit I get
>>
>> (gdb) next
>>
>>  (main:24011): GLib-CRITICAL **: g_idle_add_full: assertion `function !=
>> NULL' failed
>>
>> on_StartScan_activate () at main.cpp:129
>>
>> (gdb) next
>>
>> Exiting StartScan.
>>
>>
>>  guint Scanning(void)
>>
>> {
>>
>> while(1 == scan_on_fg)
>>
>> { //Bean counting with rest of GUI in control, I hoped. }
>>
>> return(FALSE); //Remove this thread.
>>
>> }
>>
>>
>>  Regards Ian.
>>
>> ___
>> gtk-list mailing list
>> gtk-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-list
>>
>>
>
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_idle_add() clarification

2015-01-20 Thread Ian Chapman

Thanks for your reply Richard.
Yes, I know that.  I thought Scanning() was a lower level than the gtk 
window and thus the StartScan_active() would exit before the mainloop 
would add Scanning() and then only execute Scanning() when nothing else 
(signals) was active.


I was also asking about the GLib-CRITICAL stuff on exiting Scanning().  Ian.

On 01/20/2015 03:34 PM, richard boaz wrote:

hi,

you are calling the function Scanning() in the g_idle_add() call.

richard

On Tue, Jan 20, 2015 at 3:23 PM, Ian Chapman > wrote:


Hi all,

Sorry to bother but I'm lost with the workings of

guint g_idle_add ()

My code is as
follows

extern "C"

void on_StartScan_activate() //from gtk menu item

{ printf("Start Scan Activated. \n");

scan_on_fg =1;

Scanning_lvl = g_idle_add((GSourceFunc) Scanning(), (gpointer) 0);

printf("Exiting StartScan.\n");  //main.cpp, Line 129

return; }

I get to Scanning() okay but I don't exit on_StartScan_activeat()
until I exit Scanning() (not what I expected).

Worse still when I step through Scanning as I exit I get

(gdb) next

(main:24011): GLib-CRITICAL **: g_idle_add_full: assertion
`function != NULL' failed

on_StartScan_activate () at main.cpp:129

(gdb) next

Exiting StartScan.


guint Scanning(void)

{

while(1 == scan_on_fg)

{ //Bean counting with rest of GUI in control, I hoped. }

return(FALSE); //Remove this thread.

}


Regards Ian.


___
gtk-list mailing list
gtk-list@gnome.org 
https://mail.gnome.org/mailman/listinfo/gtk-list




___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_idle_add() clarification

2015-01-20 Thread richard boaz
hi,

you are calling the function Scanning() in the g_idle_add() call.

richard

On Tue, Jan 20, 2015 at 3:23 PM, Ian Chapman  wrote:

>  Hi all,
>
> Sorry to bother but I'm lost with the workings of
>
> guint g_idle_add ()
>
> My code is as
> follows
>
> extern "C"
>
> void on_StartScan_activate() //from gtk menu item
>
> { printf("Start Scan Activated. \n");
>
> scan_on_fg =1;
>
> Scanning_lvl = g_idle_add((GSourceFunc) Scanning(), (gpointer) 0);
>
> printf("Exiting StartScan.\n");  //main.cpp, Line 129
>
> return; }
>
> I get to Scanning() okay but I don't exit on_StartScan_activeat() until I
> exit Scanning() (not what I expected).
>
> Worse still when I step through Scanning as I exit I get
>
> (gdb) next
>
>  (main:24011): GLib-CRITICAL **: g_idle_add_full: assertion `function !=
> NULL' failed
>
> on_StartScan_activate () at main.cpp:129
>
> (gdb) next
>
> Exiting StartScan.
>
>
>  guint Scanning(void)
>
> {
>
> while(1 == scan_on_fg)
>
> { //Bean counting with rest of GUI in control, I hoped. }
>
> return(FALSE); //Remove this thread.
>
> }
>
>
>  Regards Ian.
>
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list