From: Mu-Woong Lee Date: Wed, 27 Apr 2016 10:16:20 +0000 (+0900) Subject: Remove daily timer of the social stats logger X-Git-Tag: submit/tizen/20160503.015801^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4449a92e4b9665d0d86d10bfe268f14b8407c27;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git Remove daily timer of the social stats logger Call log mirroring only occurs when a client request is raised Change-Id: Ifc79b00b1cd0ecd8a10004e94de6fd08dde0c88d Signed-off-by: Mu-Woong Lee --- diff --git a/include/ProviderTypes.h b/include/ProviderTypes.h index 2ab4a96..79817b3 100644 --- a/include/ProviderTypes.h +++ b/include/ProviderTypes.h @@ -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" diff --git a/src/social-stats/LogAggregator.cpp b/src/social-stats/LogAggregator.cpp index 2fc9608..ecee5e2 100644 --- a/src/social-stats/LogAggregator.cpp +++ b/src/social-stats/LogAggregator.cpp @@ -21,40 +21,28 @@ #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, ¤tTime); _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); diff --git a/src/social-stats/LogAggregator.h b/src/social-stats/LogAggregator.h index cc3962d..bd226f3 100644 --- a/src/social-stats/LogAggregator.h +++ b/src/social-stats/LogAggregator.h @@ -19,18 +19,16 @@ #include #include -#include 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& records); - bool onTimerExpired(int timerId); }; /* class ContactLogAggregator */ diff --git a/src/social-stats/SocialStatisticsTypes.h b/src/social-stats/SocialStatisticsTypes.h index cbe852d..41b5666 100644 --- a/src/social-stats/SocialStatisticsTypes.h +++ b/src/social-stats/SocialStatisticsTypes.h @@ -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 index 6e1b869..0000000 --- a/src/social-stats/SocialStatsLogger.cpp +++ /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 &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 index 3d15128..0000000 --- a/src/social-stats/SocialStatsLogger.h +++ /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 -#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 &privilege); - - private: - ContactLogAggregator __aggregator; - }; - -} /* namespace ctx */ - -#endif /* _CONTEXT_SOCIAL_STATS_LOGGER_H_ */ - diff --git a/src/social-stats/SocialStatsProvider.cpp b/src/social-stats/SocialStatsProvider.cpp index 22d46b5..552473c 100644 --- a/src/social-stats/SocialStatsProvider.cpp +++ b/src/social-stats/SocialStatsProvider.cpp @@ -14,14 +14,23 @@ * 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() diff --git a/src/social-stats/create.cpp b/src/social-stats/create.cpp index 6b318b9..60a1a55 100644 --- a/src/social-stats/create.cpp +++ b/src/social-stats/create.cpp @@ -16,13 +16,11 @@ #include #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);