how to properly use settimmer?
ok I am willing to learn how to make this work. :D
I can get my program to work on the cli. changing the image at a given time, now i just want to autotomize it to be able to set a time for it to call for another file to load off a (linked) list within the program. I got the timer to cycle in some separate code using seconds, ( converting it to minutes after I get it to actually work), then I dropped it in my main code, I've tried this about 5 different ways its getting late here so I'm posting my last attempt. Code:
if (opts.cycletime > 0) Code:
unsigned int cycletime; Code:
case 201: Code:
char *set_timer(void) |
You are properly using setitimer(), the comments do not match the timer values, you are using 1 second for the first timeout value and then whatever is in the value of 'whattime' for the repeat timeout values.
You don't show your timer handler. I have code which does work, which uses SIGALRM, which may or may not be the same numerical value for the SIG you are using. Or multiple signals may also occur at timeout. Those are really the technical differences I notice in what you're using. Not sure if they're enough where things won't work, just that the timeouts are not 250 mS as your comment states. They can't be when you're using the tv_sec portion of the structure. Use the tv_usec and if the value is 250,000 then it will be 250 mSec. Next, my timer_handler() increments a counter. My main loop checks that counter against a value and once it overflows, it will do the desired action, and it will reset the counter. The timer_handler() runs forever, always just incrementing the counter. Additional thought is that say my desired time is 1/2 of a second, or 500 mSec. My timer_handler() function, run by my itimer, actually runs at maybe 20 mSec. The timer_handler() increments a counter each time. So my main loop checks that count to see if it exceeds a value of 25. Because 25 times 20 mSec works out to be 500 mSec. That's how I do it versus allowing the itimer to give me a single event. It might be more helpful for you to not edit your posts. Because you asked an initial question, you've worked through it, and then you edit your post and no one can tell if your first question is still a question. |
Quote:
this is where I got that code http://www.informit.com/articles/art...3618&seqNum=14 and yeah I was having a hard time figuring out how this thing worked, because the handler is not called in that body of code, at least I could not see it using the function call timer_handler(int varName); and probably still am because I have not yet played with it as of yet. As this is off the net example, It looked like it will suit my purposes,so why write another one?. When running it in a separate main where the body of the code was in main, and the time handler as posted in here - I put that in too, and not seeing it actually calling the function within the code confused me, but I added it to mine none the less in the same file that the set-timer is in then made a different function to be call within it, thinking maybe that is how this thing is working, still got nothing. the seconds I was using because that is what they are there for to, to use seconds instead of milliseconds - it doesn't have to be that precise. So i was just fiddling with it to see what the times do to get it down to seconds instead. the first one is to set it to wait time, and the second one is to set it to how long before repeating, that was my understanding of it. so 1 sec wait time, then whatever the user put it in the command line to set it to minutes, that has not been converted yet, but converting seconds is easier then milliseconds less zeros to count. so I was just using seconds for trial, sorry I was in a bit of a hurry posting this, the setting are just to see if i can get it to work, one second wait times any faster and imlib will not have time to load and display an image. Code:
still needs to be set to minutes (whattime * 60) but that can wait until I get it to work first. Code:
void timer_handler (int signum) Code:
timer_handler set_timer are in the same c file, cycle_images() is in the file where the list is called so it will not need a return value, though I may have to go back and double check that to be sure. after I post this I am going to go back and chew on what you posed some more. MOD: I know it has to be some little simple mistake, as I call cycle_images() from main too, just to see if it pulls a filename from that function to be passed to the loadimage function to set the image to the desktop, and it gets a filename, Code:
in main cycle images <-- printf just before the cycle_images function call thanks. |
Quote:
Quote:
Quote:
When running it in a separate main where the body of the code was in main, and the time handler as posted in here - I put that in too, and not seeing it actually calling the function within the code confused me, but I added it to mine none the less in the same file that the set-timer is in then made a different function to be call within it, thinking maybe that is how this thing is working, still got nothing. the seconds I was using because that is what they are there for to, to use seconds instead of milliseconds - it doesn't have to be that precise. As far as the rest of what you've discussed, and your concern about running the updates to the UI, how about you verify that the timing is correct, that the timeouts do occur and getting that part correct, before you worry about whether or not it is calling your update function. |
Quote:
Code:
#include <signal.h> Code:
//with ITIMER_REAL |
I use ITIMER_REAL and it works fine for me. However you go with what works and try to explain it by reading the man pages.
And actually here is the difference, which is something I already mentioned (courtesy setitimer(2)): Quote:
|
Quote:
GNU Basic Signal Handling https://www.gnu.org/software/libc/ma...-Handling.html just to complaine for a minute, Code:
This is the type of signal handler functions. Signal handlers take one integer argument specifying the signal number, Code:
void timer_handler (int signum) Code:
anyways I found a different way and it worked but it does not release the program in the terminal Code:
typedef void (*sighandler_t)(int); |
Context & Trivial example, via Inter-Dimensional Portal
From "Linux La-La Land" :-)
First, the Context, signal numbers and the types of events to which they correspond. On various Linux-en, Cygwin, and various other environments, it is possible to do this from the command line: Code:
this is a command prompt > kill -l Code:
/* Signals. */ Code:
/* setitimer_use.c */ Code:
this is a command prompt > setitimer_use 2 |
All times are GMT -5. The time now is 12:18 AM. |