473,657 Members | 2,686 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_cbfun c(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 1418
"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
6267
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 following... ============ #include <boost/random/linear_congruential.hpp> #include <boost/random/uniform_real.hpp> #include <boost/random/variate_generator.hpp>
0
1180
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 called System. All of our classes are declared in our own namespace X. We are getting an error message along the lines of: Error C2027: use of undefined type 'X::System'. SuppressFinalize
4
1658
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 : 'Button1_click... Dim dllMail as Object Set dllMail = CreateObject("MyDll.SendMail") With dllMail
4
1618
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 person from associated number. The associated number is used as a que position reference (i.e. the person next has the lowest number.) Here is an example: -
4
2799
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
1281
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 values can be stored as the application runs, but I am unsure where to declare an object belonging to this class. Should it be in the program class as a static member and do I then pass it to my Forms constructor? Thanks for your help,
0
1656
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 noticed a certain "drop in framerate" to appear at regular intervals without any apparent reason. Here's the code I'm using: class BasicTimer
12
2686
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" << i << endl;
3
1599
by: mcco | last post by:
I have the next piece of code: vector<ChatSession> ssid; void SessionCreator( void *ch ) { vector<string> users; ...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.