summaryrefslogtreecommitdiff
path: root/src/time/timr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/time/timr.cpp')
-rwxr-xr-x[-rw-r--r--]src/time/timr.cpp193
1 files changed, 95 insertions, 98 deletions
diff --git a/src/time/timr.cpp b/src/time/timr.cpp
index 65ba780..40240c3 100644..100755
--- a/src/time/timr.cpp
+++ b/src/time/timr.cpp
@@ -1,27 +1,3 @@
-/*:*
- *: File: ./src/time/timr.cpp
- *:
- *: yChat; Homepage: www.yChat.org; Version 0.8.3-CURRENT
- *:
- *: Copyright (C) 2003 Paul C. Buetow, Volker Richter
- *: Copyright (C) 2004 Paul C. Buetow
- *: Copyright (C) 2005 EXA Digital Solutions GbR
- *:
- *: This program is free software; you can redistribute it and/or
- *: modify it under the terms of the GNU General Public License
- *: as published by the Free Software Foundation; either version 2
- *: of the License, or (at your option) any later version.
- *:
- *: This program is distributed in the hope that it will be useful,
- *: but WITHOUT ANY WARRANTY; without even the implied warranty of
- *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *: GNU General Public License for more details.
- *:
- *: You should have received a copy of the GNU General Public License
- *: along with this program; if not, write to the Free Software
- *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *:*/
-
#ifndef TIMR_CPP
#define TIMR_CPP
@@ -39,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";
@@ -56,47 +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 );
- time_t clock_start;
- time_t clock_now;
+#ifdef NCURSES
+ print_time( );
+#endif
- time( &clock_start );
- tm time_start = *localtime( &clock_start );
- tm time_now;
+ time_t clock_start;
+ time_t clock_now;
- while ( get_timer_active() )
- {
- // sleep a second!
- usleep( 1000000 );
+ time( &clock_start );
+ tm time_start = *localtime( &clock_start );
+ tm time_now;
- // get the current time!
- time( &clock_now );
+ while ( get_timer_active() )
+ {
+ // sleep a second!
+ usleep( 1000000 );
- time_now = *localtime( &clock_now );
+ // get the current time!
+ time( &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 );
+ time_now = *localtime( &clock_now );
- // run every minute:
- if ( time_now.tm_sec == 0 )
- {
+ // 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())
+ print_time( );
+#endif
+
+ // run every minute:
+ if ( time_now.tm_sec == 0 )
+ {
#ifdef SERVMSG
cout << TIMERUP << get_uptime() << endl;
#endif
@@ -108,87 +93,99 @@ 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 )
{
-
- wrap::SOCK->clean_ipcache();
- // 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();
- }
+ wrap::GCOL->remove_garbage(); //<<
+
+ // run every hour
+ if ( time_now.tm_hour % 60 == 0 )
+ {
+ // 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::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours )
+timr::print_time( )
{
+ if ( !wrap::NCUR->is_ready() )
+ return;
- int i_hours = (int) d_uptime / 3600;
- int i_minutes = (int) d_uptime / 60;
+ 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
- while ( i_minutes >= 60 )
- i_minutes -= 60;
+void
+timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours )
+{
- while ( d_uptime >= 60 )
- d_uptime -= 60;
+ int i_hours = (int) d_uptime / 3600;
+ int i_minutes = (int) d_uptime / 60;
- // Calculate offset time
- i_cur_hours += get_offset();
+ while ( i_minutes >= 60 )
+ i_minutes -= 60;
- for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours )
- i_cur_hours =- i;
+ while ( d_uptime >= 60 )
+ d_uptime -= 60;
- if (i_cur_hours == 24)
- i_cur_hours = 0;
+ // Calculate offset time
+ i_cur_hours += get_offset();
- 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 );
+ for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours )
+ i_cur_hours =- i;
- 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 );
+ 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 );
}
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