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:
Frediano Ziglio 2019-05-23 11:47:39 +01:00 committed by Frediano Ziglio
parent 164a333f99
commit f680cc7870
2 changed files with 13 additions and 3 deletions

View File

@ -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_ */

View File

@ -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()