473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with "rolling my own" Timer class

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 much appreciated. The code (snippet) follows below:

#include <ctime>

typedef void (*TIMER_CB_FUNC)( void ) ;

class Timer {
public:
inline Timer():m_cbfunc(0),m_interval(0),m_stime(0){} ;
Timer( TIMER_CB_FUNC, unsigned short) ;
Timer( const Timer&) ;
Timer& operator= (const Timer& ) ;
virtual ~Timer() ; //not really required

private:
TIMER_CB_FUNC m_cbfunc ;
unsigned short m_interval ;
time_t m_stime ;

/* private functions */
void reset( void );
};

Basically when the Timer class is constructed, it must start a new
thread that waits till the time is up and then notifies me. MTIA

Nov 17 '05 #1
2 1411
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
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 ...


I can't help you with the cross platform issues except to mention that there
are libraries that try to smooth over the platform differences like this one

http://www.cs.wustl.edu/~schmidt/ACE.html

and this one

http://www.roguewave.com/products/enterprise/

and this one

http://www.boost.org/doc/html/threads.html

On the Win32 side, it should be a no-brainer to wrap a class around the
multimedia function timeSetEvent() which dispatches callbacks at a future
time and which manages the lifetime of the thread on which the callbacks
occur.

Regards,
Will
Nov 17 '05 #2


William DePalo [MVP VC++] wrote:
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
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 ...

I can't help you with the cross platform issues except to mention that there
are libraries that try to smooth over the platform differences like this one

http://www.cs.wustl.edu/~schmidt/ACE.html

and this one

http://www.roguewave.com/products/enterprise/

and this one

http://www.boost.org/doc/html/threads.html

On the Win32 side, it should be a no-brainer to wrap a class around the
multimedia function timeSetEvent() which dispatches callbacks at a future
time and which manages the lifetime of the thread on which the callbacks
occur.

Regards,
Will


Thanks Will for the post. I think to keep things simple for now, I'll
just use conditional compilation and branch the logic accross the
platforms. Would you be so kind as to get me started with the
timeSetEvent() wrapper, I'm currently reading up on the function notes
and I'm sure I'll be able to follow up on an example that you provide.

MTIA

Nov 17 '05 #3

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

Similar topics

1
6251
by: John C | last post by:
Hi, I am trying to include the generation of random numbers in my c++ class. However I don't quite know how to incorporate it. To start with, I managed to get random numbers going via the...
0
1175
by: kevin_g_frey | last post by:
Hello We have an internal tool that generates a series of .NET class wrappers for accessing our database entities. One of our database entities is called "System" so our correspond __gc class is...
4
1647
by: Screaming Eagles 101 | last post by:
How can I make my own Mail control (unvisible one) to use with a form ? Does anyone know where to find code ? I would like to fill in some parameters, and then send a mail, a bit like this : ...
4
1608
by: Gary | last post by:
I'm a bit confused hopefuly someone can help. I have a text file which stores names and an associated number. Each line in the text file represents one person, and a semicolon ' ; ' seperates...
4
2792
by: David Ricketts | last post by:
I'm familiar with all the must own books for C++ developers, the Meyers, the Sutters, the Alexandrescus, etc. But what are the "must own" books for Java?
2
1269
by: bg_ie | last post by:
Hi, I wish to write a WindowsApplication which prompts the user to enter a set of values in text boxes. I then what to write these values to an xml file. I have created my own class where these...
0
1651
by: Andreas Schmitt | last post by:
I wrote a small timer class for use in a graphics engine I am working on for teaching myself. The small time based animations I tried with it seem to work fine but displaying the frame rate I...
12
2669
by: gato | last post by:
Hello Everybody, I want my own class to behave like the following oss object; ------------------------ code begin ----- int main () { int i = 67; ostringstream oss; oss << "A" <<...
3
1586
by: mcco | last post by:
I have the next piece of code: vector<ChatSession> ssid; void SessionCreator( void *ch ) { vector<string> users; ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
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
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5023
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...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.