Remove daily timer of the social stats logger 90/67590/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 27 Apr 2016 10:16:20 +0000 (19:16 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 27 Apr 2016 10:16:20 +0000 (19:16 +0900)
Call log mirroring only occurs when a client request is raised

Change-Id: Ifc79b00b1cd0ecd8a10004e94de6fd08dde0c88d
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/ProviderTypes.h
src/social-stats/LogAggregator.cpp
src/social-stats/LogAggregator.h
src/social-stats/SocialStatisticsTypes.h
src/social-stats/SocialStatsLogger.cpp [deleted file]
src/social-stats/SocialStatsLogger.h [deleted file]
src/social-stats/SocialStatsProvider.cpp
src/social-stats/create.cpp

index 2ab4a96..79817b3 100644 (file)
@@ -82,7 +82,6 @@
 #define SUBJ_VIDEO_FREQUENCY           SUBJ_VIDEO_STATS "frequency"
 
 #define SUBJ_SOCIAL_STATS                      "stats/contact/"
-#define SUBJ_SOCIAL_LOGGER                     SUBJ_SOCIAL_STATS "logger"
 #define SUBJ_SOCIAL_FREQ_ADDRESS       SUBJ_SOCIAL_STATS "often"
 #define SUBJ_SOCIAL_FREQUENCY          SUBJ_SOCIAL_STATS "frequency"
 
index 2fc9608..ecee5e2 100644 (file)
 #include "LogAggregator.h"
 
 ctx::ContactLogAggregator::ContactLogAggregator() :
-       __timerId(-1),
        __timeDiff(0)
 {
        __createTable();
-       __timerId = __timerManager.setAt(3, 0, DayOfWeek::EVERYDAY, this);
+       __aggregateContactLog();
 }
 
 ctx::ContactLogAggregator::~ContactLogAggregator()
 {
-       __timerManager.remove(__timerId);
 }
 
 void ctx::ContactLogAggregator::__createTable()
 {
-       static bool done = false;
-       IF_FAIL_VOID(!done);
-
        __dbManager.createTable(0, SOCIAL_TABLE_CONTACT_LOG, SOCIAL_TABLE_CONTACT_LOG_COLUMNS, NULL, NULL);
        __dbManager.execute(0, SOCIAL_TEMP_CONTACT_FREQ_SQL, NULL);
-
-       done = true;
-}
-
-bool ctx::ContactLogAggregator::onTimerExpired(int timerId)
-{
-       aggregateContactLog();
-       return true;
 }
 
-void ctx::ContactLogAggregator::aggregateContactLog()
+void ctx::ContactLogAggregator::__aggregateContactLog()
 {
        __dbManager.execute(0,
                        "SELECT IFNULL(MAX(" KEY_UNIV_TIME "),0) AS " KEY_LAST_TIME \
                        ", (strftime('%s', 'now', 'localtime')) - (strftime('%s', 'now')) AS " TIME_DIFFERENCE \
+                       ", (strftime('%s', 'now')) AS " CURRENT_TIME \
                        " FROM " SOCIAL_TABLE_CONTACT_LOG, this);
 }
 
@@ -63,19 +51,27 @@ void ctx::ContactLogAggregator::onExecuted(unsigned int queryId, int error, std:
        IF_FAIL_VOID_TAG(!records.empty(), _E, "Invalid query result");
 
        int lastTime = 0;
+       int currentTime = 0;
+
        records[0].get(NULL, KEY_LAST_TIME, &lastTime);
        records[0].get(NULL, TIME_DIFFERENCE, &__timeDiff);
+       records[0].get(NULL, CURRENT_TIME, &currentTime);
 
        _D("Last Time: %d / Local - UTC: %d", lastTime, __timeDiff);
 
        contacts_list_h list = NULL;
 
+       if (lastTime < currentTime - LOG_RETENTION_PERIOD)
+               lastTime = currentTime - LOG_RETENTION_PERIOD;
+
        __getUpdatedContactLogList(lastTime, &list);
        IF_FAIL_VOID(list);
 
        __removeExpiredLog();
        __insertContactLogList(list);
        __destroyContactLogList(list);
+
+       delete this;
 }
 
 void ctx::ContactLogAggregator::__getUpdatedContactLogList(int lastTime, contacts_list_h *list)
@@ -124,6 +120,8 @@ void ctx::ContactLogAggregator::__insertContactLogList(contacts_list_h list)
 {
        IF_FAIL_VOID(contacts_list_first(list) == CONTACTS_ERROR_NONE);
 
+       /* TODO: optimize here using transaction */
+
        do {
                contacts_record_h record = NULL;
                contacts_list_get_current_record_p(list, &record);
index cc3962d..bd226f3 100644 (file)
 
 #include <contacts.h>
 #include <DatabaseManager.h>
-#include <TimerManager.h>
 
 namespace ctx {
 
-       class ContactLogAggregator : public IDatabaseListener, public ITimerListener {
+       class ContactLogAggregator : public IDatabaseListener {
        private:
-               int __timerId;
                int __timeDiff;
-               TimerManager __timerManager;
                DatabaseManager __dbManager;
 
                void __createTable();
+               void __aggregateContactLog();
                void __getUpdatedContactLogList(int last_time, contacts_list_h *list);
                void __insertContactLogList(contacts_list_h list);
                void __destroyContactLogList(contacts_list_h list);
@@ -40,12 +38,9 @@ namespace ctx {
                ContactLogAggregator();
                ~ContactLogAggregator();
 
-               void aggregateContactLog();
-
                void onTableCreated(unsigned int queryId, int error) {}
                void onInserted(unsigned int queryId, int error, int64_t rowId) {}
                void onExecuted(unsigned int queryId, int error, std::vector<Json>& records);
-               bool onTimerExpired(int timerId);
 
        };      /* class ContactLogAggregator */
 
index cbe852d..41b5666 100644 (file)
@@ -40,6 +40,7 @@
 #define SOCIAL_ADDRESS                         "Address"
 #define SOCIAL_PHONE_LOG_TYPE          "PLogType"
 #define TIME_DIFFERENCE                                "TimeDIff"
+#define CURRENT_TIME                           "CurrentTime"
 
 enum SocialCommType {
        SOCIAL_COMMUNICATION_TYPE_CALL = 1,
diff --git a/src/social-stats/SocialStatsLogger.cpp b/src/social-stats/SocialStatsLogger.cpp
deleted file mode 100644 (file)
index 6e1b869..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SocialStatisticsTypes.h"
-#include "SocialStatsLogger.h"
-
-using namespace ctx;
-
-SocialStatsLogger::SocialStatsLogger() :
-       ContextProvider(SOCIAL_SUBJ_LOGGER)
-{
-}
-
-SocialStatsLogger::~SocialStatsLogger()
-{
-}
-
-void SocialStatsLogger::getPrivilege(std::vector<const char*> &privilege)
-{
-       privilege.push_back(PRIV_CALL_HISTORY);
-}
-
-int SocialStatsLogger::subscribe(Json option, Json* requestResult)
-{
-       return ERR_NONE;
-}
-
-int SocialStatsLogger::unsubscribe(Json option)
-{
-       return ERR_NONE;
-}
diff --git a/src/social-stats/SocialStatsLogger.h b/src/social-stats/SocialStatsLogger.h
deleted file mode 100644 (file)
index 3d15128..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_SOCIAL_STATS_LOGGER_H_
-#define _CONTEXT_SOCIAL_STATS_LOGGER_H_
-
-#include <ContextProvider.h>
-#include "LogAggregator.h"
-
-namespace ctx {
-
-       class SocialStatsLogger : public ContextProvider {
-       public:
-               SocialStatsLogger();
-               ~SocialStatsLogger();
-
-               int subscribe(Json option, Json* requestResult);
-               int unsubscribe(Json option);
-               void getPrivilege(std::vector<const char*> &privilege);
-
-       private:
-               ContactLogAggregator __aggregator;
-       };
-
-}      /* namespace ctx */
-
-#endif /* _CONTEXT_SOCIAL_STATS_LOGGER_H_ */
-
index 22d46b5..552473c 100644 (file)
  * limitations under the License.
  */
 
-#include "SocialStatsProvider.h"
 #include "DbHandle.h"
+#include "LogAggregator.h"
+#include "SocialStatsProvider.h"
 
 using namespace ctx;
 
 SocialStatsProvider::SocialStatsProvider(const char *subject) :
        ContextProvider(subject)
 {
+       static bool done = false;
+       IF_FAIL_VOID(!done);
+
+       done = true;
+
+       ContactLogAggregator *aggr = new(std::nothrow) ContactLogAggregator();
+       if(!aggr)
+               _E("Memory allocation failed");
 }
 
 SocialStatsProvider::~SocialStatsProvider()
index 6b318b9..60a1a55 100644 (file)
 
 #include <create.h>
 #include "SocialStatsProvider.h"
-#include "SocialStatsLogger.h"
 
 using namespace ctx;
 
 extern "C" SO_EXPORT ContextProvider* create(const char *subject)
 {
-       ADD_PROVIDER(SUBJ_SOCIAL_LOGGER, SocialStatsLogger);
        ADD_PROVIDER(SUBJ_SOCIAL_FREQ_ADDRESS, TopContactsProvider);
        ADD_PROVIDER(SUBJ_SOCIAL_FREQUENCY, ContactFreqProvider);