[Spice-devel] [PATCH spice-streaming-agent] plugin: Do not use references to pass ownership

Frediano Ziglio fziglio at redhat.com
Thu Sep 20 13:32:19 UTC 2018


Usually when references are used ownership is not moved.
Avoid to use references to confuse code reader.
Pointers and references have same ABI so the change does not
break plugin ABI.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 include/spice-streaming-agent/plugin.hpp | 3 ++-
 src/concrete-agent.cpp                   | 4 ++--
 src/concrete-agent.hpp                   | 2 +-
 src/gst-plugin.cpp                       | 2 +-
 src/mjpeg-fallback.cpp                   | 2 +-
 5 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/spice-streaming-agent/plugin.hpp b/include/spice-streaming-agent/plugin.hpp
index e9acf2d..5845272 100644
--- a/include/spice-streaming-agent/plugin.hpp
+++ b/include/spice-streaming-agent/plugin.hpp
@@ -104,8 +104,9 @@ class Agent
 public:
     /*!
      * Register a plugin in the system.
+     * Agent will take ownership of the plugin.
      */
-    virtual void Register(Plugin& plugin) = 0;
+    virtual void Register(Plugin* plugin) = 0;
 
     /*!
      * Get options array.
diff --git a/src/concrete-agent.cpp b/src/concrete-agent.cpp
index 1f8b4b4..7abc38f 100644
--- a/src/concrete-agent.cpp
+++ b/src/concrete-agent.cpp
@@ -37,9 +37,9 @@ bool ConcreteAgent::PluginVersionIsCompatible(unsigned pluginVersion) const
         MinorVersion(version) >= MinorVersion(pluginVersion);
 }
 
-void ConcreteAgent::Register(Plugin& plugin)
+void ConcreteAgent::Register(Plugin* plugin)
 {
-    plugins.push_back(std::shared_ptr<Plugin>(&plugin));
+    plugins.push_back(std::shared_ptr<Plugin>(plugin));
 }
 
 const ConfigureOption* ConcreteAgent::Options() const
diff --git a/src/concrete-agent.hpp b/src/concrete-agent.hpp
index c0cf9ba..fd08cd5 100644
--- a/src/concrete-agent.hpp
+++ b/src/concrete-agent.hpp
@@ -27,7 +27,7 @@ class ConcreteAgent final : public Agent
 {
 public:
     ConcreteAgent();
-    void Register(Plugin& plugin) override;
+    void Register(Plugin* plugin) override;
     const ConfigureOption* Options() const override;
     void LoadPlugins(const std::string &directory);
     // pointer must remain valid
diff --git a/src/gst-plugin.cpp b/src/gst-plugin.cpp
index 6eb9e7e..4060942 100644
--- a/src/gst-plugin.cpp
+++ b/src/gst-plugin.cpp
@@ -456,7 +456,7 @@ SPICE_STREAMING_AGENT_PLUGIN(agent)
 
     plugin->ParseOptions(agent->Options());
 
-    agent->Register(*plugin.release());
+    agent->Register(plugin.release());
 
     return true;
 }
diff --git a/src/mjpeg-fallback.cpp b/src/mjpeg-fallback.cpp
index 08353f2..dd72558 100644
--- a/src/mjpeg-fallback.cpp
+++ b/src/mjpeg-fallback.cpp
@@ -188,7 +188,7 @@ bool MjpegPlugin::Register(Agent* agent)
         syslog(LOG_ERR, "Error parsing plugin option: %s", e.what());
     }
 
-    agent->Register(*plugin.release());
+    agent->Register(plugin.release());
 
     return true;
 }
-- 
2.17.1



More information about the Spice-devel mailing list