[smart_ptr] Rename to ivi::settings::unique_ptr.
authorOssama Othman <ossama.othman@intel.com>
Sun, 13 Oct 2013 04:43:42 +0000 (21:43 -0700)
committerOssama Othman <ossama.othman@intel.com>
Sun, 13 Oct 2013 04:43:42 +0000 (21:43 -0700)
The name "smart_ptr" in the ivi::settings namespace does not
convey the actual semantics.  Rename to "unique_ptr" to better
reflect its C++11 std::unique_ptr<> style of behavior.

Change-Id: I0af30c6e3db88e08e0dcefe77206af1b3d4a255d
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
16 files changed:
include/settingsd/Makefile.am
include/settingsd/event_callback.hpp
include/settingsd/response_callback.hpp
include/settingsd/send_callback.hpp
include/settingsd/unique_ptr.hpp [moved from include/settingsd/smart_ptr.hpp with 76% similarity]
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 24b3371..910082a 100644 (file)
@@ -84,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 5646c8f..02936ef 100644 (file)
@@ -115,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 2a47ae7..e0af875 100644 (file)
@@ -31,7 +31,7 @@
 #define IVI_SETTINGS_SEND_CALLBACK_HPP
 
 #include <settingsd/json_glib_traits.hpp>
-#include <settingsd/smart_ptr.hpp>
+#include <settingsd/unique_ptr.hpp>
 
 #include <libwebsockets.h>
 
@@ -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
similarity index 76%
rename from include/settingsd/smart_ptr.hpp
rename to include/settingsd/unique_ptr.hpp
index d03aaef..de6d3fd 100644 (file)
@@ -1,7 +1,7 @@
 /**
- * @file smart_ptr.hpp
+ * @file unique_ptr.hpp
  *
- * @brief C++11 style smart pointer for use by settings plug-ins.
+ * @brief C++11 style @c unique_ptr for use by settings plug-ins.
  *
  * @author Ossama Othman @<ossama.othman@@intel.com@>
  *
@@ -24,8 +24,8 @@
  * Boston, MA  02110-1301  USA
  */
 
-#ifndef IVI_SETTINGS_SMART_PTR_HPP
-#define IVI_SETTINGS_SMART_PTR_HPP
+#ifndef IVI_SETTINGS_UNIQUE_PTR_HPP
+#define IVI_SETTINGS_UNIQUE_PTR_HPP
 
 #include <memory>
 
@@ -35,22 +35,22 @@ namespace ivi
   namespace settings
   {
     /**
-     * @typedef smart_ptr
+     * @typedef unique_ptr
      *
-     * @brief C++11 style smart pointer for use by settings plug-ins.
+     * @brief C++11 style unique pointer for use by settings plug-ins.
      *
-     * This type alias exposes a C++11-style smart pointer interface
+     * 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 smart_ptr =
+    template<typename T> using unique_ptr =
       ::std::unique_ptr<T,
                         typename traits<T>::delete_functor>;
   }
 }
 
-#endif /* IVI_SETTINGS_SMART_PTR_HPP */
+#endif /* IVI_SETTINGS_UNIQUE_PTR_HPP */
 
 
 // Local Variables:
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) {