File: vtimer.cxx

package info (click to toggle)
v1 1.17-4
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,812 kB
  • ctags: 6,780
  • sloc: cpp: 43,604; ansic: 5,003; makefile: 955; sh: 30
file content (103 lines) | stat: -rw-r--r-- 2,568 bytes parent folder | download | duplicates (3)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//===============================================================
// vTimer.cxx - vTimer class functions - X11R5
//
// Copyright (C) 1995,1996  Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================

#include <v/vapp.h>
#include <v/vtimer.h>

// Define static data of the class


//======================>>> vTimer::vTimer <<<=======================
  vTimer::vTimer( )		// default constructor
  {
    SysDebug(Constructor,"vTimer::vTimer - constructor\n")

    _id = 0;			// no id
    _interval = 0;		// no interval
  }

//======================>>> vTimer::~vTimer <<<=======================
  vTimer::~vTimer( )
  {
    SysDebug(Destructor,"vTimer::~vTimer - destructor\n")

    if (_id)			// remove timer if in effect
      {
	XtRemoveTimeOut(_id);
	_id = 0;
      }
  }

//======================>>> vTimer::TimerSet <<<=======================
  int vTimer::TimerSet(long interval)
  {

    if (_id)			// remove timer if in effect
      {
	XtRemoveTimeOut(_id);
	_id = 0;
      }

    _interval = interval;

    _id = XtAppAddTimeOut(
	theApp->appContext(),	// needs app context
	_interval,		// interval in ms
	CtimerCB,		// the callback
	(XtPointer)this);	// us

    return (_id == 0) ? 0 : 1;
  }

//======================>>> vTimer::TimerStop <<<=======================
  void vTimer::TimerStop(void)
  {
    if (_id)			// remove timer if in effect
      {
	XtRemoveTimeOut(_id);
	_id = 0;
      }
  }

//======================>>> vTimer::TimerTick <<<=======================
  void vTimer::TimerTick(void)
  {
    // default has no action - will be overridden
  }

//=========================>>> vTimer::tick <<<=======================
  void vTimer::tick(void)
  {
    // internal tick routine

    TimerTick();		// call the work routine

    // X requires you to reinstall timer to get another tick
    _id = XtAppAddTimeOut(
	theApp->appContext(),	// needs app context
	_interval,		// interval in ms
	CtimerCB,		// the callback
	(XtPointer)this);	// us

  }

extern "C"
{
//============================>>> CtimerCB <<<==========================
  void CtimerCB(XtPointer client_data, XtIntervalId* notUsed)
  { 
    //	timer tick callback
    //
    // client_data will have the this pointer of our object

    ((vTimer*)client_data)->tick();	// call our tick routine
  }
}