[Spice-devel] [PATCH spice-streaming-agent 1/3] Make error.hpp and the Error class a public API

Lukáš Hrázký lhrazky at redhat.com
Tue Dec 4 10:41:49 UTC 2018


Moves IOError and its descendants to stream-port.hpp, as those are I/O
errors related to that. Makes the Error class a public base class for
exceptions thrown across the API boundary.

Note exception ABI conpatibility is not guaranteed between different
compilers, but it is compatible between gcc and clang so for these two
compilers it is safe.

Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
---
 include/spice-streaming-agent/Makefile.am     |  1 +
 .../spice-streaming-agent}/error.hpp          | 22 +------------------
 src/Makefile.am                               |  2 --
 src/cursor-updater.cpp                        |  2 +-
 src/error.cpp                                 | 21 ------------------
 src/frame-log.cpp                             |  2 +-
 src/spice-streaming-agent.cpp                 |  2 +-
 src/stream-port.cpp                           |  5 ++++-
 src/stream-port.hpp                           | 22 +++++++++++++++++++
 src/unittests/Makefile.am                     |  1 -
 src/unittests/test-stream-port.cpp            |  2 +-
 11 files changed, 32 insertions(+), 50 deletions(-)
 rename {src => include/spice-streaming-agent}/error.hpp (63%)
 delete mode 100644 src/error.cpp

diff --git a/include/spice-streaming-agent/Makefile.am b/include/spice-streaming-agent/Makefile.am
index 844f791..bcd679b 100644
--- a/include/spice-streaming-agent/Makefile.am
+++ b/include/spice-streaming-agent/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 public_includedir = $(includedir)/spice-streaming-agent
 public_include_HEADERS = \
+	error.hpp \
 	frame-capture.hpp \
 	plugin.hpp \
 	$(NULL)
diff --git a/src/error.hpp b/include/spice-streaming-agent/error.hpp
similarity index 63%
rename from src/error.hpp
rename to include/spice-streaming-agent/error.hpp
index e30990f..2993dbb 100644
--- a/src/error.hpp
+++ b/include/spice-streaming-agent/error.hpp
@@ -18,27 +18,7 @@ namespace streaming_agent {
 class Error : public std::runtime_error
 {
 public:
-    Error(const std::string &message);
-};
-
-class IOError : public Error
-{
-public:
-    using Error::Error;
-
-    IOError(const std::string &msg, int sys_errno);
-};
-
-class ReadError : public IOError
-{
-public:
-    using IOError::IOError;
-};
-
-class WriteError : public IOError
-{
-public:
-    using IOError::IOError;
+    Error(const std::string &message) : std::runtime_error(message) {}
 };
 
 template<class T>
diff --git a/src/Makefile.am b/src/Makefile.am
index 104da47..36a5d8a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,8 +57,6 @@ spice_streaming_agent_SOURCES = \
 	concrete-agent.hpp \
 	cursor-updater.cpp \
 	cursor-updater.hpp \
-	error.cpp \
-	error.hpp \
 	frame-log.cpp \
 	frame-log.hpp \
 	mjpeg-fallback.cpp \
diff --git a/src/cursor-updater.cpp b/src/cursor-updater.cpp
index f0412db..c27131b 100644
--- a/src/cursor-updater.cpp
+++ b/src/cursor-updater.cpp
@@ -7,7 +7,7 @@
 
 #include "cursor-updater.hpp"
 
-#include "error.hpp"
+#include <spice-streaming-agent/error.hpp>
 
 #include <spice/stream-device.h>
 #include <spice/enums.h>
diff --git a/src/error.cpp b/src/error.cpp
deleted file mode 100644
index 561537d..0000000
--- a/src/error.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/* The errors module.
- *
- * \copyright
- * Copyright 2018 Red Hat Inc. All rights reserved.
- */
-
-#include "error.hpp"
-
-#include <string.h>
-
-
-namespace spice {
-namespace streaming_agent {
-
-Error::Error(const std::string &message) : std::runtime_error(message) {}
-
-IOError::IOError(const std::string &msg, int sys_errno) :
-    Error(msg + ": " + std::to_string(sys_errno) + " - " + strerror(sys_errno))
-{}
-
-}} // namespace spice::streaming_agent
diff --git a/src/frame-log.cpp b/src/frame-log.cpp
index cc993cd..62fffc3 100644
--- a/src/frame-log.cpp
+++ b/src/frame-log.cpp
@@ -6,8 +6,8 @@
 
 #include "frame-log.hpp"
 
-#include "error.hpp"
 #include "hexdump.h"
+#include <spice-streaming-agent/error.hpp>
 
 #include <chrono>
 #include <cstdarg>
diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 36d0692..4b44df3 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -9,7 +9,7 @@
 #include "cursor-updater.hpp"
 #include "frame-log.hpp"
 #include "stream-port.hpp"
-#include "error.hpp"
+#include <spice-streaming-agent/error.hpp>
 
 #include <spice/stream-device.h>
 #include <spice/enums.h>
diff --git a/src/stream-port.cpp b/src/stream-port.cpp
index afef2e9..2670120 100644
--- a/src/stream-port.cpp
+++ b/src/stream-port.cpp
@@ -5,7 +5,6 @@
  */
 
 #include "stream-port.hpp"
-#include "error.hpp"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -19,6 +18,10 @@
 namespace spice {
 namespace streaming_agent {
 
+IOError::IOError(const std::string &msg, int sys_errno) :
+    Error(msg + ": " + std::to_string(sys_errno) + " - " + strerror(sys_errno))
+{}
+
 InboundMessage::InboundMessage(const StreamDevHeader &header, std::unique_ptr<uint8_t[]> &&data) :
     header(header),
     data(std::move(data))
diff --git a/src/stream-port.hpp b/src/stream-port.hpp
index cf010a4..08473f7 100644
--- a/src/stream-port.hpp
+++ b/src/stream-port.hpp
@@ -10,6 +10,8 @@
 #include <spice/stream-device.h>
 #include <spice/enums.h>
 
+#include <spice-streaming-agent/error.hpp>
+
 #include <cstddef>
 #include <string>
 #include <memory>
@@ -20,6 +22,26 @@
 namespace spice {
 namespace streaming_agent {
 
+class IOError : public Error
+{
+public:
+    using Error::Error;
+
+    IOError(const std::string &msg, int sys_errno);
+};
+
+class ReadError : public IOError
+{
+public:
+    using IOError::IOError;
+};
+
+class WriteError : public IOError
+{
+public:
+    using IOError::IOError;
+};
+
 struct StartStopMessage
 {
     bool start_streaming = false;
diff --git a/src/unittests/Makefile.am b/src/unittests/Makefile.am
index c9de603..1ae5a07 100644
--- a/src/unittests/Makefile.am
+++ b/src/unittests/Makefile.am
@@ -55,7 +55,6 @@ test_mjpeg_fallback_LDADD = \
 test_stream_port_SOURCES = \
 	test-stream-port.cpp \
 	../stream-port.cpp \
-	../error.cpp \
 	$(NULL)
 
 EXTRA_DIST = \
diff --git a/src/unittests/test-stream-port.cpp b/src/unittests/test-stream-port.cpp
index e23a058..e7b7b89 100644
--- a/src/unittests/test-stream-port.cpp
+++ b/src/unittests/test-stream-port.cpp
@@ -10,7 +10,7 @@
 #include <signal.h>
 
 #include "stream-port.hpp"
-#include "error.hpp"
+#include <spice-streaming-agent/error.hpp>
 
 
 namespace ssa = spice::streaming_agent;
-- 
2.19.2



More information about the Spice-devel mailing list