Add flush timer
authorJusung Son <jusung07.son@samsung.com>
Thu, 29 Oct 2020 10:50:00 +0000 (19:50 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 2 Nov 2020 05:04:51 +0000 (14:04 +0900)
Change-Id: I56577b6dde58762dc3538bb05c131778846acc6e
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/notification_ex_service.cc

index 509a510..a7b00fa 100644 (file)
@@ -15,6 +15,8 @@
  */
 
 #include <dlog.h>
+#include <malloc.h>
+#include <sqlite3.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <notification_type.h>
@@ -57,6 +59,7 @@
 #include "notification_ex_service.h"
 
 #define NORMAL_UID_BASE 5000
+#define MAX_TIMEOUT 30 * 1000 /* 30 sec */
 
 using namespace std;
 using namespace notification;
@@ -303,6 +306,24 @@ out:
       }
     }
   }
+
+  void SetMemoryTrimTimer(void) {
+    static guint timer = 0;
+    if (timer > 0)
+      g_source_remove(timer);
+
+    timer = g_timeout_add(MAX_TIMEOUT, TimeoutHandler, &timer);
+  }
+
+  static gboolean TimeoutHandler(gpointer data) {
+    guint* timer = static_cast<guint*>(data);
+    sqlite3_release_memory(-1);
+    malloc_trim(0);
+    *timer = 0;
+
+    return false;
+  }
+
   unique_ptr<Reporter> reporter_;
   unique_ptr<Manager> manager_;
   map<string, string> hide_map_;
@@ -399,6 +420,8 @@ class DPMReporter : public Reporter {
       default :
         break;
     }
+
+    facade_->SetMemoryTrimTimer();
   }
 
   list<shared_ptr<item::AbstractItem>> OnRequestEvent(const IEventInfo& info) override {
@@ -412,12 +435,15 @@ class DPMReporter : public Reporter {
                 facade_->receiver_group_list_);
 
     facade_->TranslateText(item_list);
+    facade_->SetMemoryTrimTimer();
 
     return item_list;
   }
 
   int OnRequestNumber(const IEventInfo& info) override {
     DBG("Get count !!! %s", info.GetItemId().c_str());
+    facade_->SetMemoryTrimTimer();
+
     return DBManager::GetNotificationList(facade_->GetUid(info)).size();
   }
 
@@ -521,6 +547,7 @@ class DPMManager : public Manager {
         DBG("SendError !!!");
         SendError(info, static_cast<NotificationError>(ret));
     }
+    facade_->SetMemoryTrimTimer();
   }
 
   void OnUpdate(const IEventInfo& info,
@@ -553,6 +580,7 @@ class DPMManager : public Manager {
     } else {
       SendError(info, static_cast<NotificationError>(ret));
     }
+    facade_->SetMemoryTrimTimer();
   }
 
   int DoDelete(const IEventInfo& info,
@@ -595,12 +623,15 @@ class DPMManager : public Manager {
       if (ret == ERROR_NONE)
         facade_->LaunchDefaultViewer(deletedList, NOTIFICATION_OP_DELETE);
     }
+    facade_->SetMemoryTrimTimer();
   }
 
   list<shared_ptr<item::AbstractItem>> OnRequestEvent(const IEventInfo& info) override {
     DBG("Get !!! %s", info.GetOwner().c_str());
     list<shared_ptr<item::AbstractItem>> item_list;
     uid_t uid = facade_->GetUid(info);
+    facade_->SetMemoryTrimTimer();
+
     if (info.GetItemId().empty()) {
       if (!info.GetChannel().empty()) {
         /* get by channel */
@@ -625,6 +656,8 @@ class DPMManager : public Manager {
     int count = 0;
     DBG("Get count !!! %s, %s", info.GetOwner().c_str(), info.GetChannel().c_str());
     DBManager::GetCount(info.GetOwner(), info.GetChannel(), facade_->GetUid(info), &count);
+    facade_->SetMemoryTrimTimer();
+
     return count;
   }
 
@@ -758,6 +791,7 @@ HAPI int notification_ex_service_init(int restart_count) {
         restart_count);
 
   notification_init_default_viewer();
+  facade_->SetMemoryTrimTimer();
 
   return ERROR_NONE;
 }