Re: [Spice-devel] [PATCH 13/14] Use C++ style for cursor message initialization instead of C style

2018-02-14 Thread Frediano Ziglio
> 
> From: Christophe de Dinechin 
> 
> Signed-off-by: Christophe de Dinechin 
> ---
>  src/spice-streaming-agent.cpp | 49
>  +--
>  1 file changed, 29 insertions(+), 20 deletions(-)
> 
> diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
> index a55e1a5..7a3a46d 100644
> --- a/src/spice-streaming-agent.cpp
> +++ b/src/spice-streaming-agent.cpp
> @@ -53,6 +53,12 @@ struct SpiceStreamDataMessage
>  StreamMsgData msg;
>  };
>  
> +struct SpiceStreamCursorMessage
> +{
> +StreamDevHeader hdr;
> +StreamMsgCursorSet msg;
> +};
> +
>  struct Stream
>  {
>  Stream(const char *name, int ): fd(fd)
> @@ -310,38 +316,41 @@ static void usage(const char *progname)
>  }
>  
>  static void
> -send_cursor(unsigned width, unsigned height, int hotspot_x, int hotspot_y,
> +send_cursor(uint16_t width, uint16_t height,
> +uint16_t hotspot_x, uint16_t hotspot_y,
>  std::function fill_cursor)
>  {
>  if (width >= STREAM_MSG_CURSOR_SET_MAX_WIDTH ||
>  height >= STREAM_MSG_CURSOR_SET_MAX_HEIGHT)
>  return;
>  
> -size_t cursor_size =
> -sizeof(StreamDevHeader) + sizeof(StreamMsgCursorSet) +
> -width * height * sizeof(uint32_t);
> -std::unique_ptr msg(new uint8_t[cursor_size]);
> -
> -StreamDevHeader
> _hdr(*reinterpret_cast(msg.get()));
> -memset(_hdr, 0, sizeof(dev_hdr));
> -dev_hdr.protocol_version = STREAM_DEVICE_PROTOCOL;
> -dev_hdr.type = STREAM_TYPE_CURSOR_SET;
> -dev_hdr.size = cursor_size - sizeof(StreamDevHeader);
> +const uint32_t cursor_msgsize =
> +sizeof(SpiceStreamCursorMessage) + width * height *
> sizeof(uint32_t);
> +const uint32_t hdrsize  = sizeof(StreamDevHeader);
>  
> -StreamMsgCursorSet _msg(*reinterpret_cast *>(msg.get() + sizeof(StreamDevHeader)));
> -memset(_msg, 0, sizeof(cursor_msg));
> +std::unique_ptr storage(new uint8_t[cursor_msgsize]);
>  
> -cursor_msg.type = SPICE_CURSOR_TYPE_ALPHA;
> -cursor_msg.width = width;
> -cursor_msg.height = height;
> -cursor_msg.hot_spot_x = hotspot_x;
> -cursor_msg.hot_spot_y = hotspot_y;
> +SpiceStreamCursorMessage *cursor_msg =
> +new(storage.get()) SpiceStreamCursorMessage {
> +.hdr = {
> +.protocol_version = STREAM_DEVICE_PROTOCOL,
> +.type = STREAM_TYPE_CURSOR_SET,
> +.size = cursor_msgsize - hdrsize
> +},
> +.msg = {
> +.type = SPICE_CURSOR_TYPE_ALPHA,
> +.width = width,
> +.height = height,
> +.hot_spot_x = hotspot_x,
> +.hot_spot_y = hotspot_y
> +}
> +};
>  
> -uint32_t *pixels = reinterpret_cast(cursor_msg.data);
> +uint32_t *pixels = reinterpret_cast(cursor_msg->msg.data);
>  fill_cursor(pixels);
>  
>  std::lock_guard stream_guard(stream_mtx);
> -write_all(streamfd, msg.get(), cursor_size);
> +write_all(streamfd, storage.get(), cursor_msgsize);
>  }
>  
>  static void cursor_changes(Display *display, int event_base)

Does not compile on gcc

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH 13/14] Use C++ style for cursor message initialization instead of C style

2018-02-14 Thread Christophe de Dinechin
From: Christophe de Dinechin 

Signed-off-by: Christophe de Dinechin 
---
 src/spice-streaming-agent.cpp | 49 +--
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index a55e1a5..7a3a46d 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -53,6 +53,12 @@ struct SpiceStreamDataMessage
 StreamMsgData msg;
 };
 
+struct SpiceStreamCursorMessage
+{
+StreamDevHeader hdr;
+StreamMsgCursorSet msg;
+};
+
 struct Stream
 {
 Stream(const char *name, int ): fd(fd)
@@ -310,38 +316,41 @@ static void usage(const char *progname)
 }
 
 static void
-send_cursor(unsigned width, unsigned height, int hotspot_x, int hotspot_y,
+send_cursor(uint16_t width, uint16_t height,
+uint16_t hotspot_x, uint16_t hotspot_y,
 std::function fill_cursor)
 {
 if (width >= STREAM_MSG_CURSOR_SET_MAX_WIDTH ||
 height >= STREAM_MSG_CURSOR_SET_MAX_HEIGHT)
 return;
 
-size_t cursor_size =
-sizeof(StreamDevHeader) + sizeof(StreamMsgCursorSet) +
-width * height * sizeof(uint32_t);
-std::unique_ptr msg(new uint8_t[cursor_size]);
-
-StreamDevHeader _hdr(*reinterpret_cast(msg.get()));
-memset(_hdr, 0, sizeof(dev_hdr));
-dev_hdr.protocol_version = STREAM_DEVICE_PROTOCOL;
-dev_hdr.type = STREAM_TYPE_CURSOR_SET;
-dev_hdr.size = cursor_size - sizeof(StreamDevHeader);
+const uint32_t cursor_msgsize =
+sizeof(SpiceStreamCursorMessage) + width * height * sizeof(uint32_t);
+const uint32_t hdrsize  = sizeof(StreamDevHeader);
 
-StreamMsgCursorSet _msg(*reinterpret_cast(msg.get() + sizeof(StreamDevHeader)));
-memset(_msg, 0, sizeof(cursor_msg));
+std::unique_ptr storage(new uint8_t[cursor_msgsize]);
 
-cursor_msg.type = SPICE_CURSOR_TYPE_ALPHA;
-cursor_msg.width = width;
-cursor_msg.height = height;
-cursor_msg.hot_spot_x = hotspot_x;
-cursor_msg.hot_spot_y = hotspot_y;
+SpiceStreamCursorMessage *cursor_msg =
+new(storage.get()) SpiceStreamCursorMessage {
+.hdr = {
+.protocol_version = STREAM_DEVICE_PROTOCOL,
+.type = STREAM_TYPE_CURSOR_SET,
+.size = cursor_msgsize - hdrsize
+},
+.msg = {
+.type = SPICE_CURSOR_TYPE_ALPHA,
+.width = width,
+.height = height,
+.hot_spot_x = hotspot_x,
+.hot_spot_y = hotspot_y
+}
+};
 
-uint32_t *pixels = reinterpret_cast(cursor_msg.data);
+uint32_t *pixels = reinterpret_cast(cursor_msg->msg.data);
 fill_cursor(pixels);
 
 std::lock_guard stream_guard(stream_mtx);
-write_all(streamfd, msg.get(), cursor_size);
+write_all(streamfd, storage.get(), cursor_msgsize);
 }
 
 static void cursor_changes(Display *display, int event_base)
-- 
2.13.5 (Apple Git-94)

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel