summaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
Diffstat (limited to 'src/time')
-rw-r--r--src/time/CVS/Entries8
-rwxr-xr-xsrc/time/timo.cpp20
-rwxr-xr-xsrc/time/timo.h12
-rwxr-xr-xsrc/time/timr.cpp164
-rwxr-xr-xsrc/time/timr.h81
5 files changed, 141 insertions, 144 deletions
diff --git a/src/time/CVS/Entries b/src/time/CVS/Entries
index bcedcb0..1320336 100644
--- a/src/time/CVS/Entries
+++ b/src/time/CVS/Entries
@@ -1,5 +1,5 @@
-/timo.cpp/1.5/Mon Feb 21 01:55:50 2005//
-/timo.h/1.4/Mon Feb 21 01:55:50 2005//
-/timr.cpp/1.13/Mon Feb 21 01:55:50 2005//
-/timr.h/1.5/Mon Feb 21 01:55:50 2005//
+/timo.cpp/1.4/Fri Jan 7 21:00:19 2005//
+/timo.h/1.3/Thu Nov 18 13:41:47 2004//
+/timr.cpp/1.11/Mon Feb 14 17:33:09 2005//
+/timr.h/1.4/Fri Jan 7 21:00:19 2005//
D
diff --git a/src/time/timo.cpp b/src/time/timo.cpp
index fd89bdf..d00bafe 100755
--- a/src/time/timo.cpp
+++ b/src/time/timo.cpp
@@ -7,32 +7,32 @@ using namespace std;
timo::timo()
{
- pthread_mutex_init( &mut_t_time, NULL );
+ pthread_mutex_init( &mut_t_time, NULL );
}
timo::~timo()
{
- pthread_mutex_destroy( &mut_t_time );
+ pthread_mutex_destroy( &mut_t_time );
}
double
timo::get_last_activity( )
{
- double d_ret;
+ double d_ret;
- pthread_mutex_lock ( &mut_t_time );
- d_ret = wrap::TIMR->get_time_diff( t_time );
- pthread_mutex_unlock( &mut_t_time );
+ pthread_mutex_lock ( &mut_t_time );
+ d_ret = wrap::TIMR->get_time_diff( t_time );
+ pthread_mutex_unlock( &mut_t_time );
- return d_ret;
+ return d_ret;
}
void
timo::renew_timeout( )
{
- pthread_mutex_lock ( &mut_t_time );
- time( &t_time );
- pthread_mutex_unlock( &mut_t_time );
+ pthread_mutex_lock ( &mut_t_time );
+ time( &t_time );
+ pthread_mutex_unlock( &mut_t_time );
}
#endif
diff --git a/src/time/timo.h b/src/time/timo.h
index 32268df..4eaecf8 100755
--- a/src/time/timo.h
+++ b/src/time/timo.h
@@ -8,15 +8,15 @@ using namespace std;
class timo // timeout class
{
protected:
- time_t t_time; // last activity time.
- pthread_mutex_t mut_t_time;
+ time_t t_time; // last activity time.
+ pthread_mutex_t mut_t_time;
public:
- timo( );
- ~timo( );
+ timo( );
+ ~timo( );
- double get_last_activity();
- void renew_timeout();
+ double get_last_activity();
+ void renew_timeout();
};
#endif
diff --git a/src/time/timr.cpp b/src/time/timr.cpp
index d2251d0..12b5972 100755
--- a/src/time/timr.cpp
+++ b/src/time/timr.cpp
@@ -15,7 +15,7 @@ timr::timr()
pthread_mutex_init( &mut_s_uptime, NULL);
pthread_mutex_init( &mut_i_offset, NULL);
- i_time_offset = tool::string2int( wrap::CONF->get_elem("chat.timeoffset") );
+ i_time_offset = tool::string2int( wrap::CONF->get_elem("chat.timeoffset") );
wrap::system_message( TIMEROF + tool::int2string( i_time_offset ) );
s_time = "00:00:00";
@@ -32,58 +32,56 @@ timr::~timr()
bool
timr::get_timer_active() const
{
- return b_timer_active;
+ return b_timer_active;
}
int
-timr::get_offset()
+timr::get_offset()
{
- pthread_mutex_lock ( &mut_i_offset );
- int i_ret_val = i_time_offset;
- pthread_mutex_unlock( &mut_i_offset );
- return i_ret_val;
+ pthread_mutex_lock ( &mut_i_offset );
+ int i_ret_val = i_time_offset;
+ pthread_mutex_unlock( &mut_i_offset );
+ return i_ret_val;
}
void
timr::start( void *v_ptr )
{
- wrap::system_message( TIMERTH );
+ wrap::system_message( TIMERTH );
#ifdef NCURSES
-
- print_time( );
+ print_time( );
#endif
- time_t clock_start;
- time_t clock_now;
+ time_t clock_start;
+ time_t clock_now;
- time( &clock_start );
- tm time_start = *localtime( &clock_start );
- tm time_now;
+ time( &clock_start );
+ tm time_start = *localtime( &clock_start );
+ tm time_now;
- while ( get_timer_active() )
- {
- // sleep a second!
- usleep( 1000000 );
+ while ( get_timer_active() )
+ {
+ // sleep a second!
+ usleep( 1000000 );
- // get the current time!
- time( &clock_now );
+ // get the current time!
+ time( &clock_now );
- time_now = *localtime( &clock_now );
+ time_now = *localtime( &clock_now );
- // set the current time && the current ychat uptime!
- set_time( difftime( clock_now, clock_start ),
- time_now.tm_sec, time_now.tm_min, time_now.tm_hour );
+ // set the current time && the current ychat uptime!
+ set_time( difftime( clock_now, clock_start ),
+ time_now.tm_sec, time_now.tm_min, time_now.tm_hour );
#ifdef NCURSES
-
- if (wrap::NCUR->is_ready())
+ if (wrap::NCUR->is_ready())
print_time( );
-#endif
+#endif
- // run every minute:
- if ( time_now.tm_sec == 0 )
- {
+ // run every minute:
+ if ( time_now.tm_sec == 0 )
+ {
#ifdef SERVMSG
cout << TIMERUP << get_uptime() << endl;
#endif
@@ -95,43 +93,43 @@ timr::start( void *v_ptr )
wrap::CHAT->check_timeout( p_timeout_settings );
delete p_timeout_settings;
- string s_ping = "<!-- PING! //-->\n";
+ string s_ping = "<!-- PING! //-->\n";
wrap::CHAT->msg_post( &s_ping );
#ifdef DATABASE
// Disconnecting idle database conenction
wrap::DATA->check_data_con_timeout();
#endif
- //*>>
-
- // Run every ten minutes:
+ //*>>
+
+ // run every ten minutes:
if ( time_now.tm_min % 10 == 0 )
{
- // Run every hour
- if ( time_now.tm_min % 60 == 0 )
- {
- wrap::GCOL->remove_garbage(); //<<
-
- // Run every day
- if (time_now.tm_min == 0 || time_now.tm_min == 60 )
- if (time_now.tm_hour == 0 || time_now.tm_hour == 24)
- wrap::STAT->update_rusage_history();
- }
+ // run every hour
+ if ( time_now.tm_hour % 60 == 0 )
+ {
+ wrap::GCOL->remove_garbage(); //<<
+
+ // run every day
+ if (time_now.tm_min == 0 || time_now.tm_min == 60 )
+ if (time_now.tm_hour == 0 || time_now.tm_hour == 24)
+ wrap::STAT->update_rusage_history();
+ }
}
+ }
}
- }
}
#ifdef NCURSES
void
timr::print_time( )
{
- if ( !wrap::NCUR->is_ready() )
- return;
+ if ( !wrap::NCUR->is_ready() )
+ return;
- mvprintw( NCUR_TIME_X, NCUR_TIME_Y, "Time: %s ", get_time().c_str());
- mvprintw( NCUR_UPTIME_X, NCUR_UPTIME_Y, "Uptime: %s ", get_uptime().c_str());
- refresh();
+ mvprintw( NCUR_TIME_X, NCUR_TIME_Y, "Time: %s ", get_time().c_str());
+ mvprintw( NCUR_UPTIME_X, NCUR_UPTIME_Y, "Uptime: %s ", get_uptime().c_str());
+ refresh();
}
#endif
@@ -139,55 +137,55 @@ void
timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours )
{
- int i_hours = (int) d_uptime / 3600;
- int i_minutes = (int) d_uptime / 60;
-
- while ( i_minutes >= 60 )
- i_minutes -= 60;
+ int i_hours = (int) d_uptime / 3600;
+ int i_minutes = (int) d_uptime / 60;
- while ( d_uptime >= 60 )
- d_uptime -= 60;
+ while ( i_minutes >= 60 )
+ i_minutes -= 60;
- // Calculate offset time
- i_cur_hours += get_offset();
+ while ( d_uptime >= 60 )
+ d_uptime -= 60;
- for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours )
- i_cur_hours =- i;
+ // Calculate offset time
+ i_cur_hours += get_offset();
- if (i_cur_hours == 24)
- i_cur_hours = 0;
+ for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours )
+ i_cur_hours =- i;
- pthread_mutex_lock ( &mut_s_time );
- s_time = add_zero_to_front( tool::int2string( i_cur_hours ) ) + ":" +
- add_zero_to_front( tool::int2string( i_cur_minutes ) ) + ":" +
- add_zero_to_front( tool::int2string( i_cur_seconds ) );
- pthread_mutex_unlock( &mut_s_time );
+ if (i_cur_hours == 24)
+ i_cur_hours = 0;
+
+ pthread_mutex_lock ( &mut_s_time );
+ s_time = add_zero_to_front( tool::int2string( i_cur_hours ) ) + ":" +
+ add_zero_to_front( tool::int2string( i_cur_minutes ) ) + ":" +
+ add_zero_to_front( tool::int2string( i_cur_seconds ) );
+ pthread_mutex_unlock( &mut_s_time );
- pthread_mutex_lock ( &mut_s_uptime );
- s_uptime = add_zero_to_front( tool::int2string( i_hours ) ) + ":" +
- add_zero_to_front( tool::int2string( i_minutes ) ) + ":" +
- add_zero_to_front( tool::int2string( (int) d_uptime ) );
- pthread_mutex_unlock( &mut_s_uptime );
+ pthread_mutex_lock ( &mut_s_uptime );
+ s_uptime = add_zero_to_front( tool::int2string( i_hours ) ) + ":" +
+ add_zero_to_front( tool::int2string( i_minutes ) ) + ":" +
+ add_zero_to_front( tool::int2string( (int) d_uptime ) );
+ pthread_mutex_unlock( &mut_s_uptime );
}
string
timr::add_zero_to_front( string s_time )
{
- if ( s_time.length() == 1 )
- {
- string s_new = "0" + s_time;
- return s_new;
- }
+ if ( s_time.length() == 1 )
+ {
+ string s_new = "0" + s_time;
+ return s_new;
+ }
- return s_time;
+ return s_time;
}
double
timr::get_time_diff( time_t &clock_diff )
{
- time_t clock_now;
- time( &clock_now );
+ time_t clock_now;
+ time( &clock_now );
- return difftime(clock_now, clock_diff);
+ return difftime(clock_now, clock_diff);
}
#endif
diff --git a/src/time/timr.h b/src/time/timr.h
index 12cdd8f..46234b3 100755
--- a/src/time/timr.h
+++ b/src/time/timr.h
@@ -12,53 +12,52 @@ using namespace std;
class timr : public thro
{
private:
- bool b_timer_active;
- int i_time_offset;
- string s_uptime;
- string s_time;
-
- pthread_mutex_t mut_s_time;
- pthread_mutex_t mut_s_uptime;
- pthread_mutex_t mut_i_offset;
-
+ bool b_timer_active;
+ int i_time_offset;
+ string s_uptime;
+ string s_time;
+
+ pthread_mutex_t mut_s_time;
+ pthread_mutex_t mut_s_uptime;
+ pthread_mutex_t mut_i_offset;
+
public:
- timr();
- ~timr();
+ timr();
+ ~timr();
- bool get_timer_active() const;
- void start( void *v_ptr );
+ bool get_timer_active() const;
+ void start( void *v_ptr );
#ifdef NCURSES
-
- void print_time();
+ void print_time();
#endif
- void set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours );
- string add_zero_to_front( string s_time );
-
- // inline for dynamic module access!
- string
- get_time( )
- {
- string s_ret;
- pthread_mutex_lock ( &mut_s_time );
- s_ret = this->s_time;
- pthread_mutex_unlock( &mut_s_time );
- return s_ret;
- }
-
- string
- get_uptime( )
- {
- string s_ret;
- pthread_mutex_lock ( &mut_s_uptime );
- s_ret = this->s_uptime;
- pthread_mutex_unlock( &mut_s_uptime );
- return s_ret;
- }
-
- int get_offset();
- double get_time_diff( time_t &clock_diff );
+ void set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours );
+ string add_zero_to_front( string s_time );
+
+ // inline for dynamic module access!
+ string
+ get_time( )
+ {
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_time );
+ s_ret = this->s_time;
+ pthread_mutex_unlock( &mut_s_time );
+ return s_ret;
+ }
+
+ string
+ get_uptime( )
+ {
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_uptime );
+ s_ret = this->s_uptime;
+ pthread_mutex_unlock( &mut_s_uptime );
+ return s_ret;
+ }
+
+ int get_offset();
+ double get_time_diff( time_t &clock_diff );
};
#endif