Fix error handling inconsistency 16/248216/3
authorhyunho <hhstark.kang@samsung.com>
Tue, 24 Nov 2020 02:40:12 +0000 (11:40 +0900)
committerhyunho <hhstark.kang@samsung.com>
Thu, 26 Nov 2020 05:05:43 +0000 (14:05 +0900)
Change-Id: I19eed1e4d0ef264c9d157cdca5642c04e045b0a8
Signed-off-by: hyunho <hhstark.kang@samsung.com>
14 files changed:
notification-ex/dbus_event_listener.cc
notification-ex/dbus_sender.cc
notification-ex/dbus_sender.h
notification-ex/dbus_sender_implementation.h
notification-ex/event_sender_interface.h
notification-ex/ex_util.cc
notification-ex/ex_util.h
notification-ex/manager.cc
notification-ex/manager.h
notification-ex/manager_implementation.h
notification-ex/reporter.cc
notification-ex/reporter.h
notification-ex/reporter_implementation.h
notification-ex/stub.cc

index 954a634..fffed25 100644 (file)
@@ -71,46 +71,34 @@ uid_t DBusEventListener::Impl::GetSenderUid(GDBusConnection* connection,
   auto cp = cache.find(sender_name);
   if (cp != cache.end())
     return cp->second;
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+            g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+                DBUS_INTERFACE_NAME, "GetConnectionUnixUser"),
+            g_object_unref);
 
-  GDBusMessage* msg = nullptr;
-  GDBusMessage* reply = nullptr;
+  g_dbus_message_set_body(msg_ptr.get(), g_variant_new("(s)", sender_name));
   GError* err = nullptr;
-  GVariant* body;
-  uid_t uid = 0;
-
-  msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
-      DBUS_INTERFACE_NAME, "GetConnectionUnixUser");
-  if (!msg) {
-    LOGE("Failed to alloc new method call");
-    goto out;
-  }
-
-  g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
-  reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
-      G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
+      connection, msg_ptr.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr,
+      nullptr, &err);
 
   if (!reply) {
     if (err != nullptr) {
       LOGE("Failed to get uid [%s]", err->message);
       g_error_free(err);
     }
-    goto out;
+    THROW(ERROR_IO_ERROR);
   }
 
-  body = g_dbus_message_get_body(reply);
+  GVariant* body = g_dbus_message_get_body(reply);
+  uid_t uid = 0;
   g_variant_get(body, "(u)", &uid);
+  g_object_unref(reply);
 
   if (cache.size() >= MAX_CACHE_COUNT)
     cache.clear();
 
   cache[sender_name] = uid;
-
-out:
-  if (msg)
-    g_object_unref(msg);
-  if (reply)
-    g_object_unref(reply);
-
   return uid;
 }
 
@@ -121,45 +109,39 @@ pid_t DBusEventListener::Impl::GetSenderPid(GDBusConnection* connection,
   if (cp != cache.end())
     return cp->second;
 
-  GDBusMessage* msg = nullptr;
-  GDBusMessage* reply = nullptr;
-  GError* err = nullptr;
-  GVariant* body;
-  pid_t pid = 0;
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+            g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+                DBUS_INTERFACE_NAME, "GetConnectionUnixProcessID"),
+            g_object_unref);
 
-  msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
-      DBUS_INTERFACE_NAME, "GetConnectionUnixProcessID");
-  if (!msg) {
+  if (!msg_ptr || !msg_ptr.get()) {
     LOGE("Failed to alloc new method call");
-    goto out;
+    THROW(ERROR_OUT_OF_MEMORY);
   }
 
-  g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
-  reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
-      G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+  g_dbus_message_set_body(msg_ptr.get(), g_variant_new("(s)", sender_name));
+  GError* err = nullptr;
+  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
+      connection, msg_ptr.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1,
+      nullptr, nullptr, &err);
 
   if (!reply) {
     if (err != nullptr) {
       LOGE("Failed to get uid [%s]", err->message);
       g_error_free(err);
     }
-    goto out;
+    THROW(ERROR_IO_ERROR);
   }
 
-  body = g_dbus_message_get_body(reply);
+  GVariant* body = g_dbus_message_get_body(reply);
+  pid_t pid = 0;
   g_variant_get(body, "(u)", &pid);
+  g_object_unref(reply);
 
   if (cache.size() >= MAX_CACHE_COUNT)
     cache.clear();
 
   cache[sender_name] = pid;
-
-out:
-  if (msg)
-    g_object_unref(msg);
-  if (reply)
-    g_object_unref(reply);
-
   return pid;
 }
 
@@ -214,7 +196,7 @@ void DBusEventListener::Impl::SignalCb(GDBusConnection* connection,
       }
     }
     dl->parent_->NotifyObserver(info, ret_list);
-  } catch(Exception &ex) {
+  } catch(Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
   }
 }
@@ -391,7 +373,7 @@ void DBusEventListener::Impl::OnMethodCall(
             ERROR_IO_ERROR, "invalid operation");
       return;
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
     g_dbus_method_invocation_return_error(invocation, noti_ex_error_quark(),
             ERROR_IO_ERROR, "OnMethodCall fail");
index 36bce5c..89ea543 100644 (file)
@@ -28,6 +28,7 @@
 #include "notification-ex/event_info_internal.h"
 #include "notification-ex/ex_util.h"
 #include "notification-ex/socket_handler.h"
+#include "notification-ex/exception.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -58,7 +59,7 @@ DBusSender::~DBusSender() {
   LOGW("Destroyed");
 }
 
-bool DBusSender::Impl::EmitSignal(string bus_name, string signal_name,
+void DBusSender::Impl::EmitSignal(string bus_name, string signal_name,
     GVariant* data) {
   GError* err = nullptr;
   GDBusConnection* conn = DBusConnectionManager::GetInst().GetConnection();
@@ -70,21 +71,21 @@ bool DBusSender::Impl::EmitSignal(string bus_name, string signal_name,
   if (result == FALSE) {
     LOGE("g_dbus_connection_emit_signal() is failed. error(%s)",
         err ? err->message : "Unknown");
+    int err_code = util::ConvertDBusError(err->code);
     g_clear_error(&err);
-    return false;
+    THROW(err_code);
   }
 
   result = g_dbus_connection_flush_sync(conn, NULL, &err);
   if (result == FALSE) {
     LOGE("g_dbus_connection_flush_sync() is failed. error(%s)",
         err ? err->message : "Unknown");
+    int err_code = util::ConvertDBusError(err->code);
     g_clear_error(&err);
-    return false;
+    THROW(err_code);
   }
-
   LOGI("Successfully emit signal to %s, %s, %s",
       bus_name.c_str(), path_.c_str(), signal_name.c_str());
-  return true;
 }
 
 string DBusSender::Impl::GetBusName(string appid, string dest_appid) const {
@@ -104,40 +105,46 @@ void DBusSender::Notify(GVariantBuilder* builder,
   string bus_name = impl_->GetBusName(appid, dest_appid);
   LOGI("bus name %s, %s", dest_appid.c_str(), bus_name.c_str());
   impl_->EmitSignal(bus_name, signal_name, data);
-  g_variant_builder_unref(builder);
 }
 
 void DBusSender::Notify(const IEventInfo& info, list<Bundle> serialized,
     string dest_appid) {
-  GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+
+  std::unique_ptr<GVariantBuilder,
+      decltype(g_variant_builder_unref)*> builder_ptr(
+          g_variant_builder_new(G_VARIANT_TYPE("a(s)")),
+              g_variant_builder_unref);
   int idx = 0;
   for (auto& i : serialized) {
     if (idx != 0 && idx % 10 == 0) {
-      Notify(builder, info, dest_appid);
-      g_variant_builder_unref(builder);
-      builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+      Notify(builder_ptr.get(), info, dest_appid);
+      builder_ptr.reset(g_variant_builder_new(G_VARIANT_TYPE("a(s)")));
     }
-    g_variant_builder_add(builder, "(s)",
+    g_variant_builder_add(builder_ptr.get(), "(s)",
         reinterpret_cast<char*>(i.ToRaw().first.get()));
     idx++;
   }
-  Notify(builder, info, dest_appid);
+  Notify(builder_ptr.get(), info, dest_appid);
 }
 
-
-GDBusMessage* DBusSender::Impl::MethodCall(string appid, string method_name,
+int DBusSender::Impl::MethodCall(string appid, string method_name,
     Bundle serialized) {
-  GDBusMessage* msg = g_dbus_message_new_method_call(
-      DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
-      path_.c_str(),
-      DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
-      method_name.c_str());
-  if (!msg) {
+
+  std::string dpm_name = DBusConnectionManager::GetInst()
+      .GetDataProviderMasterName();
+  std::string interface_name = DBusConnectionManager::GetInst()
+      .GetInterfaceName();
+
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+            g_dbus_message_new_method_call(dpm_name.c_str(), path_.c_str(),
+                interface_name.c_str(), method_name.c_str()),
+            g_object_unref);
+  if (!msg_ptr || !msg_ptr.get()) {
     LOGE("Can't allocate new method call");
-    return nullptr;
+    THROW(ERROR_OUT_OF_MEMORY);
   }
 
-  g_dbus_message_set_body(msg,
+  g_dbus_message_set_body(msg_ptr.get(),
       g_variant_new("(ss)",
         appid.c_str(),
         reinterpret_cast<char*>(serialized.ToRaw().first.get())));
@@ -146,37 +153,45 @@ GDBusMessage* DBusSender::Impl::MethodCall(string appid, string method_name,
       path_.c_str(), method_name.c_str(), appid.c_str());
 
   GError* err = nullptr;
-  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
-      DBusConnectionManager::GetInst().GetConnection(), msg,
-      G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
+      g_dbus_connection_send_message_with_reply_sync(
+          DBusConnectionManager::GetInst().GetConnection(), msg_ptr.get(),
+          G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err),
+      g_object_unref);
   if (err != NULL) {
     LOGE("MethodCall, err[%s]", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-      set_last_result(ERROR_PERMISSION_DENIED);
-    else
-      set_last_result(ERROR_IO_ERROR);
+    int err_code = util::ConvertDBusError(err->code);
+    g_error_free(err);
+    THROW(err_code);
+  }
+
+  if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
+    LOGE("RequestReturnValue got error %s", err->message);
+    int err_code = util::ConvertDBusError(err->code);
     g_error_free(err);
+    THROW(err_code);
   }
 
-  g_object_unref(msg);
-  return reply;
+  int num;
+  GVariant *reply_body = g_dbus_message_get_body(reply_ptr.get());
+  g_variant_get(reply_body, "(i)", &num);
+  return num;
 }
 
-std::list<Bundle> DBusSender::Impl::MethodCallWithSocket(
+std::list<Bundle> DBusSender::Impl::GetListMethodCall(
     string appid, string method_name, Bundle serialized) {
   list<Bundle> ret_list;
   int fds[2];
   int ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds);
   if (ret < 0) {
-    LOGE("socketpair [%d]", ret);
-    return ret_list;
+    LOGE("socketpair fail [%d]", ret);
+    THROW(ERROR_IO_ERROR);
   }
   SocketHandler send_sock(fds[SEND_SOCK_IDX]);
   SocketHandler recv_sock(fds[RECV_SOCK_IDX]);
   std::unique_ptr<GUnixFDList, decltype(g_object_unref)*> fd_list_ptr(
           GetFdList(send_sock.Get()), g_object_unref);
 
-
   std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
       g_dbus_message_new_method_call(
           DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
@@ -186,7 +201,7 @@ std::list<Bundle> DBusSender::Impl::MethodCallWithSocket(
       g_object_unref);
   if (!msg_ptr || !msg_ptr.get()) {
     LOGE("Can't allocate new method call");
-    return ret_list;
+    THROW(ERROR_OUT_OF_MEMORY);
   }
 
   g_dbus_message_set_unix_fd_list(msg_ptr.get(), fd_list_ptr.get());
@@ -206,16 +221,26 @@ std::list<Bundle> DBusSender::Impl::MethodCallWithSocket(
       g_object_unref);
   if (err != NULL) {
     LOGE("MethodCall, err[%s]", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-      set_last_result(ERROR_PERMISSION_DENIED);
-    else
-      set_last_result(ERROR_IO_ERROR);
+    int err_code = util::ConvertDBusError(err->code);
     g_error_free(err);
-  } else if (CheckReplyMessage(reply_ptr.get()) == 0) {
+    THROW(err_code);
+  } else {
+    GError* err = nullptr;
+    if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
+      LOGE("Request got error %s", err->message);
+      int err_code = util::ConvertDBusError(err->code);
+      g_error_free(err);
+      THROW(err_code);
+    }
     GVariant *reply_body = g_dbus_message_get_body(reply_ptr.get());
     int cnt;
     g_variant_get(reply_body, "(i)", &cnt);
     ret_list = util::ReadBundleList(recv_sock.Get(), cnt);
+    if (ret_list.size() == 0)
+      THROW(ERROR_NOT_EXIST_ID);
+
+    if (static_cast<int>(ret_list.size()) != cnt)
+      THROW(ERROR_IO_ERROR);
   }
   return ret_list;
 }
@@ -233,13 +258,13 @@ GUnixFDList* DBusSender::Impl::GetFdList(int fd) {
   return fd_list;
 }
 
-GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
+void DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
     list<Bundle> serialized) {
   int fds[2];
   int ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds);
   if (ret < 0) {
-    LOGE("socketpair [%d]", ret);
-    return nullptr;
+    LOGE("socketpair fail [%d]", ret);
+    THROW(ERROR_IO_ERROR);
   }
 
   SocketHandler send_sock(fds[SEND_SOCK_IDX]);
@@ -248,18 +273,24 @@ GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
   auto fd_list_ptr = std::unique_ptr<GUnixFDList, decltype(g_object_unref)*>(
           fd_list, g_object_unref);
 
-  GDBusMessage* msg = g_dbus_message_new_method_call(
-      DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
-      path_.c_str(),
-      DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
-      EventInfo::GetString(info.GetEventType()).c_str());
-  if (!msg) {
+  std::string dpm_name = DBusConnectionManager::GetInst()
+      .GetDataProviderMasterName();
+  std::string interface_name = DBusConnectionManager::GetInst()
+      .GetInterfaceName();
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+      g_dbus_message_new_method_call(
+          dpm_name.c_str(),
+          path_.c_str(),
+          interface_name.c_str(),
+          EventInfo::GetString(info.GetEventType()).c_str()),
+      g_object_unref);
+  if (!msg_ptr || !msg_ptr.get()) {
     LOGE("Can't allocate new method call");
-    return nullptr;
+    THROW(ERROR_OUT_OF_MEMORY);
   }
 
-  g_dbus_message_set_unix_fd_list(msg, fd_list);
-  g_dbus_message_set_body(msg,
+  g_dbus_message_set_unix_fd_list(msg_ptr.get(), fd_list);
+  g_dbus_message_set_body(msg_ptr.get(),
       g_variant_new("(ssi)",
           appid.c_str(),
           reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()),
@@ -270,80 +301,45 @@ GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
       EventInfo::GetString(info.GetEventType()).c_str(), appid.c_str());
 
   GError* err = nullptr;
-  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
-      DBusConnectionManager::GetInst().GetConnection(), msg,
-      G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
-  if (err != NULL) {
+  std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
+      g_dbus_connection_send_message_with_reply_sync(
+          DBusConnectionManager::GetInst().GetConnection(), msg_ptr.get(),
+          G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err),
+      g_object_unref);
+  if (err != nullptr) {
     LOGE("MethodCall, err[%s]", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-      set_last_result(ERROR_PERMISSION_DENIED);
-    else
-      set_last_result(ERROR_IO_ERROR);
+    int err_code = util::ConvertDBusError(err->code);
     g_error_free(err);
-  } else {
-    for (auto& i : serialized) {
-      unsigned int data_size = static_cast<unsigned int>(
-          strlen(reinterpret_cast<char*>(i.ToRaw().first.get())));
-      int ret = util::WriteSocket(send_sock.Get(),
-          reinterpret_cast<char*>(&data_size), sizeof(data_size));
-      if (ret != 0)
-        break;
-      ret = util::WriteSocket(send_sock.Get(),
-          reinterpret_cast<char*>(i.ToRaw().first.get()), data_size);
-      if (ret != 0)
-        break;
-    }
+    THROW(err_code);
   }
 
-  g_object_unref(msg);
-  return reply;
-}
-
-int DBusSender::SendMessage(const IEventInfo& info, list<Bundle> serialized,
-    string dest_appid) {
-  string appid = info.GetOwner();
-  if (appid.length() == 0)
-    appid = util::GetAppId();
-
-  GDBusMessage* reply = impl_->MethodCall(appid, info, serialized);
-  if (!reply)
-    return ERROR_IO_ERROR;
-
-  int ret = ERROR_NONE;
-  GError* err = nullptr;
-  if (g_dbus_message_to_gerror(reply, &err)) {
+  if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
     LOGE("SendMessage got error %s", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED) {
-      set_last_result(ERROR_PERMISSION_DENIED);
-      ret = ERROR_PERMISSION_DENIED;
-    } else {
-      set_last_result(ERROR_IO_ERROR);
-      ret = ERROR_IO_ERROR;
-    }
+    int err_code = util::ConvertDBusError(err->code);
     g_error_free(err);
-    return ret;
-  } else {
-    set_last_result(ERROR_NONE);
+    THROW(err_code);
   }
 
-  return 0;
+  for (auto& i : serialized) {
+    unsigned int data_size = static_cast<unsigned int>(
+        strlen(reinterpret_cast<char*>(i.ToRaw().first.get())));
+    int ret = util::WriteSocket(send_sock.Get(),
+        reinterpret_cast<char*>(&data_size), sizeof(data_size));
+    if (ret != 0)
+      break;
+    ret = util::WriteSocket(send_sock.Get(),
+        reinterpret_cast<char*>(i.ToRaw().first.get()), data_size);
+    if (ret != 0)
+      break;
+  }
 }
 
-int DBusSender::Impl::CheckReplyMessage(GDBusMessage* reply) {
-  GError* err = nullptr;
-  if (g_dbus_message_to_gerror(reply, &err)) {
-    LOGE("Request got error %s", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-      set_last_result(ERROR_PERMISSION_DENIED);
-    else
-      set_last_result(ERROR_IO_ERROR);
-
-    g_error_free(err);
-    return -1;
-  } else {
-    set_last_result(ERROR_NONE);
-  }
-  return 0;
+void DBusSender::SendMessage(const IEventInfo& info, list<Bundle> serialized,
+    string dest_appid) {
+  string appid = info.GetOwner();
+  if (appid.length() == 0)
+    appid = util::GetAppId();
+  impl_->MethodCall(appid, info, serialized);
 }
 
 std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
@@ -353,7 +349,7 @@ std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
 
   string method_name = EventInfo::GetString(info.GetEventType());
   Bundle serialized = info.Serialize();
-  return impl_->MethodCallWithSocket(appid, method_name, serialized);
+  return impl_->GetListMethodCall(appid, method_name, serialized);
 }
 
 int DBusSender::RequestReturnValue(const IEventInfo& info) {
@@ -363,32 +359,7 @@ int DBusSender::RequestReturnValue(const IEventInfo& info) {
 
   string method_name = EventInfo::GetString(info.GetEventType());
   Bundle serialized = info.Serialize();
-
-  GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
-  if (!reply)
-    return 0;
-
-  auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
-      reply, g_object_unref);
-
-  GError* err = nullptr;
-  if (g_dbus_message_to_gerror(reply, &err)) {
-    LOGE("RequestReturnValue got error %s", err->message);
-    if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-      set_last_result(ERROR_PERMISSION_DENIED);
-    else
-      set_last_result(ERROR_IO_ERROR);
-
-    g_error_free(err);
-    return 0;
-  } else {
-    set_last_result(ERROR_NONE);
-  }
-
-  int num;
-  GVariant *reply_body = g_dbus_message_get_body(reply);
-  g_variant_get(reply_body, "(i)", &num);
-  return num;
+  return impl_->MethodCall(appid, method_name, serialized);
 }
 
 }  // namespace notification
index 2198459..4614416 100644 (file)
@@ -37,7 +37,7 @@ class EXPORT_API DBusSender : public IEventSender {
   virtual ~DBusSender();
   void Notify(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
       std::string dest_appid = "") override;
-  int SendMessage(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
+  void SendMessage(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
       std::string dest_appid = "") override;
   std::list<tizen_base::Bundle> Request(const IEventInfo& info) override;
   int RequestReturnValue(const IEventInfo& info) override;
index 7d1c501..f701fa8 100644 (file)
@@ -39,16 +39,15 @@ class DBusSender::Impl {
  private:
   std::string GetBusName(
       std::string appid, std::string dest_appid) const;
-  bool EmitSignal(std::string bus_name,
+  void EmitSignal(std::string bus_name,
       std::string signal_name, GVariant* data);
-  GDBusMessage* MethodCall(std::string appid, std::string method_name,
+  int MethodCall(std::string appid, std::string method_name,
       tizen_base::Bundle serialized);
-  GDBusMessage* MethodCall(std::string appid, const IEventInfo& info,
+  void MethodCall(std::string appid, const IEventInfo& info,
       std::list<tizen_base::Bundle> serialized);
-  std::list<tizen_base::Bundle> MethodCallWithSocket(std::string appid,
+  std::list<tizen_base::Bundle> GetListMethodCall(std::string appid,
       std::string method_name, tizen_base::Bundle serialized);
   GUnixFDList* GetFdList(int fd);
-  int CheckReplyMessage(GDBusMessage* reply);
   std::string path_;
   DBusSender* parent_;
 };
index ed2e965..ad1cd72 100644 (file)
@@ -36,7 +36,7 @@ class EXPORT_API IEventSender {
   virtual void Notify(const IEventInfo& info,
       std::list<tizen_base::Bundle> serialized,
       std::string dest_appid = "") = 0;
-  virtual int SendMessage(const IEventInfo& info,
+  virtual void SendMessage(const IEventInfo& info,
       std::list<tizen_base::Bundle> serialized,
       std::string dest_appid = "") = 0;
   virtual std::list<tizen_base::Bundle> Request(const IEventInfo& info) = 0;
index 2b796e5..d961c5b 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "notification-ex/ex_util.h"
 #include "notification-ex/socket_handler.h"
+#include "notification-ex/common.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -289,6 +290,13 @@ int WriteSocket(int fd, const char* buffer, unsigned int nbytes) {
   return 0;
 }
 
+int ConvertDBusError(int error) {
+  if (error == G_DBUS_ERROR_ACCESS_DENIED)
+    return ERROR_PERMISSION_DENIED;
+
+  return ERROR_IO_ERROR;
+}
+
 
 }  // namespace util
 }  // namespace notification
index 1906695..0c36226 100644 (file)
@@ -37,6 +37,7 @@ namespace util {
   unsigned int ReadSocket(int fd, char* buffer, unsigned int nbytes);
   int WriteSocket(int fd, const char* buffer, unsigned int nbytes);
   std::list<tizen_base::Bundle> ReadBundleList(int recvfd, int noti_cnt);
+  int ConvertDBusError(int error);
 }  // namespace util
 }  // namespace notification
 
index b5e243d..36cf000 100644 (file)
@@ -28,6 +28,7 @@
 #include "notification-ex/ex_util.h"
 #include "notification-ex/item_info_internal.h"
 #include "notification-ex/null_item.h"
+#include "notification-ex/exception.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -71,17 +72,6 @@ Manager::Impl::Impl(Manager* parent,
   sender_->RequestReturnValue(info);
 }
 
-int Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
-    IEventInfo::EventType type) {
-  Bundle serialized = noti->Serialize();
-  EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId());
-  list<Bundle> serialized_list {serialized};
-
-  /* Reply to Sender */
-  sender_->Notify(info, serialized_list, noti->GetSenderAppId());
-  return info.GetRequestId();
-}
-
 void Manager::SendError(const IEventInfo& info, NotificationError error) {
   list<Bundle> serialized_list {};
   IEventInfo& i = const_cast<IEventInfo&>(info);
@@ -90,44 +80,42 @@ void Manager::SendError(const IEventInfo& info, NotificationError error) {
   impl_->sender_->Notify(info, serialized_list, info.GetOwner());
 }
 
-int Manager::Update(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Update(shared_ptr<item::AbstractItem> noti) {
   Bundle serialized = noti->Serialize();
   EventInfo info(
       EventInfo::Update, util::GetAppId(), noti->GetChannel(), noti->GetId());
   list<Bundle> serialized_list {serialized};
-
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(
+  impl_->sender_->SendMessage(
       info, serialized_list, noti->GetSenderAppId());
+  return info.GetRequestId();
 }
 
-int Manager::Delete(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Delete(shared_ptr<item::AbstractItem> noti) {
   Bundle serialized = noti->Serialize();
   EventInfo info(
       EventInfo::Delete, util::GetAppId(), noti->GetChannel(), noti->GetId());
   list<Bundle> serialized_list {serialized};
-
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(
+  impl_->sender_->SendMessage(
       info, serialized_list, noti->GetSenderAppId());
+  return info.GetRequestId();
 }
 
-int Manager::DeleteAll(int& request_id) {
+int Manager::DeleteAll() {
   EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
-  request_id = info.GetRequestId();
-  return impl_->sender_->RequestReturnValue(info);
+  impl_->sender_->RequestReturnValue(info);
+  return info.GetRequestId();
 }
 
-int Manager::DeleteByChannel(string channel, int& request_id) {
+int Manager::DeleteByChannel(string channel) {
   EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
-  request_id = info.GetRequestId();
-  return impl_->sender_->RequestReturnValue(info);
+  impl_->sender_->RequestReturnValue(info);
+  return info.GetRequestId();
 }
 
-int Manager::DeleteByAppId(string appId, int& request_id) {
+int Manager::DeleteByAppId(string appId) {
   EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "", appId);
-  request_id = info.GetRequestId();
-  return impl_->sender_->RequestReturnValue(info);
+  impl_->sender_->RequestReturnValue(info);
+  return info.GetRequestId();
 }
 
 int Manager::GetCount() const {
@@ -135,7 +123,7 @@ int Manager::GetCount() const {
   return impl_->sender_->RequestReturnValue(info);
 }
 
-int Manager::Hide(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Hide(shared_ptr<item::AbstractItem> noti) {
   (reinterpret_cast<IItemInfoInternal*>(noti->GetInfo().get()))
       ->AddHideViewer(util::GetAppId());
 
@@ -143,19 +131,14 @@ int Manager::Hide(shared_ptr<item::AbstractItem> noti, int& request_id) {
       EventInfo::Update, util::GetAppId(), noti->GetChannel(), noti->GetId());
   Bundle serialized = noti->Serialize();
   list<Bundle> serialized_list {serialized};
-
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(
+  impl_->sender_->SendMessage(
       info, serialized_list, noti->GetSenderAppId());
+  return info.GetRequestId();
 }
 
 unique_ptr<item::AbstractItem> Manager::FindByRootID(string id) {
   EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
   list<Bundle> result = impl_->sender_->Request(info);
-  if (result.size() == 0) {
-    LOGE("Fail to get noti");
-    return unique_ptr<item::AbstractItem>{};
-  }
   Bundle b = result.front();
   unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
   return gen_item;
index e303c60..5134dee 100644 (file)
@@ -40,12 +40,12 @@ class EXPORT_API Manager : public IEventObserver {
   virtual ~Manager();
 
   std::list<std::unique_ptr<item::AbstractItem>> Get(std::string channel = "");
-  int Update(std::shared_ptr<item::AbstractItem> noti, int& request_id);
-  int Delete(std::shared_ptr<item::AbstractItem> noti, int& request_id);
-  int DeleteAll(int& request_id);
-  int DeleteByChannel(std::string channel, int& request_id);
-  int DeleteByAppId(std::string appId, int& request_id);
-  int Hide(std::shared_ptr<item::AbstractItem> noti, int& request_id);
+  int Update(std::shared_ptr<item::AbstractItem> noti);
+  int Delete(std::shared_ptr<item::AbstractItem> noti);
+  int DeleteAll();
+  int DeleteByChannel(std::string channel);
+  int DeleteByAppId(std::string appId);
+  int Hide(std::shared_ptr<item::AbstractItem> noti);
   std::unique_ptr<item::AbstractItem> FindByRootID(std::string id);
   int SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
   int SendEvent(const IEventInfo& info, std::list<std::shared_ptr<item::AbstractItem>> notiList);
index 5502822..aac9d51 100644 (file)
@@ -35,8 +35,6 @@ class Manager::Impl {
 
  private:
   friend class Manager;
-  int SendNotify(std::shared_ptr<item::AbstractItem> noti,
-      IEventInfo::EventType type);
   std::unique_ptr<IEventSender> sender_;
   std::unique_ptr<IEventListener> listener_;
   std::string receiver_group_;
index 7e03f69..d100aac 100644 (file)
@@ -28,6 +28,7 @@
 #include "notification-ex/ex_util.h"
 #include "notification-ex/item_info_internal.h"
 #include "notification-ex/shared_file.h"
+#include "notification-ex/exception.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -58,15 +59,6 @@ Reporter::Impl::Impl(Reporter* parent,
   listener_->RegisterObserver(parent_);
 }
 
-int Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
-    IEventInfo::EventType type) {
-  Bundle serialized = noti->Serialize();
-  EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId());
-  list<Bundle> serialized_list {serialized};
-  sender_->Notify(info, serialized_list);
-  return info.GetRequestId();
-}
-
 void Reporter::SendError(const IEventInfo& info, NotificationError error) {
   list<Bundle> serialized_list {};
   IEventInfo& i = const_cast<IEventInfo&>(info);
@@ -75,7 +67,7 @@ void Reporter::SendError(const IEventInfo& info, NotificationError error) {
   impl_->sender_->Notify(info, serialized_list, info.GetOwner());
 }
 
-int Reporter::Post(std::shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
   LOGI("Post noti");
   static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
   Bundle serialized = noti->Serialize();
@@ -85,12 +77,11 @@ int Reporter::Post(std::shared_ptr<item::AbstractItem> noti, int& request_id) {
   list<Bundle> serialized_list {serialized};
   SharedFile::CopyPrivateFile(noti);
 
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(info, serialized_list);
+  impl_->sender_->SendMessage(info, serialized_list);
+  return info.GetRequestId();
 }
 
-int Reporter::Post(
-    std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+int Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
   LOGI("Post noti list");
   EventInfo info(EventInfo::Post, util::GetAppId(), "");
   list<Bundle> serialized_list;
@@ -101,11 +92,11 @@ int Reporter::Post(
     SharedFile::CopyPrivateFile(i);
   }
 
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(info, serialized_list);
+  impl_->sender_->SendMessage(info, serialized_list);
+  return info.GetRequestId();
 }
 
-int Reporter::Update(std::shared_ptr<AbstractItem> noti, int& request_id) {
+int Reporter::Update(std::shared_ptr<AbstractItem> noti) {
   static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
   Bundle serialized = noti->Serialize();
 
@@ -114,12 +105,12 @@ int Reporter::Update(std::shared_ptr<AbstractItem> noti, int& request_id) {
   list<Bundle> serialized_list {serialized};
   SharedFile::CopyPrivateFile(noti);
 
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(info, serialized_list);
+  impl_->sender_->SendMessage(info, serialized_list);
+  return info.GetRequestId();
 }
 
 int Reporter::Update(
-    std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+    std::list<std::shared_ptr<AbstractItem>> notiList) {
   EventInfo info(EventInfo::Update, util::GetAppId(), "");
   list<Bundle> serialized_list;
   for (auto& i : notiList) {
@@ -129,23 +120,22 @@ int Reporter::Update(
     SharedFile::CopyPrivateFile(i);
   }
 
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(info, serialized_list);
+  impl_->sender_->SendMessage(info, serialized_list);
+  return info.GetRequestId();
 }
 
-int Reporter::Delete(std::shared_ptr<AbstractItem> noti, int& request_id) {
+int Reporter::Delete(std::shared_ptr<AbstractItem> noti) {
   Bundle serialized = noti->Serialize();
   EventInfo info(
       EventInfo::Delete, util::GetAppId(), noti->GetChannel(), noti->GetId());
   list<Bundle> serialized_list {serialized};
-
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(
+  impl_->sender_->SendMessage(
       info, serialized_list, noti->GetSenderAppId());
+  return info.GetRequestId();
 }
 
 int Reporter::Delete(
-    std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+    std::list<std::shared_ptr<AbstractItem>> notiList) {
   EventInfo info(EventInfo::Delete, util::GetAppId(), "");
   list<Bundle> serialized_list;
   for (auto& i : notiList) {
@@ -155,29 +145,25 @@ int Reporter::Delete(
     SharedFile::CopyPrivateFile(i);
   }
 
-  request_id = info.GetRequestId();
-  return impl_->sender_->SendMessage(info, serialized_list);
+  impl_->sender_->SendMessage(info, serialized_list);
+  return info.GetRequestId();
 }
 
-int Reporter::DeleteAll(int& request_id) {
+int Reporter::DeleteAll() {
   EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
-  request_id = info.GetRequestId();
-  return impl_->sender_->RequestReturnValue(info);
+  impl_->sender_->RequestReturnValue(info);
+  return info.GetRequestId();
 }
 
-int Reporter::DeleteByChannel(string channel, int& request_id) {
+int Reporter::DeleteByChannel(string channel) {
   EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
-  request_id = info.GetRequestId();
-  return impl_->sender_->RequestReturnValue(info);
+  impl_->sender_->RequestReturnValue(info);
+  return info.GetRequestId();
 }
 
 std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
   EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
   list<Bundle> result = impl_->sender_->Request(info);
-  if (result.size() == 0) {
-    LOGE("Fail to get noti");
-    return unique_ptr<item::AbstractItem>{};
-  }
   Bundle b = result.front();
   unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
   return gen_item;
@@ -186,11 +172,6 @@ std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
 list<unique_ptr<AbstractItem>> Reporter::FindByChannel(string channel) {
   EventInfo info(EventInfo::Get, util::GetAppId(), channel, "");
   list<Bundle> result = impl_->sender_->Request(info);
-  if (result.size() == 0) {
-    LOGE("Fail to get noti");
-    return list<unique_ptr<item::AbstractItem>>{};
-  }
-
   list<unique_ptr<AbstractItem>> gen_item_list;
   for (auto& i : result)
     gen_item_list.push_back(ItemInflator::Create(i));
@@ -201,11 +182,6 @@ list<unique_ptr<AbstractItem>> Reporter::FindByChannel(string channel) {
 list<unique_ptr<AbstractItem>> Reporter::FindAll() {
   EventInfo info(EventInfo::Get, util::GetAppId(), "", "");
   list<Bundle> result = impl_->sender_->Request(info);
-  if (result.size() == 0) {
-    LOGE("Fail to get noti");
-    return list<unique_ptr<item::AbstractItem>>{};
-  }
-
   list<unique_ptr<AbstractItem>> gen_item_list;
   for (auto& i : result)
     gen_item_list.push_back(ItemInflator::Create(i));
@@ -225,6 +201,7 @@ int Reporter::SendEvent(const IEventInfo& info,
     Bundle b = i->Serialize();
     serialized_list.push_back(b);
   }
+
   impl_->sender_->Notify(info, serialized_list);
   return info.GetRequestId();
 }
index ba6f4b3..36e6840 100644 (file)
@@ -43,14 +43,14 @@ class EXPORT_API Reporter : public IEventObserver {
   int SendEvent(const IEventInfo& info,
       std::list<std::shared_ptr<item::AbstractItem>> notiList);
   void SendError(const IEventInfo& info, NotificationError error);
-  int Post(std::shared_ptr<item::AbstractItem> noti, int& request_id);
-  int Post(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
-  int Update(std::shared_ptr<item::AbstractItem> noti, int& request_id);
-  int Update(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
-  int Delete(std::shared_ptr<item::AbstractItem> noti, int& request_id);
-  int Delete(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
-  int DeleteAll(int& request_id);
-  int DeleteByChannel(std::string channel, int& request_id);
+  int Post(std::shared_ptr<item::AbstractItem> noti);
+  int Post(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+  int Update(std::shared_ptr<item::AbstractItem> noti);
+  int Update(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+  int Delete(std::shared_ptr<item::AbstractItem> noti);
+  int Delete(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+  int DeleteAll();
+  int DeleteByChannel(std::string channel);
   std::unique_ptr<item::AbstractItem> FindByRootID(std::string id);
   std::list<std::unique_ptr<item::AbstractItem>> FindByChannel(std::string channel);
   std::list<std::unique_ptr<item::AbstractItem>> FindAll();
index 8628dcf..7f228e4 100644 (file)
@@ -35,8 +35,6 @@ class Reporter::Impl {
 
  private:
   friend class Reporter;
-  int SendNotify(std::shared_ptr<item::AbstractItem> noti,
-      IEventInfo::EventType type);
   std::unique_ptr<IEventSender> sender_;
   std::unique_ptr<IEventListener> listener_;
   Reporter* parent_;
index 68cb4b4..7563eef 100644 (file)
@@ -2629,24 +2629,18 @@ extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
   if (receiver_group)
     receiver_group_str = string(receiver_group);
 
-  ManagerStub* stub = new (std::nothrow) ManagerStub(
+  try {
+    ManagerStub* stub = new (std::nothrow) ManagerStub(
       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
-      receiver_group_str);
-  if (stub == nullptr) {
-    LOGE("Fail to create manager");
-    return NOTI_EX_ERROR_IO_ERROR;
-  }
+        receiver_group_str);
 
-  int ret = get_last_result();
-  if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-    LOGE("error(%d)", ret);
-    delete stub;
-    return ret;
+    stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
+        new ManagerCallbackInfo(event_callbacks, data)));
+    *handle = static_cast<noti_ex_manager_h>(stub);
+  } catch (Exception& ex) {
+    return ex.GetErrorCode();
   }
-  stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
-      new ManagerCallbackInfo(event_callbacks, data)));
-  *handle = static_cast<noti_ex_manager_h>(stub);
 
   return NOTI_EX_ERROR_NONE;
 }
@@ -2671,22 +2665,9 @@ extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
-    int ret = get_last_result();
-    if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-      LOGE("error(%d)", ret);
-      *items = nullptr;
-      *count = 0;
-      return ret;
-    }
-
-    if (item_list.size() == 0) {
-      *items = nullptr;
-      *count = 0;
-      return NOTI_EX_ERROR_NONE;
-    }
-
     noti_ex_item_h* added_item =
-        (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
+        static_cast<noti_ex_item_h*>(
+          calloc(item_list.size(), sizeof(noti_ex_item_h)));
     if (added_item == nullptr) {
       LOGE("Fail to create items");
       return NOTI_EX_ERROR_OUT_OF_MEMORY;
@@ -2698,15 +2679,21 @@ extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
     }
     *items = added_item;
     *count = item_list.size();
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+      *items = nullptr;
+      *count = 0;
+      return NOTI_EX_ERROR_NONE;
+    }
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
-    noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
+    noti_ex_manager_h handle, char* channel,
+    noti_ex_item_h** items, int* count) {
   if (handle == nullptr || channel == nullptr ||
       items == nullptr || count == nullptr) {
     LOGE("Invalid parameter");
@@ -2716,21 +2703,9 @@ extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
-    int ret = get_last_result();
-    if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-      LOGE("error(%d)", ret);
-      *items = nullptr;
-      *count = 0;
-      return ret;
-    }
-
-    if (item_list.size() == 0) {
-      *items = nullptr;
-      *count = 0;
-      return NOTI_EX_ERROR_NONE;
-    }
     noti_ex_item_h* added_item =
-        (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
+        static_cast<noti_ex_item_h*>(
+          calloc(item_list.size(), sizeof(noti_ex_item_h)));
     if (added_item == nullptr) {
       LOGE("Fail to create items");
       return NOTI_EX_ERROR_OUT_OF_MEMORY;
@@ -2742,9 +2717,14 @@ extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
     }
     *items = added_item;
     *count = item_list.size();
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+      *items = nullptr;
+      *count = 0;
+      return NOTI_EX_ERROR_NONE;
+    }
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return NOTI_EX_ERROR_NONE;
@@ -2752,8 +2732,6 @@ extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
 
 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
     noti_ex_item_h noti, int *request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
@@ -2765,19 +2743,17 @@ extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Update(sp->GetPtr(), *request_id);
+      *request_id = stub->Update(sp->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
     return NOTI_EX_ERROR_IO_ERROR;
   }
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
     noti_ex_item_h noti, int *request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
@@ -2790,43 +2766,33 @@ extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Delete(item->GetPtr(), *request_id);
+      *request_id = stub->Delete(item->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
-
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
     int *request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
-    stub->DeleteAll(*request_id);
-    ret = get_last_result();
-    if (ret != ERROR_NONE) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+    *request_id = stub->DeleteAll();
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
     noti_ex_manager_h handle, const char* channel, int* request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || channel == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
@@ -2834,24 +2800,16 @@ extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
 
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
-    stub->DeleteByChannel(channel, *request_id);
-    ret = get_last_result();
-    if (ret != ERROR_NONE) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+    *request_id = stub->DeleteByChannel(channel);
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
     return NOTI_EX_ERROR_IO_ERROR;
   }
-
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
     noti_ex_manager_h handle, const char* app_id, int* request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
@@ -2859,24 +2817,17 @@ extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
 
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
-    stub->DeleteByAppId(app_id, *request_id);
-    ret = get_last_result();
-    if (ret != ERROR_NONE) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+    *request_id = stub->DeleteByAppId(app_id);
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
     noti_ex_item_h noti, int *request_id) {
-  int ret = ERROR_NONE;
-
   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
@@ -2888,13 +2839,13 @@ extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Hide(item->GetPtr(), *request_id);
+      *request_id = stub->Hide(item->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
-  return ret;
+  return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
@@ -2906,21 +2857,15 @@ extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
-    int ret = get_last_result();
-    if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-
-    if (ptr == nullptr) {
+    *item = new Handle(ptr);
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
       LOGW("Not exist ID");
       *item = nullptr;
       return NOTI_EX_ERROR_NONE;
     }
-    *item = new Handle(ptr);
-  } catch (Exception &ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
@@ -2936,15 +2881,9 @@ extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
     IEventInfo* c_info = static_cast<IEventInfo*>(info);
     stub->SendError(static_cast<const IEventInfo&>(*c_info),
         static_cast<NotificationError>(error));
-
-    int ret = get_last_result();
-    if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
@@ -2958,15 +2897,9 @@ extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
   try {
     ManagerStub* stub = static_cast<ManagerStub*>(handle);
     *count = stub->GetCount();
-
-    int ret = get_last_result();
-    if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
@@ -3110,18 +3043,18 @@ extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
 
-  ReporterStub* stub = new (std::nothrow) ReporterStub(
-      unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
-      unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
-  if (stub == nullptr) {
-    LOGE("Fail to create manager");
-    return NOTI_EX_ERROR_IO_ERROR;
+  try {
+    ReporterStub* stub = new (std::nothrow) ReporterStub(
+        unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
+        unique_ptr<DBusEventListener>(
+            new DBusEventListener(Reporter::GetPath())));
+    stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
+        new ReporterCallbackInfo(event_callbacks, data)));
+    *handle = static_cast<noti_ex_reporter_h>(stub);
+  } catch (Exception& ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return ex.GetErrorCode();
   }
-  stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
-      new ReporterCallbackInfo(event_callbacks, data)));
-
-  *handle = static_cast<noti_ex_reporter_h>(stub);
-
   return NOTI_EX_ERROR_NONE;
 }
 
@@ -3146,9 +3079,9 @@ extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
     IEventInfo* c_info = static_cast<IEventInfo*>(info);
     stub->SendError(static_cast<const IEventInfo&>(*c_info),
         static_cast<NotificationError>(error));
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
@@ -3168,11 +3101,11 @@ extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Post(h->GetPtr(), *request_id);
+      *request_id = stub->Post(h->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return ret;
 }
@@ -3192,10 +3125,10 @@ extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
       Handle* item = static_cast<Handle*>(noti_list[i]);
       notiList.push_back(item->GetPtr());
     }
-    ret = stub->Post(notiList, *request_id);
-  } catch (Exception &ex) {
+    *request_id = stub->Post(notiList);
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return ret;
 }
@@ -3215,11 +3148,11 @@ extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Update(item->GetPtr(), *request_id);
+      *request_id = stub->Update(item->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return ret;
 }
@@ -3240,10 +3173,10 @@ extern "C" EXPORT_API int noti_ex_reporter_update_list(
       Handle* item = static_cast<Handle*>(noti_list[i]);
       notiList.push_back(item->GetPtr());
     }
-    ret = stub->Update(notiList, *request_id);
-  } catch (Exception &ex) {
+    *request_id = stub->Update(notiList);
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return ret;
 }
@@ -3263,11 +3196,11 @@ extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
       LOGE("Invalid noti reference can not be sended");
       return NOTI_EX_ERROR_INVALID_PARAMETER;
     } else {
-      ret = stub->Delete(item->GetPtr(), *request_id);
+      *request_id = stub->Delete(item->GetPtr());
     }
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return ret;
 }
@@ -3289,10 +3222,10 @@ extern "C" EXPORT_API int noti_ex_reporter_delete_list(
       Handle* item = static_cast<Handle*>(noti_list[i]);
       notiList.push_back(item->GetPtr());
     }
-    ret = stub->Delete(notiList, *request_id);
-  } catch (Exception &ex) {
+    *request_id = stub->Delete(notiList);
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return ret;
@@ -3309,15 +3242,10 @@ extern "C" EXPORT_API int noti_ex_reporter_delete_all(
 
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
-    stub->DeleteAll(*request_id);
-    ret = get_last_result();
-    if (ret != ERROR_NONE) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+    *request_id = stub->DeleteAll();
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return ret;
@@ -3334,15 +3262,10 @@ extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
 
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
-    stub->DeleteByChannel(channel, *request_id);
-    ret = get_last_result();
-    if (ret != ERROR_NONE) {
-      LOGE("error(%d)", ret);
-      return ret;
-    }
-  } catch (Exception &ex) {
+    *request_id = stub->DeleteByChannel(channel);
+  } catch (Exception& ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return ret;
@@ -3357,15 +3280,15 @@ extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
-    if (ptr == nullptr) {
+    *item = new Handle(ptr);
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
       LOGW("Not exist ID");
       *item = nullptr;
       return NOTI_EX_ERROR_NONE;
     }
-    *item = new Handle(ptr);
-  } catch (Exception &ex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
   return NOTI_EX_ERROR_NONE;
 }
@@ -3383,13 +3306,6 @@ extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h ha
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
     list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
-    if (list_ptr.empty()) {
-      LOGW("Not exist ID");
-      *noti_list = nullptr;
-      *count = 0;
-      return NOTI_EX_ERROR_NONE;
-    }
-
     int size = list_ptr.size();
     list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
     if (list_item == nullptr) {
@@ -3405,10 +3321,16 @@ extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h ha
 
     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
     *count = size;
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+      LOGW("Not exist ID");
+      *noti_list = nullptr;
+      *count = 0;
+      return NOTI_EX_ERROR_NONE;
+    }
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
     free(list_item);
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return NOTI_EX_ERROR_NONE;
@@ -3426,11 +3348,6 @@ extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
     list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
-    if (list_ptr.empty()) {
-      LOGW("Not exist ID");
-      *noti_list = nullptr;
-      return NOTI_EX_ERROR_NONE;
-    }
 
     int size = list_ptr.size();
     list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
@@ -3447,10 +3364,15 @@ extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
 
     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
     *count = size;
-  } catch (Exception &ex) {
+  } catch (Exception& ex) {
+    if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+      LOGW("Not exist ID");
+      *noti_list = nullptr;
+      return NOTI_EX_ERROR_NONE;
+    }
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
     free(list_item);
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return NOTI_EX_ERROR_NONE;
@@ -3466,9 +3388,9 @@ extern "C" EXPORT_API int noti_ex_reporter_get_count_by_channel(
   try {
     ReporterStub* stub = static_cast<ReporterStub*>(handle);
     *count = stub->GetCount(channel);
-  } catch (Exception &ex) {
+  } catch (Exceptionex) {
     LOGE("%s %d", ex.what(), ex.GetErrorCode());
-    return NOTI_EX_ERROR_IO_ERROR;
+    return ex.GetErrorCode();
   }
 
   return NOTI_EX_ERROR_NONE;