[dbus_connection] Improved exception safety. 84/10984/2
authorOssama Othman <ossama.othman@intel.com>
Mon, 14 Oct 2013 22:58:17 +0000 (15:58 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 16 Oct 2013 21:59:35 +0000 (14:59 -0700)
Change-Id: I9dc39a6bab125c426107d9f742d2585b74cea75e
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
include/settingsd/glib_traits.hpp
plugins/connman/dbus_connection.cpp
plugins/connman/dbus_connection.hpp

index 8578b08..7fc4d9c 100644 (file)
@@ -38,6 +38,22 @@ namespace ivi
   {
     template<typename T> struct traits;
 
+    // GDBusConnection traits specialization.
+    template<>
+    struct traits<GDBusConnection>
+    {
+      struct delete_functor
+      {
+        void
+        operator()(GDBusConnection * p) const
+        {
+          if (p != nullptr)
+            g_object_unref(p);
+        }
+      };
+    };
+
+
     // GVariant traits specialization.
     template<>
     struct traits<GVariant>
@@ -57,7 +73,6 @@ namespace ivi
     template<>
     struct traits<GVariantIter>
     {
-      // Functor to be used in std::unique_ptr<> specialization.
       struct delete_functor
       {
         void
@@ -107,6 +122,7 @@ namespace ivi
         operator()(GMainLoop * p) const
         {
           if (p != nullptr)
+            g_main_loop_quit(p);
             g_main_loop_unref(p);
         }
       };
index bb8b0a9..c2e59b7 100644 (file)
@@ -38,7 +38,8 @@ ivi::settings::dbus_connection::dbus_connection()
 {
   GError * error = nullptr;
 
-  connection_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
+  connection_.reset(
+    g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
 
   if (connection_ == nullptr) {
     unique_ptr<GError> safe_error(error);
@@ -51,7 +52,7 @@ ivi::settings::dbus_connection::~dbus_connection()
   GError * error = nullptr;
 
   if (connection_ != nullptr
-      && !g_dbus_connection_close_sync(connection_,
+      && !g_dbus_connection_close_sync(connection_.get(),
                                        nullptr,
                                        &error)) {
     g_critical("D-Bus connection close failed: %s.\n",
index 62a25ec..4334489 100644 (file)
@@ -31,6 +31,9 @@
 
 #include <gio/gio.h>
 
+#include <settingsd/glib_traits.hpp>
+#include <settingsd/unique_ptr.hpp>
+
 
 namespace ivi
 {
@@ -50,7 +53,7 @@ namespace ivi
       GDBusConnection *
       connection()
       {
-        return connection_;
+        return connection_.get();
       }
 
     private:
@@ -66,7 +69,7 @@ namespace ivi
     private:
 
       /// Underlying connection to D-Bus system bus.
-      GDBusConnection * connection_;
+      unique_ptr<GDBusConnection> connection_;
 
     };
   }