From 99302d7d8c2aa8a5e92cc9d47d6c408b6d544421 Mon Sep 17 00:00:00 2001 From: hyunho Date: Fri, 22 Nov 2019 10:43:53 +0900 Subject: [PATCH] Return NULL when fail to find item Change-Id: Idff2983512eb22366f37cfa4a4327bf289935b1e Signed-off-by: hyunho --- notification-ex/stub.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc index f8b50a7..45f5c1a 100644 --- a/notification-ex/stub.cc +++ b/notification-ex/stub.cc @@ -1935,6 +1935,12 @@ extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle, Handle* p = static_cast(handle); AbstractItem& find_item = p->Get()->FindByID(string(id)); + if (find_item.GetType() == AbstractItem::NullObject) { + LOGW("Not exist ID"); + *item = nullptr; + return NOTI_EX_ERROR_NONE; + } + *item = new Handle(&find_item); return NOTI_EX_ERROR_NONE; } @@ -2465,6 +2471,11 @@ extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle, GroupItem* p = static_cast(h->Get()); AbstractItem& find_item = p->FindByMainType(static_cast(type)); + if (find_item.GetType() == AbstractItem::NullObject) { + LOGW("Not exist ID"); + *item = nullptr; + return NOTI_EX_ERROR_NONE; + } *item = new Handle(&find_item); return NOTI_EX_ERROR_NONE; @@ -2669,7 +2680,13 @@ extern "C" EXPORT_API int noti_ex_manager_find_by_root_id( } try { ManagerStub* stub = static_cast(handle); - *item = new Handle(stub->FindByRootID(root_id)); + shared_ptr ptr = stub->FindByRootID(root_id); + if (ptr == nullptr) { + 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; @@ -3006,7 +3023,13 @@ extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id( } try { ReporterStub* stub = static_cast(handle); - *item = new Handle(stub->FindByRootID(root_id)); + shared_ptr ptr = stub->FindByRootID(root_id); + if (ptr == nullptr) { + 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; -- 2.7.4