Public Member Functions | Private Member Functions | Private Attributes | Friends

nitro::Timer Class Reference

#include <utilities/timer.h>

Collaboration diagram for nitro::Timer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Timer (void)
void SetTimeout (const std::size_t theTimeout)
void SetInstant (const bool theInstant)
void SetSingle (const bool theSingle)
void Run (void)
virtual void Action (void)
virtual ~Timer ()

Private Member Functions

 Timer (const Timer &)
Timer operator= (const Timer &)

Private Attributes

std::size_t Timeout
bool Instant
bool Single
ThreadAbstraction TimerThread

Friends

void * _TimerWrapperFunction (void *)

Detailed Description

Definition at line 44 of file timer.h.


Constructor & Destructor Documentation

nitro::Timer::Timer ( void   ) 

Constructor.

Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 10 of file timer.cpp.

References Instant, Single, and Timeout.

        {
                Timeout = 1000;

                Instant = true;

                Single = false;
        }

nitro::Timer::~Timer (  )  [virtual]

Virtual destructor.

Author:
Dodonov A.A.

Definition at line 125 of file timer.cpp.

        {
                try
                {
                }
                catch( nitro::exception e )
                {
                }
                catch( ... )
                {
                }
        }

nitro::Timer::Timer ( const Timer  )  [inline, private]

Private copy-constructor.

Author:
Dodonov A.A.

Definition at line 227 of file timer.h.

{}


Member Function Documentation

void nitro::Timer::Action ( void   )  [virtual]

Function of the timer's action.

Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 110 of file timer.cpp.

References nitro::exception::code(), and nitro::exception::what().

Referenced by nitro::_TimerWrapperFunction().

        {
                try
                {
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Timer::Action( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Timer::Action( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

Timer nitro::Timer::operator= ( const Timer  )  [inline, private]

Private assign operator.

Author:
Dodonov A.A.

Definition at line 239 of file timer.h.

{return( *this );}

void nitro::Timer::Run ( void   ) 

Function starts timer.

Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 94 of file timer.cpp.

References _TimerWrapperFunction, nitro::exception::code(), nitro::ThreadAbstraction::CreateThread(), TimerThread, and nitro::exception::what().

        {
                try
                {
                        TimerThread.CreateThread( _TimerWrapperFunction , ( void * )( Timer * )this );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Timer::Run( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Timer::Run( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Timer::SetInstant ( const bool  theInstant  ) 

Function sets field Instant.

Parameters:
theInstant - flag of the instant action's execution.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 35 of file timer.cpp.

References nitro::exception::code(), Instant, and nitro::exception::what().

        {
                try
                {
                        Instant = theInstant;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Timer::SetInstant( const bool theInstant )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Timer::SetInstant( const bool theInstant )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Timer::SetSingle ( const bool  theSingle  ) 

Function sets field Instant.

Parameters:
theSingle - flag of the single action's execution.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 51 of file timer.cpp.

References nitro::exception::code(), Single, and nitro::exception::what().

        {
                try
                {
                        Single = theSingle;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Timer::SetSingle( const bool theSingle )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Timer::SetSingle( const bool theSingle )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Timer::SetTimeout ( const std::size_t  theTimeout  ) 

Function sets timeout.

Parameters:
theTimeout - Timeout.
Exceptions:
nitro::exception Throws an exception of that type with the error description.
Author:
Dodonov A.A.

Definition at line 19 of file timer.cpp.

References nitro::exception::code(), Timeout, and nitro::exception::what().

        {
                try
                {
                        Timeout = theTimeout;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Timer::SetTimeout( const std::size_t theTimeout )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Timer::SetTimeout( const std::size_t theTimeout )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


Friends And Related Function Documentation

void* _TimerWrapperFunction ( void *  Param  )  [friend]

Timer function for the thread.

Author:
Dodonov A.A.

Definition at line 67 of file timer.cpp.

Referenced by Run().

        {
                Timer *                                 TimerPtr( ( Timer * ) Param );

                if( TimerPtr->Instant )
                {
                        TimerPtr->Action();

                        if( TimerPtr->Single )
                        {
                                return( NULL );
                        }
                }

                for( ; true ; )
                {
                        ThreadAbstraction::Sleep( TimerPtr->Timeout );

                        TimerPtr->Action();

                        if( TimerPtr->Single )
                        {
                                return( NULL );
                        }
                }
        }


Member Data Documentation

bool nitro::Timer::Instant [private]

Instant execution of the action.

Author:
Dodonov A.A.

Definition at line 191 of file timer.h.

Referenced by nitro::_TimerWrapperFunction(), SetInstant(), and Timer().

bool nitro::Timer::Single [private]

Single execution of the action.

Author:
Dodonov A.A.

Definition at line 203 of file timer.h.

Referenced by nitro::_TimerWrapperFunction(), SetSingle(), and Timer().

std::size_t nitro::Timer::Timeout [private]

Timeout for action execution.

Author:
Dodonov A.A.

Definition at line 179 of file timer.h.

Referenced by nitro::_TimerWrapperFunction(), SetTimeout(), and Timer().

Timer's action will be executed in this thread .

Author:
Dodonov A.A.

Definition at line 215 of file timer.h.

Referenced by Run().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1