Cleaned up stylistic nits and common branch naming issues on the new uiTimer() code. Also switched the Windows code to use a simple struct instead of the class (and with a uipriv name).
This commit is contained in:
parent
85a4c6d35d
commit
cac4cd9e81
|
@ -247,13 +247,13 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
|||
int (*f)(void *data);
|
||||
void *data;
|
||||
}
|
||||
- (id)initWithCallback:(int (*)(void *))callback data:(void*)callbackData;
|
||||
- (id)initWithCallback:(int (*)(void *))callback data:(void *)callbackData;
|
||||
- (void)doTimer:(NSTimer *)timer;
|
||||
@end
|
||||
|
||||
@implementation uiprivTimerDelegate
|
||||
|
||||
- (id)initWithCallback:(int (*)(void *))callback data:(void*)callbackData
|
||||
- (id)initWithCallback:(int (*)(void *))callback data:(void *)callbackData
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
@ -265,7 +265,7 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
|||
|
||||
- (void)doTimer:(NSTimer *)timer
|
||||
{
|
||||
if (!self->f(self->data))
|
||||
if (!(*(self->f))(self->data))
|
||||
[timer invalidate];
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ void uiTimer(int milliseconds, int (*f)(void *data), void *data)
|
|||
uiprivTimerDelegate *delegate;
|
||||
|
||||
delegate = [[uiprivTimerDelegate alloc] initWithCallback:f data:data];
|
||||
[NSTimer scheduledTimerWithTimeInterval:milliseconds / 1000.0
|
||||
[NSTimer scheduledTimerWithTimeInterval:(milliseconds / 1000.0)
|
||||
target:delegate
|
||||
selector:@selector(doTimer:)
|
||||
userInfo:nil
|
||||
|
|
13
unix/main.c
13
unix/main.c
|
@ -112,24 +112,23 @@ struct timer {
|
|||
void *data;
|
||||
};
|
||||
|
||||
static gboolean dotimer(gpointer data)
|
||||
static gboolean doTimer(gpointer data)
|
||||
{
|
||||
struct timer *t = (struct timer *) data;
|
||||
|
||||
if((*(t->f))(t->data))
|
||||
return TRUE;
|
||||
else {
|
||||
uiFree(t);
|
||||
if (!(*(t->f))(t->data)) {
|
||||
uiprivFree(t);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void uiTimer(int milliseconds, int (*f)(void *data), void *data)
|
||||
{
|
||||
struct timer *t;
|
||||
|
||||
t = uiNew(struct timer);
|
||||
t = uiprivNew(struct timer);
|
||||
t->f = f;
|
||||
t->data = data;
|
||||
g_timeout_add(milliseconds, dotimer, t);
|
||||
g_timeout_add(milliseconds, doTimer, t);
|
||||
}
|
||||
|
|
|
@ -131,9 +131,11 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
|||
|
||||
void uiTimer(int milliseconds, int (*f)(void *data), void *data)
|
||||
{
|
||||
UINT_PTR timer;
|
||||
|
||||
timer = (UINT_PTR) new TimerHandler(f, data);
|
||||
if (SetTimer(utilWindow, timer, milliseconds, NULL) == 0)
|
||||
logLastError(L"SetTimer()");
|
||||
uiprivTimer *timer;
|
||||
|
||||
timer = uiprivNew(uiprivTimer);
|
||||
timer->f = f;
|
||||
timer->data = data;
|
||||
if (SetTimer(utilWindow, (UINT_PTR) timer, milliseconds, NULL) == 0)
|
||||
logLastError(L"error calling SetTimer() in uiTimer()");
|
||||
}
|
||||
|
|
|
@ -95,20 +95,9 @@ extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor);
|
|||
extern void uninitUtilWindow(void);
|
||||
|
||||
// main.cpp
|
||||
struct TimerHandler {
|
||||
public:
|
||||
TimerHandler() : TimerHandler(NULL, NULL) {}
|
||||
TimerHandler(int(*f)(void *data), void *data)
|
||||
{
|
||||
this->f = f;
|
||||
this->data = data;
|
||||
}
|
||||
int operator()()
|
||||
{
|
||||
return this->f(this->data);
|
||||
}
|
||||
private:
|
||||
int(*f)(void *data);
|
||||
typedef struct uiprivTimer;
|
||||
struct uiprivTimer {
|
||||
void (*f)(void *);
|
||||
void *data;
|
||||
};
|
||||
extern int registerMessageFilter(void);
|
||||
|
|
|
@ -18,7 +18,7 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
|||
{
|
||||
void (*qf)(void *);
|
||||
LRESULT lResult;
|
||||
TimerHandler *timer;
|
||||
uiprivTimer *timer;
|
||||
|
||||
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
||||
return lResult;
|
||||
|
@ -38,11 +38,11 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
|||
(*qf)((void *) lParam);
|
||||
return 0;
|
||||
case WM_TIMER:
|
||||
timer = (TimerHandler *) wParam;
|
||||
if (!(*timer)()) {
|
||||
if (!KillTimer(utilWindow, (UINT_PTR) timer))
|
||||
logLastError(L"KillTimer()");
|
||||
delete timer;
|
||||
timer = (uiprivTimer *) wParam;
|
||||
if (!(*(timer->f))(timer->data)) {
|
||||
if (KillTimer(utilWindow, (UINT_PTR) timer) == 0)
|
||||
logLastError(L"error calling KillTimer() to end uiTimer() procedure");
|
||||
uiprivFree(timer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue