Add function to get the numbers of all notification 84/163584/8
authorSeungha Son <seungha.son@samsung.com>
Mon, 11 Dec 2017 06:51:41 +0000 (15:51 +0900)
committerSeungha Son <seungha.son@samsung.com>
Fri, 15 Dec 2017 03:07:21 +0000 (12:07 +0900)
related patch
 -data-provider-master: https://review.tizen.org/gerrit/#/c/163585/
 -tizenfx : https://review.tizen.org/gerrit/#/c/163969/

Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: I3e045efd94fca77192e45403ed00a78f83e5f292

include/notification_internal.h
include/notification_ipc.h
include/notification_noti.h
src/notification_db_query.h
src/notification_internal.c
src/notification_ipc.c
src/notification_noti.c

index a07929d..216f9ca 100755 (executable)
@@ -314,6 +314,13 @@ NOTIFICATION_DEPRECATED_API int notification_delete_group_by_group_id(const char
 NOTIFICATION_DEPRECATED_API int notification_delete_group_by_priv_id(const char *app_id,
                                                          notification_type_e type,
                                                          int priv_id);
+
+/**
+ * @brief This function will be deprecated.
+ *
+ */
+NOTIFICATION_DEPRECATED_API int notifiation_clear(notification_type_e type);
+
 /**
  * @brief This function will be deprecated.
  *
@@ -324,10 +331,21 @@ NOTIFICATION_DEPRECATED_API int notification_get_count(notification_type_e type,
                                            int *count);
 
 /**
- * @brief This function will be deprecated.
- *
+ * @internal
+ * @brief
+ * @details Gets the numbers of all notifications
+ * @since tizen 4.0
+ * @param[int] type the type of notification
+ * @param[out] count the numbers of all notifications
+ * @return NOTIFICATION_ERROR_NONE on success, other value on failure
+ * @retval NOTIFICATION_ERROR_NONE Success
+ * @retval NOTIFICATION_ERROR_INVALID_PARAMETER Invalid input value
+ * @retval NOTIFICATION_ERROR_IO_ERROR I/O Error
+ * @retval NOTIFICATION_ERROR_FROM_DB Error from DB
+ * @retval NOTIFICATION_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-NOTIFICATION_DEPRECATED_API int notifiation_clear(notification_type_e type);
+int notification_get_all_count(notification_type_e type, int *count);
+int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid);
 
 /**
  * @internal
index 39227f1..4b4ceb0 100755 (executable)
@@ -98,6 +98,7 @@ int notification_ipc_make_dnd_allow_exception_from_gvariant(
 int notification_ipc_send_event(notification_h noti, int event_type, int priv_id);
 int notification_ipc_check_event_receiver(int priv_id, bool *available);
 void notification_ipc_reset_event_handler(int priv_id);
+int notification_ipc_request_get_all_count(notification_type_e type, int *count, uid_t uid);
 #ifdef __cplusplus
 }
 #endif
index 89013f7..fd0d662 100644 (file)
@@ -51,6 +51,8 @@ int notification_noti_get_count(notification_type_e type,
                int group_id, int priv_id,
                int *count, uid_t uid);
 
+int notification_noti_get_all_count(notification_type_e type, int *count, uid_t uid);
+
 int notification_noti_get_grouping_list(notification_type_e type,
                int count,
                notification_list_h *list,
index 07c79d7..37cf83c 100755 (executable)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#define NOTIFICATION_DB_TABLE "noti_list"
 #define NOTIFICATION_SETTING_DB_TABLE "notification_setting"
 #define NOTIFICATION_SYSTEM_SETTING_DB_TABLE "notification_system_setting"
 #define NOTIFICATION_DND_ALLOW_EXCEPTION "dnd_allow_exception"
index 07ebe37..ca82988 100755 (executable)
@@ -1989,3 +1989,32 @@ out:
 
        return ret;
 }
+
+EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid)
+{
+       int ret;
+
+       if (count == NULL) {
+               NOTIFICATION_ERR("Invalid parameter - count is null");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (type < NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
+               NOTIFICATION_ERR("Invalid parameter - wrong type");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = notification_ipc_request_get_all_count(type, count, uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Failed to get count [%d]", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
+{
+       return notification_get_all_count_for_uid(type, count, getuid());
+}
+
index 7c82c29..78658e9 100755 (executable)
@@ -1674,6 +1674,33 @@ int notification_ipc_get_noti_block_state(const char *app_id, int *do_not_distur
        return ret;
 }
 
+int notification_ipc_request_get_all_count(notification_type_e type, int *count, uid_t uid)
+{
+       int ret;
+       int ret_count = -1;
+       GDBusMessage *reply = NULL;
+       GVariant *reply_body = NULL;
+
+       ret = _dbus_init();
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Failed to init dbus connection[%d]", ret);
+               return ret;
+       }
+
+       ret = _send_sync_noti(g_variant_new("(ii)", type, uid),
+                       &reply, "get_noti_all_count");
+       if (ret == NOTIFICATION_ERROR_NONE) {
+               reply_body = g_dbus_message_get_body(reply);
+               g_variant_get(reply_body, "(i)", &ret_count);
+               *count = ret_count;
+       }
+
+       if (reply)
+               g_object_unref(reply);
+
+       return ret;
+}
+
 int notification_ipc_send_event(notification_h noti, int event_type, int priv_id)
 {
        int ret;
index 9a4f269..8706df6 100755 (executable)
@@ -1564,6 +1564,67 @@ err:
 }
 /* LCOV_EXCL_STOP */
 
+EXPORT_API int notification_noti_get_all_count(notification_type_e type, int *count, uid_t uid)
+{
+       int ret = NOTIFICATION_ERROR_NONE;
+       int sql_ret;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *stmt = NULL;
+       char *sql_buf = NULL;
+
+       if (count == NULL) {
+               NOTIFICATION_ERR("Invalid parameter - count is null");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       db = notification_db_open(DBPATH);
+       if (db == NULL) {
+               ret = get_last_result();
+               NOTIFICATION_ERR("Failed to open db [%d]", ret);
+               return ret;
+       }
+
+       if (type != NOTIFICATION_TYPE_NONE)
+               sql_buf = sqlite3_mprintf("SELECT count(*) FROM %q "
+                               "WHERE uid = %d AND type = %d",
+                               NOTIFICATION_DB_TABLE, uid, type);
+       else
+               sql_buf = sqlite3_mprintf("SELECT count(*) FROM %q WHERE uid = %d",
+                               NOTIFICATION_DB_TABLE, uid);
+
+       if (sql_buf == NULL) {
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               NOTIFICATION_ERR("OOM - sqlite3_mprintf");
+               goto out;
+       }
+
+       sql_ret = sqlite3_prepare_v2(db, sql_buf, -1, &stmt, NULL);
+       if (sql_ret != SQLITE_OK) {
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               NOTIFICATION_ERR("SQLITE3 Error - sqlite3_prepare_v2 [%d][%s]",
+                               sql_ret, sqlite3_errmsg(db));
+               goto out;
+       }
+
+       sql_ret = sqlite3_step(stmt);
+       if (sql_ret == SQLITE_ROW)
+               *count = sqlite3_column_int(stmt, 0);
+       else
+               *count = 0;
+
+       NOTIFICATION_INFO("The numbers of all notification is [%d]", *count);
+
+out:
+       if (stmt)
+               sqlite3_finalize(stmt);
+       if (sql_buf)
+               sqlite3_free(sql_buf);
+       if (db)
+               notification_db_close(&db);
+
+       return ret;
+}
+
 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
                                                        int count,
                                                        notification_list_h *list,