[07/22] Since we use a namespace, simplify name of local classes

Submitted by Christophe de Dinechin on Feb. 28, 2018, 3:43 p.m.

Details

Message ID 20180228154325.25791-8-christophe@dinechin.org
State New
Headers show
Series "streaming-agent: C++ refactoring" ( rev: 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Christophe de Dinechin Feb. 28, 2018, 3:43 p.m.
From: Christophe de Dinechin <dinechin@redhat.com>

With namespaces, the fully qualified names of the classes are
unambiguous e.g. spice::streaming_agent::Stream. So following the KISS
principle, it makes the code simpler when class names are short.

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
---
 src/spice-streaming-agent.cpp | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 7b56458..5c36906 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -44,19 +44,24 @@  static size_t write_all(int fd, const void *buf, const size_t len);
 
 static ConcreteAgent agent;
 
-struct SpiceStreamFormatMessage
+namespace spice
+{
+namespace streaming_agent
+{
+
+struct FormatMessage
 {
     StreamDevHeader hdr;
     StreamMsgFormat msg;
 };
 
-struct SpiceStreamDataMessage
+struct DataMessage
 {
     StreamDevHeader hdr;
     StreamMsgData msg;
 };
 
-struct SpiceStreamCursorMessage
+struct CursorMessage
 {
     StreamDevHeader hdr;
     StreamMsgCursorSet msg;
@@ -82,6 +87,9 @@  private:
     int fd = -1;
 };
 
+}} // namespace spice::streaming_agent
+
+
 static bool streaming_requested = false;
 static bool quit_requested = false;
 static bool log_binary = false;
@@ -223,9 +231,9 @@  write_all(int fd, const void *buf, const size_t len)
 
 static int spice_stream_send_format(int streamfd, unsigned w, unsigned h, uint8_t c)
 {
-    const size_t msgsize = sizeof(SpiceStreamFormatMessage);
+    const size_t msgsize = sizeof(FormatMessage);
     const size_t hdrsize  = sizeof(StreamDevHeader);
-    SpiceStreamFormatMessage msg = {
+    FormatMessage msg = {
         .hdr = {
             .protocol_version = STREAM_DEVICE_PROTOCOL,
             .padding = 0,       // Workaround GCC "not implemented" bug
@@ -250,8 +258,8 @@  static int spice_stream_send_format(int streamfd, unsigned w, unsigned h, uint8_
 static int spice_stream_send_frame(int streamfd, const void *buf, const unsigned size)
 {
     ssize_t n;
-    const size_t msgsize = sizeof(SpiceStreamFormatMessage);
-    SpiceStreamDataMessage msg = {
+    const size_t msgsize = sizeof(FormatMessage);
+    DataMessage msg = {
         .hdr = {
             .protocol_version = STREAM_DEVICE_PROTOCOL,
             .padding = 0,       // Workaround GCC "not implemented" bug
@@ -333,9 +341,7 @@  send_cursor(int streamfd, unsigned width, unsigned height, int hotspot_x, int ho
         return;
     }
 
-    size_t cursor_size =
-        sizeof(StreamDevHeader) + sizeof(StreamMsgCursorSet) +
-        width * height * sizeof(uint32_t);
+    size_t cursor_size = sizeof(CursorMessage) + width * height * sizeof(uint32_t);
     std::unique_ptr<uint8_t[]> msg(new uint8_t[cursor_size]);
 
     StreamDevHeader &dev_hdr(*reinterpret_cast<StreamDevHeader*>(msg.get()));

Comments

> 
> From: Christophe de Dinechin <dinechin@redhat.com>
> 
> With namespaces, the fully qualified names of the classes are
> unambiguous e.g. spice::streaming_agent::Stream. So following the KISS
> principle, it makes the code simpler when class names are short.
> 
> Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>

Rebased at
https://cgit.freedesktop.org/~fziglio/spice-streaming-agent/commit/?h=style3&id=042589c6744bb0ebaa90e1422746477ca9ebcd90

> ---
>  src/spice-streaming-agent.cpp | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
> index 7b56458..5c36906 100644
> --- a/src/spice-streaming-agent.cpp
> +++ b/src/spice-streaming-agent.cpp
> @@ -44,19 +44,24 @@ static size_t write_all(int fd, const void *buf, const
> size_t len);
>  
>  static ConcreteAgent agent;
>  
> -struct SpiceStreamFormatMessage
> +namespace spice
> +{
> +namespace streaming_agent
> +{
> +

style, they should be

namespace spice {
namespace streaming_agent {

> +struct FormatMessage
>  {
>      StreamDevHeader hdr;
>      StreamMsgFormat msg;
>  };
>  
> -struct SpiceStreamDataMessage
> +struct DataMessage
>  {
>      StreamDevHeader hdr;
>      StreamMsgData msg;
>  };
>  
> -struct SpiceStreamCursorMessage
> +struct CursorMessage
>  {
>      StreamDevHeader hdr;
>      StreamMsgCursorSet msg;
> @@ -82,6 +87,9 @@ private:
>      int fd = -1;
>  };
>  
> +}} // namespace spice::streaming_agent
> +
> +

I would use one line separation.

>  static bool streaming_requested = false;
>  static bool quit_requested = false;
>  static bool log_binary = false;
> @@ -223,9 +231,9 @@ write_all(int fd, const void *buf, const size_t len)
>  
>  static int spice_stream_send_format(int streamfd, unsigned w, unsigned h,
>  uint8_t c)
>  {
> -    const size_t msgsize = sizeof(SpiceStreamFormatMessage);
> +    const size_t msgsize = sizeof(FormatMessage);
>      const size_t hdrsize  = sizeof(StreamDevHeader);
> -    SpiceStreamFormatMessage msg = {
> +    FormatMessage msg = {
>          .hdr = {
>              .protocol_version = STREAM_DEVICE_PROTOCOL,
>              .padding = 0,       // Workaround GCC "not implemented" bug
> @@ -250,8 +258,8 @@ static int spice_stream_send_format(int streamfd,
> unsigned w, unsigned h, uint8_
>  static int spice_stream_send_frame(int streamfd, const void *buf, const
>  unsigned size)
>  {
>      ssize_t n;
> -    const size_t msgsize = sizeof(SpiceStreamFormatMessage);
> -    SpiceStreamDataMessage msg = {
> +    const size_t msgsize = sizeof(FormatMessage);
> +    DataMessage msg = {
>          .hdr = {
>              .protocol_version = STREAM_DEVICE_PROTOCOL,
>              .padding = 0,       // Workaround GCC "not implemented" bug
> @@ -333,9 +341,7 @@ send_cursor(int streamfd, unsigned width, unsigned
> height, int hotspot_x, int ho
>          return;
>      }
>  
> -    size_t cursor_size =
> -        sizeof(StreamDevHeader) + sizeof(StreamMsgCursorSet) +
> -        width * height * sizeof(uint32_t);
> +    size_t cursor_size = sizeof(CursorMessage) + width * height *
> sizeof(uint32_t);
>      std::unique_ptr<uint8_t[]> msg(new uint8_t[cursor_size]);
>  
>      StreamDevHeader
>      &dev_hdr(*reinterpret_cast<StreamDevHeader*>(msg.get()));

Otherwise is fine.

Frediano