[Spice-devel] [PATCH 18/18] minor timer interface cleanups.
Gerd Hoffmann
kraxel at redhat.com
Mon Mar 29 08:08:54 PDT 2010
Make the timer interface largely look like the watch interface.
Simliar naming convention for the functions (timer_*) and a
opaque SpiceTimer type.
---
server/red_tunnel_worker.c | 5 ++---
server/reds.c | 40 ++++++++++++++++++++--------------------
server/vd_interface.h | 12 +++++++-----
3 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
index 1392102..6c3a0ee 100644
--- a/server/red_tunnel_worker.c
+++ b/server/red_tunnel_worker.c
@@ -3311,8 +3311,7 @@ static UserTimer *create_timer(SlirpUsrNetworkInterface *usr_interface,
worker = ((RedSlirpNetworkInterface *)usr_interface)->worker;
- return (void *)worker->core_interface->create_timer(worker->core_interface,
- proc, opaque);
+ return (void *)worker->core_interface->timer_add(proc, opaque);
}
static void arm_timer(SlirpUsrNetworkInterface *usr_interface, UserTimer *timer, uint32_t ms)
@@ -3333,7 +3332,7 @@ static void arm_timer(SlirpUsrNetworkInterface *usr_interface, UserTimer *timer,
return;
}
- worker->core_interface->arm_timer(worker->core_interface, (VDObjectRef)timer, ms);
+ worker->core_interface->timer_start((SpiceTimer*)timer, ms);
}
/***********************************************
diff --git a/server/reds.c b/server/reds.c
index 1df575d..867c11c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -265,9 +265,9 @@ typedef struct RedsState {
int is_client_mouse_allowed;
int dispatcher_allows_client_mouse;
MonitorMode monitor_mode;
- VDObjectRef mig_timer;
- VDObjectRef key_modifiers_timer;
- VDObjectRef mm_timer;
+ SpiceTimer *mig_timer;
+ SpiceTimer *key_modifiers_timer;
+ SpiceTimer *mm_timer;
TicketAuthentication taTicket;
SSL_CTX *ctx;
@@ -277,7 +277,7 @@ typedef struct RedsState {
SpiceStat *stat;
pthread_mutex_t stat_lock;
RedsStatValue roundtrip_stat;
- VDObjectRef ping_timer;
+ SpiceTimer *ping_timer;
int ping_interval;
#endif
uint32_t ping_id;
@@ -684,7 +684,7 @@ static void reds_mig_cleanup()
reds->mig_inprogress = FALSE;
reds->mig_wait_connect = FALSE;
reds->mig_wait_disconnect = FALSE;
- core->disarm_timer(core, reds->mig_timer);
+ core->timer_cancel(reds->mig_timer);
mig->notifier_done(mig, reds->mig_notifier);
}
}
@@ -1036,9 +1036,9 @@ static void do_ping_client(const char *opt, int has_interval, int interval)
if (has_interval && interval > 0) {
reds->ping_interval = interval * 1000;
}
- core->arm_timer(core, reds->ping_timer, reds->ping_interval);
+ core->timer_start(reds->ping_timer, reds->ping_interval);
} else if (!strcmp(opt, "off")) {
- core->disarm_timer(core, reds->ping_timer);
+ core->timer_cancel(reds->ping_timer);
} else {
return;
}
@@ -1048,11 +1048,11 @@ static void ping_timer_cb()
{
if (!reds->peer) {
red_printf("not connected to peer, ping off");
- core->disarm_timer(core, reds->ping_timer);
+ core->timer_cancel(reds->ping_timer);
return;
}
do_ping_client(NULL, 0, 0);
- core->arm_timer(core, reds->ping_timer, reds->ping_interval);
+ core->timer_start(reds->ping_timer, reds->ping_interval);
}
#endif
@@ -2118,7 +2118,7 @@ static void reds_handle_main_link(RedLinkInfo *link)
static void activate_modifiers_watch()
{
- core->arm_timer(core, reds->key_modifiers_timer, KEY_MODIFIERS_TTL);
+ core->timer_start(reds->key_modifiers_timer, KEY_MODIFIERS_TTL);
}
static void push_key_scan(uint8_t scan)
@@ -3417,7 +3417,7 @@ static void reds_mig_continue(RedsMigSpice *s)
free(s->local_args);
free(s);
reds->mig_wait_connect = TRUE;
- core->arm_timer(core, reds->mig_timer, MIGRATE_TIMEOUT);
+ core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT);
}
static void reds_mig_receive_ack(RedsMigSpice *s)
@@ -3713,7 +3713,7 @@ static void reds_mig_finished(void *opaque, int completed)
SpiceMsgMigrate *migrate;
reds->mig_wait_disconnect = TRUE;
- core->arm_timer(core, reds->mig_timer, MIGRATE_TIMEOUT);
+ core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT);
if (!(item = new_simple_out_item(SPICE_MSG_MIGRATE, sizeof(SpiceMsgMigrate)))) {
red_printf("alloc item failed");
@@ -3990,7 +3990,7 @@ void reds_enable_mm_timer()
SpiceMsgMainMultiMediaTime *time_mes;
SimpleOutItem *item;
- core->arm_timer(core, reds->mm_timer, MM_TIMER_GRANULARITY_MS);
+ core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS);
if (!reds->peer) {
return;
}
@@ -4007,13 +4007,13 @@ void reds_enable_mm_timer()
void reds_desable_mm_timer()
{
- core->disarm_timer(core, reds->mm_timer);
+ core->timer_cancel(reds->mm_timer);
}
static void mm_timer_proc(void *opaque)
{
red_dispatcher_set_mm_time(reds_get_mm_time());
- core->arm_timer(core, reds->mm_timer, MM_TIMER_GRANULARITY_MS);
+ core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS);
}
static void attach_to_red_agent(VDIPortInterface *interface)
@@ -4300,10 +4300,10 @@ static void do_spice_init(CoreInterface *core_interface)
init_vd_agent_resources();
- if (!(reds->mig_timer = core->create_timer(core, migrate_timout, NULL))) {
+ if (!(reds->mig_timer = core->timer_add(migrate_timout, NULL))) {
red_error("migration timer create failed");
}
- if (!(reds->key_modifiers_timer = core->create_timer(core, key_modifiers_sender, NULL))) {
+ if (!(reds->key_modifiers_timer = core->timer_add(key_modifiers_sender, NULL))) {
red_error("key modifiers timer create failed");
}
@@ -4330,16 +4330,16 @@ static void do_spice_init(CoreInterface *core_interface)
if (pthread_mutex_init(&reds->stat_lock, NULL)) {
red_error("mutex init failed");
}
- if (!(reds->ping_timer = core->create_timer(core, ping_timer_cb, NULL))) {
+ if (!(reds->ping_timer = core->timer_add(ping_timer_cb, NULL))) {
red_error("ping timer create failed");
}
reds->ping_interval = PING_INTERVAL;
#endif
- if (!(reds->mm_timer = core->create_timer(core, mm_timer_proc, NULL))) {
+ if (!(reds->mm_timer = core->timer_add(mm_timer_proc, NULL))) {
red_error("mm timer create failed");
}
- core->arm_timer(core, reds->mm_timer, MM_TIMER_GRANULARITY_MS);
+ core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS);
reds_init_net();
if (reds->secure_listen_socket != -1) {
diff --git a/server/vd_interface.h b/server/vd_interface.h
index f69bf35..c5a1a5a 100644
--- a/server/vd_interface.h
+++ b/server/vd_interface.h
@@ -66,7 +66,6 @@ typedef enum {
typedef void (*vd_interface_change_notifier_t)(void *opaque, VDInterface *interface,
VDInterfaceChangeType change);
-typedef void (*timer_callback_t)(void *opaque);
#define SPICE_WATCH_EVENT_READ (1 << 0)
#define SPICE_WATCH_EVENT_WRITE (1 << 1)
@@ -74,13 +73,16 @@ typedef void (*timer_callback_t)(void *opaque);
typedef struct SpiceWatch SpiceWatch;
typedef void (*SpiceWatchFunc)(int fd, int event, void *opaque);
+typedef struct SpiceTimer SpiceTimer;
+typedef void (*SpiceTimerFunc)(void *opaque);
+
struct CoreInterface {
VDInterface base;
- VDObjectRef (*create_timer)(CoreInterface *core, timer_callback_t, void *opaue);
- void (*arm_timer)(CoreInterface *core, VDObjectRef timer, uint32_t ms);
- void (*disarm_timer)(CoreInterface *core, VDObjectRef timer);
- void (*destroy_timer)(CoreInterface *core, VDObjectRef timer);
+ SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
+ void (*timer_start)(SpiceTimer *timer, uint32_t ms);
+ void (*timer_cancel)(SpiceTimer *timer);
+ void (*timer_remove)(SpiceTimer *timer);
SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
--
1.6.6.1
More information about the Spice-devel
mailing list