summaryrefslogtreecommitdiff
path: root/src/time/timr.h
blob: 80fa2ebb6efae4f6291e674dd15d01496efe00b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*:*
 *: File: ./src/time/timr.h
 *: 
 *: 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.
 *:*/

#include "../incl.h"

#ifndef TIMR_H
#define TIMR_H

#include "../thrd/thro.h"

#include <unistd.h>

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;

public:
  timr();
  ~timr();

  bool get_timer_active() const;
  void start( void *v_ptr );

#ifdef NCURSES

  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 );
};

#endif