summaryrefslogtreecommitdiff
path: root/support/dktools/DkClockData.cpp
blob: e9c407dd420c93ec8ba5b55375db289a27e13686 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: DkClockData.cpt
*/

/**	@file DkClockData.cpp The DkClockData module.
*/


#line 85 "DkClockData.cpt"

#include "wxdkclock.h"




#line 90 "DkClockData.cpt"


DkClockData::DkClockData()
{
  

#line 95 "DkClockData.cpt"
  clvd.h = 0;
  clvd.m = 0;
  clvd.s = 0;
  clvd.a = 0;
  iAlertHour = 0;
  iAlertMinute = 0;
  iAlertEnabled = 0;
  iAlertState = 0;
  tmCurrent.Y = 0;
  tmCurrent.M = 0;
  tmCurrent.D = 0;
  tmCurrent.h = 0;
  tmCurrent.m = 0;
  tmCurrent.s = 0;
  

#line 110 "DkClockData.cpt"
}



void
DkClockData::getData(clockview_data_t *dptr)
{
  

#line 118 "DkClockData.cpt"
  if(dptr) {
    wxMutexLocker	lock(mxProtectData);
    dk3mem_cpy((void *)dptr, (void *)(&clvd), sizeof(clockview_data_t));
  }
  

#line 123 "DkClockData.cpt"
}



int
DkClockData::setTime(dk3_time_t *ct)
{
  dk3_tm_t	lct;
  int		back		= 0;
  

#line 133 "DkClockData.cpt"
  if(dk3sf_localtime_app(&lct, ct, NULL)) {
    wxMutexLocker		lock(mxProtectData);
    /*
    	Check date change.
    */
    if(2 == iAlertState) {
      if(lct.Y != tmCurrent.Y) {
        iAlertState = 0;
      } else {
        if(lct.M != tmCurrent.M) {
	  iAlertState = 0;
	} else {
	  if(lct.D != tmCurrent.D) {
	    iAlertState = 0;
	  }
	}
      }
    }
    /*
    	Check alert state change.
    */
    if((0 != iAlertEnabled) && (0 == iAlertState)) {
      if(lct.h > iAlertHour) {
        iAlertState = 1; back = 1;
      } else {
        if(lct.h == iAlertHour) {
	  if(lct.m >= iAlertMinute) {
	    iAlertState = 1; back = 1;
	  }
	}
      }
    }
    /*
    	Copy current time.
    */
    dk3mem_cpy((void *)(&tmCurrent), (void *)(&lct), sizeof(dk3_tm_t));
    /*
    	Copy to output structure.
    */
    clvd.h = lct.h;
    clvd.m = lct.m;
    clvd.s = lct.s;
    clvd.a = ((1 == iAlertState) ? 1 : 0);
  } 

#line 177 "DkClockData.cpt"
  return back;
}



void
DkClockData::setAlert(bool flag, int hour, int min)
{
  

#line 186 "DkClockData.cpt"
  iAlertState = 0;
  {
    wxMutexLocker         lock(mxProtectData);
    if(flag) {				

#line 190 "DkClockData.cpt"
      if((0 <= hour) && (23 >= hour) && (0 <= min) && (59 >= min)) {
        iAlertEnabled = 1;		

#line 192 "DkClockData.cpt"
        iAlertHour = hour;
        iAlertMinute = min;
        if(tmCurrent.h > hour) {
          iAlertState = 2;
        } else {
          if(tmCurrent.h == hour) {
	    if(tmCurrent.m >= min) {
	      iAlertState = 2;
	    }
	  }
        }
      } else {				

#line 204 "DkClockData.cpt"
        iAlertEnabled = 0;
        iAlertHour = 0;
        iAlertMinute = 0;
      }
    } else {				

#line 209 "DkClockData.cpt"
      iAlertEnabled = 0;
      iAlertHour = 0;
      iAlertMinute = 0;
    }
  } 

#line 214 "DkClockData.cpt"
}



void
DkClockData::endAlert(void)
{
  

#line 222 "DkClockData.cpt"
  {
    wxMutexLocker		lock(mxProtectData);
    if(1 == iAlertState) {
      iAlertState = 2;
    }
  }

#line 228 "DkClockData.cpt"
}



void
DkClockData::getAlertData(int *en, int *h, int *m)
{
  

#line 236 "DkClockData.cpt"
  if((en) && (h) && (m)) {
    wxMutexLocker		lock(mxProtectData);
    *en = iAlertEnabled;	

#line 239 "DkClockData.cpt"
    *h  = iAlertHour;		

#line 240 "DkClockData.cpt"
    *m  = iAlertMinute;		

#line 241 "DkClockData.cpt"
  } 

#line 242 "DkClockData.cpt"
}