[smart_ptr] Don't reinvent the wheel. Leverage std::unique_ptr<>. 79/10979/1
authorOssama Othman <ossama.othman@intel.com>
Tue, 15 Oct 2013 20:37:57 +0000 (13:37 -0700)
committerOssama Othman <ossama.othman@intel.com>
Tue, 15 Oct 2013 20:37:57 +0000 (13:37 -0700)
Change-Id: I85f01f1ef464e9ad31a4268fdcdb1c0297244c23
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
19 files changed:
include/settingsd/Makefile.am
include/settingsd/event_callback.hpp
include/settingsd/glib_traits.hpp
include/settingsd/json_glib_traits.hpp
include/settingsd/response_callback.hpp
include/settingsd/send_callback.hpp
include/settingsd/smart_ptr.hpp [deleted file]
include/settingsd/unique_ptr.hpp [new file with mode: 0644]
lib/event_callback.cpp
lib/manager.cpp
lib/manager.hpp
lib/response_callback.cpp
lib/send_callback.cpp
plugins/connman/clock.cpp
plugins/connman/connman.cpp
plugins/connman/connman_manager.cpp
plugins/connman/service.cpp
plugins/connman/technology.cpp
src/daemon.cpp

index 8b5f5e4..0d32b7b 100644 (file)
@@ -27,5 +27,5 @@ pkginclude_HEADERS =          \
        response_callback.hpp   \
        glib_traits.hpp         \
        json_glib_traits.hpp    \
-       smart_ptr.hpp           \
+       unique_ptr.hpp          \
        dbus_signal_callback.hpp
index 069296a..910082a 100644 (file)
@@ -38,7 +38,6 @@ namespace ivi
 {
   namespace settings
   {
-    template<typename T> class smart_ptr;
     class manager;
 
     /**
@@ -85,12 +84,12 @@ namespace ivi
        * The appropriate "header" information will be prepended to the
        * event.
        */
-      smart_ptr<JsonBuilder> begin_event();
+      unique_ptr<JsonBuilder> begin_event();
 
       /**
        * End the JSON formatted event to the Settings app request.
        */
-      void end_event(smart_ptr<JsonBuilder> const & builder);
+      void end_event(unique_ptr<JsonBuilder> const & builder);
 
     private:
 
index 40c26ce..8578b08 100644 (file)
@@ -3,6 +3,8 @@
  *
  * @brief @c GLib traits.
  *
+ * This header contains traits specific to GLib types.
+ *
  * @author Ossama Othman @<ossama.othman@@intel.com@>
  *
  * @copyright @par
@@ -36,53 +38,85 @@ namespace ivi
   {
     template<typename T> struct traits;
 
+    // GVariant traits specialization.
     template<>
     struct traits<GVariant>
     {
-      static void
-      release(GVariant * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_variant_unref(p);
-      }
+        void
+        operator()(GVariant * p) const
+        {
+          if (p != nullptr)
+            g_variant_unref(p);
+        }
+      };
     };
 
+    // GVariantIter traits specialization.
     template<>
     struct traits<GVariantIter>
     {
-      static void release(GVariantIter * p) { g_variant_iter_free(p); }
+      // Functor to be used in std::unique_ptr<> specialization.
+      struct delete_functor
+      {
+        void
+        operator()(GVariantIter * p) const
+        {
+          g_variant_iter_free(p);
+        }
+      };
     };
 
+    // gchar traits specialization.
     template<>
     struct traits<gchar>
     {
-      static void release(gchar * p) { g_free(p); }
+      struct delete_functor
+      {
+        void
+        operator()(gchar * p) const
+        {
+          g_free(p);
+        }
+      };
     };
 
+    // GError traits specialization.
     template<>
     struct traits<GError>
     {
-      static void release(GError * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_error_free(p);
-      }
+        void
+        operator()(GError * p) const
+        {
+          if (p != nullptr)
+            g_error_free(p);
+        }
+      };
     };
 
+    // GMainLoop traits specialization.
     template<>
     struct traits<GMainLoop>
     {
-      static void release(GMainLoop * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_main_loop_unref(p);
-      }
+        void
+        operator()(GMainLoop * p) const
+        {
+          if (p != nullptr)
+            g_main_loop_unref(p);
+        }
+      };
     };
 
   }
 }
 
 
+
 #endif /* IVI_SETTINGS_GLIB_TRAITS_HPP */
 
 
index ab627e4..427265f 100644 (file)
@@ -3,6 +3,8 @@
  *
  * @brief @c JSON-GLib traits.
  *
+ * This header contains traits specific to JSON-GLib types.
+ *
  * @author Ossama Othman @<ossama.othman@@intel.com@>
  *
  * @copyright @par
@@ -34,56 +36,71 @@ namespace ivi
 {
   namespace settings
   {
+    /**
+     * @struct gobject_delete_functor
+     *
+     * @brief Release @c GObject subclasses.
+     *
+     * This functor is used to release @c GObject classes.  It may be
+     * used anywhere a C++ functor with a function call operator of
+     * the form:
+     *    @c void operator()(T * p) const
+     * is required, such as for the @c std::unique_ptr<> "@c deleter"
+     * template or constructor parameter.
+     */
+    template<typename T>
+    struct gobject_delete_functor
+    {
+      void
+      operator()(T * p) const
+      {
+        if (p != nullptr)
+          g_object_unref(G_OBJECT(p));
+      }
+    };
+
     template<typename T> struct traits;
 
+    // JsonNode traits specialization.
     template<>
     struct traits<JsonNode>
     {
-      static void release(JsonNode * p) { json_node_free(p); }
+      struct delete_functor
+      {
+        void
+        operator()(JsonNode * p) const
+        {
+          json_node_free(p);
+        }
+      };
     };
 
+    // JsonParser traits specialization.
     template<>
     struct traits<JsonParser>
     {
-      static void
-      release(JsonParser * p)
-      {
-        if (p != nullptr)
-          g_object_unref(p);
-      }
+      typedef gobject_delete_functor<JsonParser> delete_functor;
     };
 
+    // JsonReader traits specialization.
     template<>
     struct traits<JsonReader>
     {
-      static void
-      release(JsonReader * p)
-      {
-        if (p != nullptr)
-          g_object_unref(p);
-      }
+      typedef gobject_delete_functor<JsonReader> delete_functor;
     };
 
+    // JsonBuilder traits specialization.
     template<>
     struct traits<JsonBuilder>
     {
-      static void
-      release(JsonBuilder * p)
-      {
-        if (p != nullptr)
-          g_object_unref(p);
-      }
+      typedef gobject_delete_functor<JsonBuilder> delete_functor;
     };
 
+    // JsonGenerator traits specialization.
     template<>
     struct traits<JsonGenerator>
     {
-      static void
-      release(JsonGenerator * p)
-      {
-        if (p != nullptr)
-          g_object_unref(p);
-      }
+      typedef gobject_delete_functor<JsonGenerator> delete_functor;
     };
 
   }
index 9019aa4..02936ef 100644 (file)
@@ -39,8 +39,6 @@ namespace ivi
 {
   namespace settings
   {
-    template<typename T> class smart_ptr;
-
     /**
      * @class response_callback response_callback.hpp <settingsd/response_callback.hpp>
      *
@@ -117,12 +115,12 @@ namespace ivi
        *
        * @param[in] result @c "succeeded" or @c "failed"
        */
-      smart_ptr<JsonBuilder> begin_response(char const * result);
+      unique_ptr<JsonBuilder> begin_response(char const * result);
 
       /**
        * End the JSON formatted response to the Settings app request.
        */
-      void end_response(smart_ptr<JsonBuilder> const & builder);
+      void end_response(unique_ptr<JsonBuilder> const & builder);
 
     private:
 
index bb0de5c..e0af875 100644 (file)
 #ifndef IVI_SETTINGS_SEND_CALLBACK_HPP
 #define IVI_SETTINGS_SEND_CALLBACK_HPP
 
+#include <settingsd/json_glib_traits.hpp>
+#include <settingsd/unique_ptr.hpp>
+
 #include <libwebsockets.h>
-#include <json-glib/json-glib.h>
 
 
 namespace ivi
 {
   namespace settings
   {
-    template<typename T> class smart_ptr;
-
     /**
      * @class send_callback
      *
@@ -72,7 +72,7 @@ namespace ivi
        *                      pre-marshalled (in-memory) payload.
        */
       bool send_payload(char const * send_type,
-                        smart_ptr<JsonBuilder> const & builder);
+                        unique_ptr<JsonBuilder> const & builder);
 
       /**
        * Check if the WebSocket instance @a wsi corresponds to this
diff --git a/include/settingsd/smart_ptr.hpp b/include/settingsd/smart_ptr.hpp
deleted file mode 100644 (file)
index aeb47f3..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-/**
- * @file smart_ptr.hpp
- *
- * @brief C++11 style smart pointer for use by settings plug-ins.
- *
- * @author Ossama Othman @<ossama.othman@@intel.com@>
- *
- * @copyright @par
- * Copyright 2013 Intel Corporation All Rights Reserved.
- * @par
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- * @par
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * @par
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA  02110-1301  USA
- */
-
-#ifndef IVI_SETTINGS_SMART_PTR_HPP
-#define IVI_SETTINGS_SMART_PTR_HPP
-
-#include <cstddef>
-#include <utility>
-#include <functional>
-
-
-namespace ivi
-{
-  namespace settings
-  {
-    /**
-     * @class smart_ptr
-     *
-     * @brief C++11 style smart pointer for use by settings plug-ins.
-     *
-     * This class exposes a C++11-style smart pointer interface to
-     * allow RAII based handling of resources provided by third party
-     * libraries, such as Glib.  Core functionality is implemented in
-     * traits that this class template leverages.
-     */
-    template<typename T>
-    class smart_ptr
-    {
-    public:
-      typedef T *       pointer;
-      typedef T         element_type;
-      typedef traits<T> traits_type;
-
-      constexpr smart_ptr() : p_(nullptr) {}
-
-      constexpr smart_ptr(std::nullptr_t) : p_(nullptr) {}
-
-      explicit smart_ptr(pointer p) : p_(p) {}
-
-      smart_ptr(smart_ptr&& u) : p_(u.p_) { u.p_ = nullptr; }
-
-      ~smart_ptr() { traits_type::release(p_); }
-
-      smart_ptr &
-      operator=(smart_ptr && r)
-      {
-        if (this != &r) {
-          smart_ptr<T> tmp(r);
-          swap(tmp);
-        }
-
-        return *this;
-      }
-
-      smart_ptr &
-      operator=(std::nullptr_t)
-      {
-        reset(nullptr);
-
-        return *this;
-      }
-
-      pointer
-      release()
-      {
-        pointer const old = p_;
-        p_ = nullptr;
-
-        return old;
-      }
-
-      void
-      reset(pointer p = pointer())
-      {
-        smart_ptr<T> tmp(p);
-        swap(tmp);
-      }
-
-      void swap(smart_ptr& other) { std::swap(p_, other.p_); }
-
-      pointer get() const { return p_; }
-
-      explicit operator bool() const { return p_ != nullptr; }
-
-      typename std::add_lvalue_reference<T>::type
-      operator*() const
-      {
-        /**
-         * @todo Throw exception if @c p_ @c == @c nullptr.
-         */
-        return *p_;
-      }
-
-      pointer operator->() const { return p_; }
-
-    private:
-
-      /**
-       * @name Prevent copying
-       */
-      //@{
-      smart_ptr(smart_ptr const &) = delete;
-      smart_ptr & operator=(smart_ptr const &) = delete;
-      //@}
-
-    private:
-
-      /// Pointer to the object being managed.
-      T * p_;
-
-    };
-
-    template<typename T1, typename T2>
-    bool
-    operator==(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      return x.get() == y.get();
-    }
-
-    template<typename T1, typename T2>
-    bool
-    operator!=(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      return x.get() != y.get();
-    }
-
-    template<typename T1, typename T2>
-    bool
-    operator<(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      typedef typename
-        std::common_type<typename smart_ptr<T1>::pointer,
-                         typename smart_ptr<T2>::pointer>::type type;
-
-      return std::less<type>()(x.get(), y.get());
-    }
-
-
-    template<typename T1, typename T2>
-    bool operator<=(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      return !(y < x);
-    }
-
-    template<typename T1, typename T2>
-    bool
-    operator>(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      return (y < x);
-    }
-
-    template<typename T1, typename T2>
-    bool
-    operator>=(smart_ptr<T1> const & x, smart_ptr<T2> const & y)
-    {
-      return !(x < y);
-    }
-
-    template<typename T>
-    bool
-    operator==(smart_ptr<T> const & x, std::nullptr_t) noexcept
-    {
-      return !x;
-    }
-
-    template<typename T>
-    bool
-    operator==(std::nullptr_t, smart_ptr<T> const & x) noexcept
-    {
-      return !x;
-    }
-
-    template<typename T>
-    bool
-    operator!=(smart_ptr<T> const & x, std::nullptr_t) noexcept
-    {
-      return static_cast<bool>(x);
-    }
-
-    template<typename T>
-    bool
-    operator!=(std::nullptr_t, smart_ptr<T> const & x) noexcept
-    {
-      return static_cast<bool>(x);
-    }
-
-    template<typename T>
-    bool
-    operator<(smart_ptr<T> const & x, std::nullptr_t)
-    {
-      return std::less<typename smart_ptr<T>::pointer>()(x.get(), nullptr);
-    }
-
-    template<typename T>
-    bool
-    operator<(std::nullptr_t, smart_ptr<T> const & y)
-    {
-      return std::less<typename smart_ptr<T>::pointer>()(nullptr, y.get());
-    }
-
-    template<typename T>
-    bool
-    operator<=(smart_ptr<T> const & x, std::nullptr_t)
-    {
-      return nullptr < x;
-    }
-
-    template<typename T>
-    bool
-    operator<=(std::nullptr_t, smart_ptr<T> const & y)
-    {
-      return y < nullptr;
-    }
-
-    template<typename T>
-    bool
-    operator>(smart_ptr<T> const & x, std::nullptr_t)
-    {
-      return !(nullptr < x);
-    }
-
-    template<typename T>
-    bool
-    operator>(std::nullptr_t, smart_ptr<T> const & y)
-    {
-      return !(y < nullptr);
-    }
-
-    template<typename T>
-    bool
-    operator>=(smart_ptr<T> const & x, std::nullptr_t)
-    {
-      return !(x < nullptr);
-    }
-
-    template<typename T>
-    bool
-    operator>=(std::nullptr_t, smart_ptr<T> const & y)
-    {
-      return !(nullptr < y);
-    }
-
-  }
-}
-
-namespace std
-{
-  template<typename T>
-  void
-  swap(ivi::settings::smart_ptr<T> & lhs,
-       ivi::settings::smart_ptr<T> & rhs)
-  {
-    lhs.swap(rhs);
-  }
-
-  template<typename T>
-  struct hash<ivi::settings::smart_ptr<T>>
-  {
-    typedef ivi::settings::smart_ptr<T> argument_type;
-    typedef std::size_t                 result_type;
-
-    hash();
-
-    result_type
-      operator()(argument_type const & p) const
-    {
-      typedef typename argument_type::pointer key_type;
-
-      return hash<key_type>(p.get());
-    }
-  };
-}
-
-#endif /* IVI_SETTINGS_SMART_PTR_HPP */
-
-
-// Local Variables:
-// mode:c++
-// c-basic-offset:2
-// indent-tabs-mode: nil
-// End:
diff --git a/include/settingsd/unique_ptr.hpp b/include/settingsd/unique_ptr.hpp
new file mode 100644 (file)
index 0000000..de6d3fd
--- /dev/null
@@ -0,0 +1,60 @@
+/**
+ * @file unique_ptr.hpp
+ *
+ * @brief C++11 style @c unique_ptr for use by settings plug-ins.
+ *
+ * @author Ossama Othman @<ossama.othman@@intel.com@>
+ *
+ * @copyright @par
+ * Copyright 2013 Intel Corporation All Rights Reserved.
+ * @par
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ * @par
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * @par
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef IVI_SETTINGS_UNIQUE_PTR_HPP
+#define IVI_SETTINGS_UNIQUE_PTR_HPP
+
+#include <memory>
+
+
+namespace ivi
+{
+  namespace settings
+  {
+    /**
+     * @typedef unique_ptr
+     *
+     * @brief C++11 style unique pointer for use by settings plug-ins.
+     *
+     * This type alias exposes a C++11-style @c unique_ptr interface
+     * to allow RAII based handling of resources provided by third
+     * party libraries, such as Glib.  Core functionality is
+     * implemented in traits that this type alias leverages.
+     */
+    template<typename T> using unique_ptr =
+      ::std::unique_ptr<T,
+                        typename traits<T>::delete_functor>;
+  }
+}
+
+#endif /* IVI_SETTINGS_UNIQUE_PTR_HPP */
+
+
+// Local Variables:
+// mode:c++
+// c-basic-offset:2
+// indent-tabs-mode: nil
+// End:
index 5ec7189..12cc69c 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <settingsd/event_callback.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 #include "manager.hpp"
 
 
@@ -39,7 +39,7 @@ bool
 ivi::settings::event_callback::send_event(
   std::function<void(JsonBuilder *)> event_builder)
 {
-  smart_ptr<JsonBuilder> const builder = begin_event();
+  unique_ptr<JsonBuilder> const builder = begin_event();
 
   // Append settings type-specific JSON formatted events.
   event_builder(builder.get());
@@ -49,11 +49,11 @@ ivi::settings::event_callback::send_event(
   return manager_.send_event(builder);
 }
 
-ivi::settings::smart_ptr<JsonBuilder>
+ivi::settings::unique_ptr<JsonBuilder>
 ivi::settings::event_callback::begin_event()
 {
   // Construct JSON event string.
-  smart_ptr<JsonBuilder> safe_builder(json_builder_new());
+  unique_ptr<JsonBuilder> safe_builder(json_builder_new());
   JsonBuilder * const builder = safe_builder.get();
 
   json_builder_begin_object(builder);
@@ -66,7 +66,7 @@ ivi::settings::event_callback::begin_event()
 
 void
 ivi::settings::event_callback::end_event(
-  ivi::settings::smart_ptr<JsonBuilder> const & builder)
+  ivi::settings::unique_ptr<JsonBuilder> const & builder)
 {
   json_builder_end_object(builder.get());
 }
index 22c431f..5ca8d2b 100644 (file)
@@ -30,7 +30,7 @@
 #include <settingsd/plugin.hpp>
 #include <settingsd/response_callback.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <gmodule.h>
 
@@ -137,11 +137,11 @@ ivi::settings::manager::dispatch(std::string request,
     return;
   }
 
-  smart_ptr<JsonParser> const parser(json_parser_new());
+  unique_ptr<JsonParser> const parser(json_parser_new());
   json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr);
 
   JsonReader * const reader = json_reader_new(json_parser_get_root(parser.get()));
-  smart_ptr<JsonReader> const safe_reader(reader);
+  unique_ptr<JsonReader> const safe_reader(reader);
 
   // Retrieve setting name and transcation ID from the JSON request
   // string.
@@ -210,7 +210,7 @@ ivi::settings::manager::unsubscribe_client(libwebsocket * wsi)
 
 bool
 ivi::settings::manager::send_event(
-  smart_ptr<JsonBuilder> const & builder)
+  unique_ptr<JsonBuilder> const & builder)
 {
   bool success = true;
 
index 373e097..aea12fd 100644 (file)
@@ -103,7 +103,7 @@ namespace ivi
        *
        * @return @c true on success.
        */
-      bool send_event(smart_ptr<JsonBuilder> const & builder);
+      bool send_event(unique_ptr<JsonBuilder> const & builder);
 
     private:
 
index 4d2ef40..24bf616 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <settingsd/response_callback.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 
 ivi::settings::response_callback::response_callback(
@@ -52,7 +52,7 @@ bool
 ivi::settings::response_callback::send_response(
   std::function<void(JsonBuilder *)> response_builder)
 {
-  smart_ptr<JsonBuilder> const builder = begin_response("succeeded");
+  unique_ptr<JsonBuilder> const builder = begin_response("succeeded");
 
   // Append successful Settings app results to the JSON formatted
   // response.
@@ -75,7 +75,7 @@ ivi::settings::response_callback::send_response(
 bool
 ivi::settings::response_callback::send_error(std::string error_message)
 {
-  smart_ptr<JsonBuilder> builder = begin_response("failed");
+  unique_ptr<JsonBuilder> builder = begin_response("failed");
 
   json_builder_set_member_name(builder.get(), "reason");;
   json_builder_add_string_value(builder.get(), error_message.c_str());
@@ -107,11 +107,11 @@ ivi::settings::response_callback::add_string_value(
     json_builder_add_string_value(builder, value.c_str());
 }
 
-ivi::settings::smart_ptr<JsonBuilder>
+ivi::settings::unique_ptr<JsonBuilder>
 ivi::settings::response_callback::begin_response(char const * result)
 {
   // Construct JSON response.
-  smart_ptr<JsonBuilder> safe_builder(json_builder_new());
+  unique_ptr<JsonBuilder> safe_builder(json_builder_new());
   JsonBuilder * const builder = safe_builder.get();
 
   json_builder_begin_object(builder);
@@ -127,7 +127,7 @@ ivi::settings::response_callback::begin_response(char const * result)
 
 void
 ivi::settings::response_callback::end_response(
-  ivi::settings::smart_ptr<JsonBuilder> const & builder)
+  ivi::settings::unique_ptr<JsonBuilder> const & builder)
 {
   json_builder_end_object(builder.get());
 }
index 50453ad..9330f8e 100644 (file)
@@ -27,7 +27,7 @@
 #include <settingsd/send_callback.hpp>
 #include <settingsd/glib_traits.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <cstring>
 #include <vector>
@@ -56,16 +56,16 @@ ivi::settings::send_callback::operator=(send_callback const & other)
 bool
 ivi::settings::send_callback::send_payload(
   char const * send_type,
-  smart_ptr<JsonBuilder> const & builder)
+  unique_ptr<JsonBuilder> const & builder)
 {
-  smart_ptr<JsonGenerator> const generator(json_generator_new());
-  smart_ptr<JsonNode> const root(json_builder_get_root(builder.get()));
+  unique_ptr<JsonGenerator> const generator(json_generator_new());
+  unique_ptr<JsonNode> const root(json_builder_get_root(builder.get()));
   json_generator_set_root(generator.get(), root.get());
 
   gchar * const data =
     json_generator_to_data(generator.get(), nullptr);
 
-  smart_ptr<gchar> safe_data(data);
+  unique_ptr<gchar> safe_data(data);
 
   if (data == nullptr) {
     g_critical("Unable to generate JSON formatted %s payload:\n",
index 3cd8c49..8d739cd 100644 (file)
@@ -29,7 +29,7 @@
 #include <settingsd/response_callback.hpp>
 #include <settingsd/glib_traits.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <cstring>
 #include <boost/lexical_cast.hpp>
@@ -56,13 +56,13 @@ void
 ivi::settings::clock::handle_request(std::string request,
                                      response_callback response)
 {
-  smart_ptr<JsonParser> const parser(json_parser_new());
+  unique_ptr<JsonParser> const parser(json_parser_new());
   json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr);
 
   JsonReader * const reader =
     json_reader_new(json_parser_get_root(parser.get()));
 
-  smart_ptr<JsonReader> safe_reader(reader);
+  unique_ptr<JsonReader> safe_reader(reader);
 
   char const * name = nullptr;
   if (json_reader_read_member(reader, "name")) {
@@ -91,7 +91,7 @@ ivi::settings::clock::handle_request(std::string request,
         "Unrecognized " + id() + " request name: " + name);
     }
 
-    smart_ptr<GError> safe_error(error);
+    unique_ptr<GError> safe_error(error);
 
     if (success) {
 
@@ -196,7 +196,7 @@ ivi::settings::clock::set_updates(char const * name,
                            ? "<invalid_string>"
                            : updates));
   } else {
-    smart_ptr<GVariant> const current_value(get_property(name, error));
+    unique_ptr<GVariant> const current_value(get_property(name, error));
 
     if (current_value != nullptr) {
       char const * value =
@@ -235,7 +235,7 @@ ivi::settings::clock::is_updates_auto(char const * name,
     return;
   }
 
-  smart_ptr<GVariant> const current_value(get_property(name, error));
+  unique_ptr<GVariant> const current_value(get_property(name, error));
 
   if (current_value != nullptr) {
     char const * value =
@@ -258,7 +258,7 @@ ivi::settings::clock::set_property(char const * name,
                                    response_callback /* response */,
                                    GError *& error)
 {
-  smart_ptr<GVariant> const ret(
+  unique_ptr<GVariant> const ret(
     connman_.set_property(name, value, error));
 
   return ret.get() != nullptr;
@@ -270,7 +270,7 @@ ivi::settings::clock::get_property(char const * property,
 {
   constexpr gint const timeout = 5000;  // milliseconds
 
-  smart_ptr<GVariant> const dictionary(
+  unique_ptr<GVariant> const dictionary(
     g_dbus_proxy_call_sync(connman_.proxy(),
                            "GetProperties",
                            nullptr,  // No parameters
@@ -279,18 +279,18 @@ ivi::settings::clock::get_property(char const * property,
                            nullptr,  // Not cancellable
                            &error));
 
-  smart_ptr<GVariant> value;
+  unique_ptr<GVariant> value;
 
   if (dictionary != nullptr) {
     GVariantIter * i = nullptr;
     g_variant_get(dictionary.get(), "(a{sv})", &i);
-    smart_ptr<GVariantIter> const iter(i);
+    unique_ptr<GVariantIter> const iter(i);
 
     gchar    * pname  = nullptr;
     GVariant * pvalue = nullptr;
 
     while (g_variant_iter_next(i, "{sv}", &pname, &pvalue)) {
-      smart_ptr<gchar> const name(pname);
+      unique_ptr<gchar> const name(pname);
       value.reset(pvalue);
 
       // Check if this is the property we want.
index 2367310..d0a827e 100644 (file)
@@ -27,7 +27,7 @@
 #include "connman.hpp"
 
 #include <settingsd/glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 #include <settingsd/dbus_signal_callback.hpp>
 
 #include <cstring>
@@ -56,7 +56,7 @@ ivi::settings::connman::connman(char const * interface,
                                    nullptr, // GCancellable
                                    &error);
 
-  smart_ptr<GError> safe_error(error);
+  unique_ptr<GError> safe_error(error);
 
   if (proxy_ == nullptr) {
     g_printerr("Unable to create D-Bus proxy for (\"%s\", \"%s\"): %s\n",
index a6449d7..cda4ee7 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <settingsd/dbus_signal_callback.hpp>
 #include <settingsd/glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <cstring>
 
@@ -76,7 +76,7 @@ ivi::settings::connman_manager::get_properties(
 {
   constexpr gint const timeout = 5000;  // milliseconds
 
-  smart_ptr<GVariant> const dictionary(
+  unique_ptr<GVariant> const dictionary(
     g_dbus_proxy_call_sync(connman_.proxy(),
                            "GetTechnologies",
                            nullptr,  // No parameters
@@ -88,14 +88,14 @@ ivi::settings::connman_manager::get_properties(
   if (dictionary != nullptr) {
     GVariantIter * i = nullptr;
     g_variant_get(dictionary.get(), "(a(oa{sv}))", &i);
-    smart_ptr<GVariantIter> const safe_i(i);
+    unique_ptr<GVariantIter> const safe_i(i);
 
-    for (smart_ptr<GVariant> child(g_variant_iter_next_value(i));
+    for (unique_ptr<GVariant> child(g_variant_iter_next_value(i));
          child != nullptr;
          child.reset(g_variant_iter_next_value(i))) {
 
       // The object path is the first tuple element.
-      smart_ptr<GVariant> const tmp(
+      unique_ptr<GVariant> const tmp(
         g_variant_get_child_value(child.get(), 0));
 
       char const * object =
index 968dd2d..1f7bf82 100644 (file)
@@ -27,7 +27,7 @@
 #include "service.hpp"
 
 #include <settingsd/glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 #include <settingsd/response_callback.hpp>
 
 #include <chrono>
@@ -60,7 +60,7 @@ ivi::settings::service::call_method(char const * name,
   constexpr gint const timeout = 10000;  // milliseconds
   GError * error = nullptr;
 
-  smart_ptr<GVariant> const ret(
+  unique_ptr<GVariant> const ret(
     g_dbus_proxy_call_sync(connman_.proxy(),
                            name,     // "Connect", "Disconect", ...
                            nullptr,  // No parameters
@@ -69,7 +69,7 @@ ivi::settings::service::call_method(char const * name,
                            nullptr,  // Not cancellable
                            &error));
 
-  smart_ptr<GError> safe_error;
+  unique_ptr<GError> safe_error;
 
   if (ret != nullptr) {
     // Nothing to add to successful response.
index 325b165..92a25c0 100644 (file)
@@ -31,7 +31,7 @@
 #include <settingsd/response_callback.hpp>
 #include <settingsd/glib_traits.hpp>
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <cstring>
 #include <chrono>
@@ -54,10 +54,10 @@ void
 ivi::settings::technology::handle_request(std::string request,
                                           response_callback response)
 {
-  smart_ptr<JsonParser> const parser(json_parser_new());
+  unique_ptr<JsonParser> const parser(json_parser_new());
   json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr);
 
-  smart_ptr<JsonReader> const safe_reader(
+  unique_ptr<JsonReader> const safe_reader(
     json_reader_new(json_parser_get_root(parser.get())));
   JsonReader * const reader = safe_reader.get();
 
@@ -108,7 +108,7 @@ ivi::settings::technology::get_powered(JsonReader * reader,
     return;
   }
 
-  smart_ptr<GVariant> const property(
+  unique_ptr<GVariant> const property(
     get_property("Powered", G_VARIANT_TYPE_BOOLEAN, response));
 
   if (property != nullptr) {
@@ -140,12 +140,12 @@ ivi::settings::technology::set_powered(JsonReader * reader,
 
   GError * error = nullptr;
 
-  smart_ptr<GVariant> ret(
+  unique_ptr<GVariant> ret(
     connman_.set_property(name,
                           g_variant_new_boolean(enable),
                           error));
 
-  smart_ptr<GError> safe_error(error);
+  unique_ptr<GError> safe_error(error);
 
   if (ret != nullptr) {
       // Nothing to add to successful response.
@@ -180,7 +180,7 @@ ivi::settings::technology::scan(JsonReader * reader,
   constexpr gint const timeout = 10000;  // milliseconds
   GError * error = nullptr;
 
-  smart_ptr<GVariant> const ret(
+  unique_ptr<GVariant> const ret(
     g_dbus_proxy_call_sync(connman_.proxy(),
                            "Scan",
                            nullptr,  // No parameters
@@ -189,7 +189,7 @@ ivi::settings::technology::scan(JsonReader * reader,
                            nullptr,  // Not cancellable
                            &error));
 
-  smart_ptr<GError> safe_error(error);
+  unique_ptr<GError> safe_error(error);
 
   if (ret != nullptr) {
     send_services(response, error);
@@ -246,7 +246,7 @@ void
 ivi::settings::technology::send_services(response_callback response,
                                          GError *& error)
 {
-  smart_ptr<GVariant> const services(manager_.get_services(error));
+  unique_ptr<GVariant> const services(manager_.get_services(error));
 
   if (services != nullptr) {
     response.send_response(
@@ -274,12 +274,12 @@ ivi::settings::technology::get_property(char const * name,
 {
   GError * error = nullptr;
 
-  smart_ptr<GVariant> const properties(
+  unique_ptr<GVariant> const properties(
     manager_.get_properties(technology_, error));
 
-  smart_ptr<GError> safe_error(error);
+  unique_ptr<GError> safe_error(error);
 
-  smart_ptr<GVariant> property;
+  unique_ptr<GVariant> property;
   if (properties != nullptr) {
     property.reset(
       g_variant_lookup_value(properties.get(), name, type));
index 18cf872..071d596 100644 (file)
@@ -29,7 +29,7 @@
 #include "websocket_server.hpp"
 
 #include <settingsd/glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <glib.h>
 #include <iostream>
@@ -59,7 +59,7 @@ main(int argc, char * argv[])
 
     // Glib related events, including GDbus related signal handlers,
     // will handled in this (main) thread.
-    settings::smart_ptr<GMainLoop> const loop(g_main_loop_new(nullptr, false));
+    settings::unique_ptr<GMainLoop> const loop(g_main_loop_new(nullptr, false));
     g_main_loop_run(loop.get());
   }
   catch (std::exception & e) {