mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-07 14:21:43 +00:00
event-loop: Remove template
Since SpiceCoreInterfaceInternal is a private data structure, we can extend it as we see fit without breaking ABI. In particular, adding a GMainContext member to it allows us to remove the need for the event loop template which is currently included in the basic_event_loop.c test file. Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
4b923347b7
commit
6e407a81df
@ -70,6 +70,7 @@ libserver_la_SOURCES = \
|
||||
char-device.c \
|
||||
char-device.h \
|
||||
demarshallers.h \
|
||||
event-loop.c \
|
||||
glz-encoder.c \
|
||||
glz-encoder.h \
|
||||
glz-encoder-dict.c \
|
||||
@ -159,7 +160,6 @@ EXTRA_DIST = \
|
||||
cache-item.tmpl.c \
|
||||
glz-encode-match.tmpl.c \
|
||||
glz-encode.tmpl.c \
|
||||
event-loop.tmpl.c \
|
||||
spice-server.syms \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@ -16,18 +16,10 @@
|
||||
License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* This is a template file to implement event loop using GLib one.
|
||||
*
|
||||
* Is implemented as a template file to avoid some linker problem.
|
||||
*
|
||||
* This file export a variable:
|
||||
/*
|
||||
*This file export a global variable:
|
||||
*
|
||||
* SpiceCoreInterfaceInternal event_loop_core;
|
||||
*
|
||||
* You should also define some functions like:
|
||||
*
|
||||
* GMainContext *event_loop_context_from_iface(const SpiceCoreInterfaceInternal *opaque);
|
||||
* void event_loop_channel_event(int event, SpiceChannelEventInfo *info);
|
||||
*/
|
||||
|
||||
#include "red-common.h"
|
||||
@ -44,7 +36,7 @@ static SpiceTimer* timer_add(const SpiceCoreInterfaceInternal *iface,
|
||||
{
|
||||
SpiceTimer *timer = spice_malloc0(sizeof(SpiceTimer));
|
||||
|
||||
timer->context = event_loop_context_from_iface(iface);
|
||||
timer->context = iface->main_context;
|
||||
timer->func = func;
|
||||
timer->opaque = opaque;
|
||||
|
||||
@ -157,7 +149,7 @@ static SpiceWatch *watch_add(const SpiceCoreInterfaceInternal *iface,
|
||||
spice_return_val_if_fail(func != NULL, NULL);
|
||||
|
||||
watch = spice_malloc0(sizeof(SpiceWatch));
|
||||
watch->context = event_loop_context_from_iface(iface);
|
||||
watch->context = iface->main_context;
|
||||
watch->channel = g_io_channel_unix_new(fd);
|
||||
watch->func = func;
|
||||
watch->opaque = opaque;
|
||||
@ -176,7 +168,7 @@ static void watch_remove(SpiceWatch *watch)
|
||||
free(watch);
|
||||
}
|
||||
|
||||
static SpiceCoreInterfaceInternal event_loop_core = {
|
||||
SpiceCoreInterfaceInternal event_loop_core = {
|
||||
.timer_add = timer_add,
|
||||
.timer_start = timer_start,
|
||||
.timer_cancel = timer_cancel,
|
||||
@ -185,6 +177,4 @@ static SpiceCoreInterfaceInternal event_loop_core = {
|
||||
.watch_add = watch_add,
|
||||
.watch_update_mask = watch_update_mask,
|
||||
.watch_remove = watch_remove,
|
||||
|
||||
.channel_event = event_loop_channel_event
|
||||
};
|
||||
@ -52,6 +52,10 @@ struct SpiceCoreInterfaceInternal {
|
||||
void (*watch_remove)(SpiceWatch *watch);
|
||||
|
||||
void (*channel_event)(int event, SpiceChannelEventInfo *info);
|
||||
|
||||
GMainContext *main_context;
|
||||
};
|
||||
|
||||
extern SpiceCoreInterfaceInternal event_loop_core;
|
||||
|
||||
#endif
|
||||
|
||||
@ -30,9 +30,9 @@ libtest_a_SOURCES = \
|
||||
LDADD = \
|
||||
libtest.a \
|
||||
$(top_builddir)/spice-common/common/libspice-common.la \
|
||||
$(top_builddir)/server/libspice-server.la \
|
||||
$(top_builddir)/server/libserver.la \
|
||||
$(GLIB2_LIBS) \
|
||||
$(SPICE_NONPKGCONFIG_LIBS) \
|
||||
$(SPICE_NONPKGCONFIG_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
@ -70,8 +70,6 @@ noinst_LIBRARIES += \
|
||||
|
||||
spice_server_replay_SOURCES = replay.c
|
||||
|
||||
stream_test_LDADD = ../libserver.la $(LDADD)
|
||||
|
||||
stat_test_SOURCES = stat-main.c
|
||||
stat_test_LDADD = \
|
||||
libstat_test1.a \
|
||||
|
||||
@ -43,19 +43,12 @@ GMainContext *basic_event_loop_get_context(void)
|
||||
return main_context;
|
||||
}
|
||||
|
||||
static inline GMainContext *event_loop_context_from_iface(const SpiceCoreInterfaceInternal *iface)
|
||||
{
|
||||
return main_context;
|
||||
}
|
||||
|
||||
static void event_loop_channel_event(int event, SpiceChannelEventInfo *info)
|
||||
{
|
||||
DPRINTF(0, "channel event con, type, id, event: %d, %d, %d, %d",
|
||||
info->connection_id, info->type, info->id, event);
|
||||
}
|
||||
|
||||
#include "../event-loop.tmpl.c"
|
||||
|
||||
void basic_event_loop_mainloop(void)
|
||||
{
|
||||
GMainLoop *loop = g_main_loop_new(main_context, FALSE);
|
||||
@ -91,7 +84,6 @@ static SpiceCoreInterface core = {
|
||||
},
|
||||
.timer_add = base_timer_add,
|
||||
.watch_add = base_watch_add,
|
||||
.channel_event = event_loop_channel_event,
|
||||
};
|
||||
|
||||
SpiceCoreInterface *basic_event_loop_init(void)
|
||||
@ -104,6 +96,9 @@ SpiceCoreInterface *basic_event_loop_init(void)
|
||||
core.timer_remove = event_loop_core.timer_remove;
|
||||
core.watch_update_mask = event_loop_core.watch_update_mask;
|
||||
core.watch_remove = event_loop_core.watch_remove;
|
||||
event_loop_core.channel_event = core.channel_event = event_loop_channel_event;
|
||||
event_loop_core.main_context = main_context;
|
||||
|
||||
return &core;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user