#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"
#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);
}
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)
{
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);
#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);
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 */
#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,
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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_ */
-
* 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()
#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);