summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyungKi Lee <mk5004.lee@samsung.com>2020-05-21 00:40:10 +0000
committerjusung son <jusung07.son@samsung.com>2020-05-26 05:12:16 +0000
commit4d4b971c114ce15e4487f9eaca9f08912161a7ae (patch)
treeabe8b93e43067ba1f7d5cbcf01b2612fb078de82
parente34aa5f6064f6983c7e2ca40e73d0ced09ce907a (diff)
downloadnotification-4d4b971c114ce15e4487f9eaca9f08912161a7ae.tar.gz
notification-4d4b971c114ce15e4487f9eaca9f08912161a7ae.tar.bz2
notification-4d4b971c114ce15e4487f9eaca9f08912161a7ae.zip
Revert "Revert "Add get_count api for reporter""
This reverts commit 0afc4c5514e475b98b5dcdda915ab856a1a50c70. Change-Id: I53a4c9b6aac18d272b69da45903ad15d4b500d40
-rw-r--r--notification-ex/api/notification_ex_internal.h2
-rw-r--r--notification-ex/db_manager.cc20
-rw-r--r--notification-ex/db_manager.h6
-rw-r--r--notification-ex/reporter.cc6
-rw-r--r--notification-ex/reporter.h1
-rw-r--r--notification-ex/stub.cc18
6 files changed, 44 insertions, 9 deletions
diff --git a/notification-ex/api/notification_ex_internal.h b/notification-ex/api/notification_ex_internal.h
index 7e4209e..c2016e0 100644
--- a/notification-ex/api/notification_ex_internal.h
+++ b/notification-ex/api/notification_ex_internal.h
@@ -49,6 +49,8 @@ int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
const char *channel, noti_ex_item_h **noti_list, int *count);
int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
noti_ex_item_h **noti_list, int *count);
+int noti_ex_reporter_get_count_by_channel(noti_ex_reporter_h handle,
+ const char *channel, int *count);
int noti_ex_reporter_delete_by_channel(noti_ex_reporter_h handle,
const char *channel, int *request_id);
int noti_ex_reporter_update_list(noti_ex_reporter_h handle,
diff --git a/notification-ex/db_manager.cc b/notification-ex/db_manager.cc
index 7b308aa..12cb3e3 100644
--- a/notification-ex/db_manager.cc
+++ b/notification-ex/db_manager.cc
@@ -293,7 +293,7 @@ void DBManager::CheckLimit(shared_ptr<item::AbstractItem> addedItem, sqlite3* db
uid_t uid =
static_pointer_cast<IItemInfoInternal>(addedItem->GetInfo())->GetUid();
- ret = GetCount(addedItem->GetSenderAppId(), uid, &count);
+ ret = GetCount(addedItem->GetSenderAppId(), string(), uid, &count);
if (ret != ERROR_NONE || count <= NOTI_LIMIT)
return;
@@ -532,23 +532,29 @@ map<string, string> DBManager::GetHideMap() {
return hide_map;
}
-int DBManager::GetCount(const string& app_id, uid_t uid, int* count) {
- return GetCount(0, string(), app_id, uid, count);
+int DBManager::GetCount(const string& app_id, const string& channel, uid_t uid, int* count) {
+ return GetCount(0, string(), app_id, channel, uid, count);
}
-int DBManager::GetCount(int64_t priv_id, const string& root_id, const string& app_id,
- uid_t uid, int* count) {
+int DBManager::GetCount(int64_t priv_id, const string& root_id,
+ const string& app_id, const string& channel, uid_t uid, int* count) {
int ret;
char* query;
sqlite3_stmt *stmt;
sqlite3* db;
+ string query_str;
if (priv_id != 0) {
query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
" WHERE priv_id = %" PRId64 "", priv_id);
} else if (root_id.empty()) {
- query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
- " WHERE app_id = %Q AND uid = %d", app_id.c_str(), uid);
+ if (!channel.empty())
+ query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
+ " WHERE app_id = %Q AND uid = %d AND channel = %Q",
+ app_id.c_str(), uid, channel.c_str());
+ else
+ query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
+ " WHERE app_id = %Q AND uid = %d", app_id.c_str(), uid);
} else {
query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
" WHERE root_id = %Q AND app_id = %Q AND uid = %d",
diff --git a/notification-ex/db_manager.h b/notification-ex/db_manager.h
index f2a4e5e..55d15f6 100644
--- a/notification-ex/db_manager.h
+++ b/notification-ex/db_manager.h
@@ -40,8 +40,10 @@ class EXPORT_API DBManager {
static std::map<std::string, std::string> GetHideMap();
static int UpdateHideList(std::shared_ptr<item::AbstractItem> updatedItem, const std::string& hide_list);
static int UpdateNotification(std::list<std::shared_ptr<item::AbstractItem>> updatedList);
- static int GetCount(int64_t priv_id, const std::string& root_id, const std::string& app_id, uid_t uid, int* count);
- static int GetCount(const std::string& app_id, uid_t uid, int* count);
+ static int GetCount(int64_t priv_id, const std::string& root_id,
+ const std::string& app_id, const std::string& channel, uid_t uid, int* count);
+ static int GetCount(const std::string& app_id, const std::string& channel,
+ uid_t uid, int* count);
static int DeleteNotification(std::list<std::shared_ptr<item::AbstractItem>> deletedList);
static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(uid_t uid, std::string channel = "");
static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, uid_t uid, std::string channel = "");
diff --git a/notification-ex/reporter.cc b/notification-ex/reporter.cc
index 17b5ae9..40b8929 100644
--- a/notification-ex/reporter.cc
+++ b/notification-ex/reporter.cc
@@ -194,6 +194,12 @@ list<unique_ptr<AbstractItem>> Reporter::FindAll() {
return gen_item_list;
}
+int Reporter::GetCount(string channel) const {
+ EventInfo info(EventInfo::Count, util::GetAppId(), channel);
+ int num = impl_->sender_->RequestNumber(info);
+ return num;
+}
+
int Reporter::SendEvent(const IEventInfo& info,
std::list<std::shared_ptr<item::AbstractItem>> notiList) {
list<Bundle> serialized_list;
diff --git a/notification-ex/reporter.h b/notification-ex/reporter.h
index f80c20f..36e6840 100644
--- a/notification-ex/reporter.h
+++ b/notification-ex/reporter.h
@@ -54,6 +54,7 @@ class EXPORT_API Reporter : public IEventObserver {
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();
+ int GetCount(std::string channel = "") const;
virtual void OnEvent(const IEventInfo& info,
std::list<std::shared_ptr<item::AbstractItem>> notiList);
virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc
index dd8f1f0..4f6fb0c 100644
--- a/notification-ex/stub.cc
+++ b/notification-ex/stub.cc
@@ -3332,6 +3332,24 @@ extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
return NOTI_EX_ERROR_NONE;
}
+extern "C" EXPORT_API int noti_ex_reporter_get_count_by_channel(
+ noti_ex_reporter_h handle, const char *channel, int *count) {
+ if (handle == nullptr || channel == nullptr || count == nullptr) {
+ LOGE("Invalid parameter");
+ return NOTI_EX_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ ReporterStub* stub = static_cast<ReporterStub*>(handle);
+ *count = stub->GetCount(channel);
+ } catch (Exception &ex) {
+ LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ return NOTI_EX_ERROR_IO_ERROR;
+ }
+
+ return NOTI_EX_ERROR_NONE;
+}
+
extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
const char *id, const char *text, const char *hyperlink) {
if (handle == nullptr || text == nullptr) {