dect
/
libdect
Archived
13
0
Fork 0

examples: don't use libevent functions directly exept in event_ops.c

Make all event handling go through event_ops.c.

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2010-07-24 03:48:18 +02:00
parent f9020e9086
commit 89bb432a5e
3 changed files with 23 additions and 25 deletions

View File

@ -3,7 +3,6 @@
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <event.h>
#include <dect/libdect.h>
#include <dect/terminal.h>
@ -13,7 +12,7 @@
struct call {
struct dect_keypad_buffer *keybuf;
struct dect_audio_handle *audio;
struct event event;
struct dect_timer *timer;
enum {
BLINK0,
RING,
@ -49,19 +48,18 @@ static const struct dect_ipui ipuis[] = {
},
};
static void dect_mncc_timer(int fd, short even, void *data);
static void dect_mncc_timer_schedule(struct dect_call *call)
static void dect_mncc_timer(struct dect_handle *dh, struct dect_timer *timer);
static void dect_mncc_timer_schedule(struct dect_handle *dh, struct dect_call *call)
{
struct call *priv = dect_call_priv(call);
struct timeval tv = { .tv_sec = 1 };
evtimer_set(&priv->event, dect_mncc_timer, call);
evtimer_add(&priv->event, &tv);
dect_setup_timer(priv->timer, dect_mncc_timer, call);
dect_start_timer(dh, priv->timer, 1);
}
static void dect_mncc_timer(int fd, short even, void *data)
static void dect_mncc_timer(struct dect_handle *dh, struct dect_timer *timer)
{
struct dect_call *call = data;
struct dect_call *call = timer->data;
struct dect_ie_display display;
struct dect_ie_signal signal;
struct dect_mncc_info_param info = {
@ -77,7 +75,7 @@ static void dect_mncc_timer(int fd, short even, void *data)
dect_display_append_char(&display, code++);
dect_mncc_info_req(dh, call, &info);
dect_mncc_timer_schedule(call);
dect_mncc_timer_schedule(dh, call);
}
static void dect_keypad_complete(struct dect_handle *dh, void *call,
@ -103,6 +101,7 @@ static void dect_mncc_setup_ind(struct dect_handle *dh, struct dect_call *call,
dect_ie_init(&signal);
signal.code = DECT_SIGNAL_DIAL_TONE_ON;
priv->timer = dect_alloc_timer(dh);
priv->keybuf = dect_keypad_buffer_init(dh, 3, dect_keypad_complete, call);
priv->audio = dect_audio_open();
@ -176,28 +175,28 @@ static void dect_mncc_send_call_info(struct dect_call *call)
dect_mncc_info_req(dh, call, &info);
}
static void dect_mncc_info_timer(int fd, short even, void *data);
static void dect_mncc_info_timer_schedule(struct dect_call *call)
static void dect_mncc_info_timer(struct dect_handle *dh, struct dect_timer *timer);
static void dect_mncc_info_timer_schedule(struct dect_handle *dh, struct dect_call *call)
{
struct call *priv = dect_call_priv(call);
struct timeval tv = { .tv_usec = 500000 };
evtimer_set(&priv->event, dect_mncc_info_timer, call);
evtimer_add(&priv->event, &tv);
dect_setup_timer(priv->timer, dect_mncc_info_timer, call);
dect_start_timer(dh, priv->timer, 1);
}
static void dect_mncc_info_timer(int fd, short even, void *data)
static void dect_mncc_info_timer(struct dect_handle *dh, struct dect_timer *timer)
{
struct dect_call *call = data;
struct dect_call *call = timer->data;
dect_mncc_send_call_info(call);
dect_mncc_info_timer_schedule(call);
dect_mncc_info_timer_schedule(dh, call);
}
static void dect_mncc_alert_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_alert_param *param)
{
dect_mncc_info_timer(0, 0, call);
dect_mncc_send_call_info(call);
dect_mncc_info_timer_schedule(dh, call);
}
static void dect_mncc_reject_ind(struct dect_handle *dh, struct dect_call *call,
@ -205,7 +204,7 @@ static void dect_mncc_reject_ind(struct dect_handle *dh, struct dect_call *call,
{
struct call *priv = dect_call_priv(call);
event_del(&priv->event);
dect_stop_timer(dh, priv->timer);
}
static void dect_mncc_release_ind(struct dect_handle *dh, struct dect_call *call,

View File

@ -9,7 +9,7 @@
struct dect_handle *dh;
static void event_callback(int fd, short mask, void *data)
static void event_io_callback(int fd, short mask, void *data)
{
struct dect_fd *dfd = data;
uint32_t events;
@ -35,7 +35,7 @@ static int register_fd(const struct dect_handle *dh, struct dect_fd *dfd,
if (events & DECT_FD_WRITE)
mask |= EV_WRITE;
event_set(ev, dfd->fd, mask, event_callback, dfd);
event_set(ev, dect_fd_num(dfd), mask, event_io_callback, dfd);
event_add(ev, NULL);
return 0;
}
@ -47,7 +47,7 @@ static void unregister_fd(const struct dect_handle *dh, struct dect_fd *dfd)
event_del(ev);
}
static void timer_expire(int fd, short mask, void *data)
static void event_timer_callback(int fd, short mask, void *data)
{
dect_run_timer(dh, data);
}
@ -58,7 +58,7 @@ static void start_timer(const struct dect_handle *dh,
{
struct event *ev = dect_timer_priv(timer);
evtimer_set(ev, timer_expire, timer);
evtimer_set(ev, event_timer_callback, timer);
evtimer_add(ev, (struct timeval *)tv);
}

View File

@ -3,7 +3,6 @@
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <event.h>
#include <dect/libdect.h>
#include "common.h"