473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Help on writing a timer class (cross platform thread spawing)

Hi,

I am writing a timer class that I want to be able to get to notify me
(via a callback func), when a specified interval has elapsed. I have
most of the timer functionality figured - however, I need to spawn a new
thread to carry out the "time watch" - and I need to do this in a cross
platform (Well Linux/Windows) way ...

Any help will be mucho appreciated. The code (snippet) follows below:
#include <time.h>

typedef void (*TIMER_CB_FUNC)( void ) ;

class Timer {
public:
Timer() ;
virtual ~Timer() ; //not really required
registerCallBack( TIMER_CB_FUNC, unsigned int ) ;

private
TIMER_CB_FUNC m_cbfunc ;
void restart( void );
unsigned int m_interval ;
time_t m_stime ;
};
Jul 23 '05 #1
1 2080


Alfonso Morra wrote:
Hi,

I am writing a timer class that I want to be able to get to notify me
(via a callback func), when a specified interval has elapsed. I have
most of the timer functionality figured - however, I need to spawn a new
thread to carry out the "time watch" - and I need to do this in a cross
platform (Well Linux/Windows) way ...

Any help will be mucho appreciated. The code (snippet) follows below:
#include <time.h>

typedef void (*TIMER_CB_FUNC)( void ) ;

class Timer {
public:
Timer() ;
virtual ~Timer() ; //not really required
registerCallBack( TIMER_CB_FUNC, unsigned int ) ;

private Typo Alert: this needs to be "private:" TIMER_CB_FUNC m_cbfunc ;
void restart( void );
unsigned int m_interval ;
time_t m_stime ;
};


Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Derek Fountain | last post by:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run this bit of code" sort of thing?
1
by: John | last post by:
I'm trying to write a program that's run on both Windows 98 and Linux. I need a timer, that I can start and when it hits a limit, it needs to call a callback function. I also need to be able to...
10
by: Robert | last post by:
Where can i find a free web- based VC++ course? (also i've to dowanload it) I'm interested also in VB and C++ thanks, Robert
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
2
by: Alfonso Morra | last post by:
Hi, I am writing a timer class that I want to be able to get to notify me (via a callback func), when a specified interval has elapsed. I have most of the timer functionality figured - however,...
7
by: Smokey Grindle | last post by:
I have my entire program in a Sub Main class and it runs as a notify tray icon 99% of the time... inside the program there is a timer whihc is declared like this Dim WithEvents MyTimer As New...
3
by: Beemer Biker | last post by:
Unaccountably, I cannot re-enable a timer from an background thread. The disable works fine, I just cannot get it to start back up. There is no method "InvokeRequired" like there is for...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.