summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2019-05-23 11:47:39 +0100
committerFrediano Ziglio <freddy77@gmail.com>2020-05-01 06:58:09 +0100
commitf680cc7870143beb61de6094728667a34e6083ca (patch)
treeed037e944878b4c1fd954ed218d38103c2dfd068
parent164a333f991f09452844a94ad84a3190a2b6149d (diff)
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>
-rw-r--r--server/dispatcher.h11
-rw-r--r--server/red-channel.cpp5
2 files changed, 13 insertions, 3 deletions
diff --git a/server/dispatcher.h b/server/dispatcher.h
index b3e0c789..23cae4f5 100644
--- a/server/dispatcher.h
+++ b/server/dispatcher.h
@@ -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_ */
diff --git a/server/red-channel.cpp b/server/red-channel.cpp
index 58be1921..24879b33 100644
--- a/server/red-channel.cpp
+++ b/server/red-channel.cpp
@@ -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()