mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-01-05 06:00:43 +00:00
dispatcher: Add a more safe dispatcher_send_message_custom version
Use a template to wrap the other dispatcher_send_message_custom avoiding having to pass a void* opaque and extract payload size from passed type. Will be used more by next commit when Dispatchers are turned into C++. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
164a333f99
commit
f680cc7870
@ -171,4 +171,15 @@ void dispatcher_set_opaque(Dispatcher *dispatcher, void *opaque);
|
||||
|
||||
SPICE_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
inline void
|
||||
dispatcher_send_message_custom(Dispatcher *dispatcher, void (*handler)(void *, T*),
|
||||
T *payload, bool ack)
|
||||
{
|
||||
dispatcher_send_message_custom(dispatcher, (dispatcher_handle_message) handler,
|
||||
payload, sizeof(*payload), ack);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DISPATCHER_H_ */
|
||||
|
||||
@ -335,9 +335,8 @@ typedef struct RedMessageConnect {
|
||||
RedChannelCapabilities caps;
|
||||
} RedMessageConnect;
|
||||
|
||||
static void handle_dispatcher_connect(void *opaque, void *payload)
|
||||
static void handle_dispatcher_connect(void *opaque, RedMessageConnect *msg)
|
||||
{
|
||||
RedMessageConnect *msg = (RedMessageConnect*) payload;
|
||||
RedChannel *channel = msg->channel;
|
||||
|
||||
channel->on_connect(msg->client, msg->stream, msg->migration, &msg->caps);
|
||||
@ -367,7 +366,7 @@ void RedChannel::connect(RedClient *client, RedStream *stream, int migration,
|
||||
red_channel_capabilities_init(&payload.caps, caps);
|
||||
|
||||
dispatcher_send_message_custom(dispatcher, handle_dispatcher_connect,
|
||||
&payload, sizeof(payload), false);
|
||||
&payload, false);
|
||||
}
|
||||
|
||||
GList *RedChannel::get_clients()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user