Skip to content

Commit ab22a4c

Browse files
committed
custom timer handler test
1 parent 7dde843 commit ab22a4c

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed

atp3/incl_timer_handler.cxx

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* --------------------------------------------------------------
2+
Project: ATP(A Tentative Plan) 3
3+
Purpose:
4+
Author: Ho-Jung Kim (godmode2k@hotmail.com)
5+
Date: Since Dec 2, 2014
6+
Filename: incl_timer_handler.cxx
7+
8+
Last modified: Jun 2, 2015
9+
License:
10+
11+
*
12+
* Copyright (C) 2014 Ho-Jung Kim (godmode2k@hotmail.com)
13+
*
14+
* Licensed under the Apache License, Version 2.0 (the "License");
15+
* you may not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing, software
21+
* distributed under the License is distributed on an "AS IS" BASIS,
22+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
* See the License for the specific language governing permissions and
24+
* limitations under the License.
25+
*
26+
-----------------------------------------------------------------
27+
Note:
28+
- DO NOT INCLUDE "incl_timer_handler.hxx" here
29+
-----------------------------------------------------------------
30+
1. Build:
31+
$ g++ ... -D__LINUX__ -D_REENTRANT -lpthread -lrt \
32+
`pkg-config --cflags --libs gtk+-2.0 libglade-2.0`
33+
or
34+
`pkg-config --cflags --libs gtk+-3.0 libglade-2.0`
35+
36+
TODO:
37+
-
38+
-------------------------------------------------------------- */
39+
40+
41+
42+
//! Header
43+
// ---------------------------------------------------------------
44+
// ---------------------------------------------------------------
45+
46+
47+
48+
//! Definition
49+
// ---------------------------------------------------------------
50+
// ---------------------------------------------------------------
51+
52+
53+
54+
//! Prototype
55+
// ---------------------------------------------------------------
56+
// ---------------------------------------------------------------
57+
58+
59+
60+
//! Class
61+
// ---------------------------------------------------------------
62+
// ---------------------------------------------------------------
63+
64+
65+
66+
//! Implementation
67+
// ---------------------------------------------------------------
68+
69+
70+
// class Cxxx
71+
CTimerHandler::CTimerHandler(void) : TAG("CTimerHandler") {
72+
//__LOGT__( TAG, "CTimerHandler()" );
73+
}
74+
75+
CTimerHandler::~CTimerHandler(void) {
76+
//__LOGT__( TAG, "~CTimerHandler()" );
77+
}
78+
79+
void CTimerHandler::__init(void) {
80+
//__LOGT__( TAG, "__init()" );
81+
82+
//m_update = false;
83+
}
84+
85+
void CTimerHandler::__release(void) {
86+
//__LOGT__( TAG, "__release()" );
87+
}
88+
89+
void CTimerHandler::task_in_thread(void* user_data) {
90+
//__LOGT__( TAG, "task_in_thread()" );
91+
92+
93+
goto _RELEASE;
94+
95+
/*
96+
{
97+
CAtp3* main = NULL;
98+
CViewMain* view = NULL;
99+
100+
101+
main = (CAtp3*)user_data;
102+
if ( !main ) {
103+
__LOGT__( TAG, "task_in_thread(): Main object == NULL" );
104+
goto _RELEASE;
105+
}
106+
//__LOGT__( TAG, "task_in_thread(): Main object = %p, TAG = %s", main, main->get_tag() );
107+
108+
view = main->get_view_main();
109+
if ( !view ) {
110+
__LOGT__( TAG, "task_in_thread(): MainView object == NULL" );
111+
goto _RELEASE;
112+
}
113+
//__LOGT__( TAG, "task_in_thread(): MainView object = %p, TAG = %s", view, view->get_tag() );
114+
115+
116+
while ( 1 ) {
117+
//__LOGT__( TAG, "task_in_thread(): waiting..." );
118+
119+
// Interrupt
120+
if ( get_cancel_state() ) break;
121+
122+
123+
// Update
124+
if ( view->get_attach_animstask_update() ) {
125+
//__LOGT__( TAG, "task_in_thread(): redraw..." );
126+
//view->invalidate();
127+
128+
129+
Widgets_st* widget = main->get_widget_st();
130+
131+
if ( !widget ) {
132+
__LOGT__( TAG, "task_in_thread(): Widget object == NULL" );
133+
break;
134+
}
135+
if ( !widget->pDrawingArea ) {
136+
__LOGT__( TAG, "task_in_thread(): DrawingArea object == NULL" );
137+
break;
138+
}
139+
140+
if ( !GTK_IS_WIDGET(widget->pDrawingArea) )
141+
__LOGT__( TAG, "task_in_thread(): DrawingArea == widget [FALSE]" );
142+
143+
144+
print_datetime_d();
145+
gtk_widget_queue_draw( widget->pDrawingArea );
146+
}
147+
148+
149+
// Latency
150+
__usleep( TIMER_HANDLER_LATENCY );
151+
}
152+
}
153+
*/
154+
155+
156+
157+
_RELEASE:
158+
__usleep( TIMER_HANDLER_LATENCY_OUTER );
159+
stop();
160+
}
161+
// ---------------------------------------------------------------
162+

atp3/incl_timer_handler.hxx

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#ifndef __INCL_TIMER_HANDLER_HXX__
2+
#define __INCL_TIMER_HANDLER_HXX__
3+
4+
/* --------------------------------------------------------------
5+
Project: ATP(A Tentative Plan) 3
6+
Purpose:
7+
Author: Ho-Jung Kim (godmode2k@hotmail.com)
8+
Date: Since Dec 2, 2014
9+
Filename: incl_timer_handler.h
10+
11+
Last modified: Jun 2, 2015
12+
License:
13+
14+
*
15+
* Copyright (C) 2014 Ho-Jung Kim (godmode2k@hotmail.com)
16+
*
17+
* Licensed under the Apache License, Version 2.0 (the "License");
18+
* you may not use this file except in compliance with the License.
19+
* You may obtain a copy of the License at
20+
*
21+
* http://www.apache.org/licenses/LICENSE-2.0
22+
*
23+
* Unless required by applicable law or agreed to in writing, software
24+
* distributed under the License is distributed on an "AS IS" BASIS,
25+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
* See the License for the specific language governing permissions and
27+
* limitations under the License.
28+
*
29+
-----------------------------------------------------------------
30+
Note:
31+
-----------------------------------------------------------------
32+
1. Build:
33+
$ g++ ... -D__LINUX__ -D_REENTRANT -lpthread -lrt \
34+
`pkg-config --cflags --libs gtk+-2.0 libglade-2.0`
35+
or
36+
`pkg-config --cflags --libs gtk+-3.0 libglade-2.0`
37+
-------------------------------------------------------------- */
38+
39+
40+
41+
//! Header and Definition
42+
// ---------------------------------------------------------------
43+
#include "util/CTimerHandlerTask.h"
44+
// ---------------------------------------------------------------
45+
46+
47+
48+
//! Definition
49+
// ---------------------------------------------------------------
50+
// Latency
51+
#define TIMER_HANDLER_LATENCY_OUTER 10 // millisecond
52+
53+
#ifdef __cplusplus
54+
extern "C" {
55+
#endif
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
60+
// ---------------------------------------------------------------
61+
62+
63+
64+
//! Prototype
65+
// ---------------------------------------------------------------
66+
// ---------------------------------------------------------------
67+
68+
69+
70+
//! Class
71+
// ---------------------------------------------------------------
72+
// "incl_timer_handler.cxx"
73+
class CTimerHandler : virtual public CTimerHandlerTask {
74+
private:
75+
const char* TAG;
76+
77+
//bool m_update;
78+
protected:
79+
public:
80+
explicit CTimerHandler(void);
81+
~CTimerHandler();
82+
83+
void __init(void);
84+
void __release(void);
85+
86+
87+
// ---------------------------------------------------------------
88+
89+
//void set_update(bool val) { m_update = val; }
90+
//bool get_update(void) { return m_update; }
91+
92+
// thread
93+
void task_in_thread(void* user_data = NULL);
94+
};
95+
// ---------------------------------------------------------------
96+
97+
98+
99+
#endif // __INCL_TIMER_HANDLER_HXX__

0 commit comments

Comments
 (0)