BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(jsoncpp)
BuildRequires: pkgconfig(capi-system-device)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(capi-appfw-package-manager)
SET(target "${PROJECT_NAME}-client-genuine")
-SET(DEPS "${DEPS} context-common-client")
+SET(DEPS "${DEPS} jsoncpp context-common-client")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
#include <string>
#include <utility>
-#include <CtxJson.h>
+#include <json/json.h>
#include <AppHistoryTypes.h>
#include <AppHistoryTypesPrivate.h>
#include <ServiceProxy.h>
EXPORT_API int ctx_history_query(const char* uri, int64_t start_time, int64_t end_time, unsigned int result_size, ctx_history_cursor_h* cursor)
{
- CtxJson filter;
- filter.set(NULL, KEY_START_TIME, start_time);
- filter.set(NULL, KEY_END_TIME, end_time);
- filter.set(NULL, KEY_RESULT_SIZE, (int64_t) result_size);
+ Json::Value filter;
+ filter[KEY_START_TIME] = start_time;
+ filter[KEY_END_TIME] = end_time;
+ filter[KEY_RESULT_SIZE] = (int64_t) result_size;
- return _ctx_history_query(uri, filter.str().c_str(), cursor);
+ Json::FastWriter fw;
+ fw.omitEndingLineFeed();
+ std::string filter_str = fw.write(filter);
+ return _ctx_history_query(uri, filter_str.c_str(), cursor);
}
EXPORT_API int _ctx_history_query(const char* uri, const char* filter, ctx_history_cursor_h* cursor)
SET(target "${PROJECT_NAME}-server-genuine")
-SET(DEPS "${DEPS} context-common-server capi-system-info capi-system-device capi-appfw-package-manager capi-appfw-app-manager vconf")
+SET(DEPS "${DEPS} jsoncpp context-common-server capi-system-info capi-system-device capi-appfw-package-manager capi-appfw-app-manager vconf")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
* limitations under the License.
*/
-#include <CtxJson.h>
+#include <json/json.h>
#include <ServerUtil.h>
#include "StatsManager.h"
#include "MethodCallHandler.h"
throw static_cast<int>(E_ACCESS);
}
- CtxJson jfilter = filter;
+ Json::Value jfilter;
+ Json::Reader reader;
+ reader.parse(std::string(filter), jfilter);
std::vector<std::shared_ptr<Tuple>> result;
std::vector<std::string> columnNames;
return true;
}
-int StatsProvider::read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
+int StatsProvider::read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
{
return E_NONE;
}
-std::string StatsProvider::getQuery(CtxJson& filter)
+std::string StatsProvider::getQuery(Json::Value& filter)
{
return "";
}
#include <sstream>
#include <vector>
-#include <CtxJson.h>
+#include <json/json.h>
#include <Tuple.h>
#include <IClient.h>
#include <AppHistoryTypes.h>
virtual bool isSupported(void);
virtual bool isAllowed(IClient& caller);
- virtual std::string getQuery(CtxJson& filter);
- virtual int read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
+ virtual std::string getQuery(Json::Value& filter);
+ virtual int read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
protected:
std::string __subject;
#include <sqlite3.h>
#include <glib.h>
#include <device/battery.h>
-#include <CtxJson.h>
#include <Tuple.h>
#include <Timer.h>
#include <AppHistoryTypesPrivate.h>
bool ret = __heartReader->dbOpen();
IF_FAIL_RETURN_TAG(ret, true, _E, "Failed to open heart db");
- std::vector<CtxJson> heartCpuLog;
+ std::vector<Json::Value> heartCpuLog;
ret = __heartReader->readCpuLog(__lastHeartAccessTime, &heartCpuLog);
__heartReader->dbClose();
IF_FAIL_RETURN_TAG(heartCpuLog.size() > 0, true, _W, "Heart cpu data is not prepared");
_D("Read %d rows from heart cpu table from %d", heartCpuLog.size(), __lastHeartAccessTime);
- heartCpuLog.back().get(NULL, BATTERY_TIMESTAMP, &__lastHeartAccessTime);
+ __lastHeartAccessTime = heartCpuLog.back()[BATTERY_TIMESTAMP].asInt64();
__updateLastInfo();
// Get last heart cpu log
ret = __getLastCpuUsageTable(&lastHeartCpuLog);
// Calculate per app battery usage
- std::vector<CtxJson> usage;
+ std::vector<Json::Value> usage;
BatteryUsageAnalyzer::calculateBatteryUsage(heartCpuLog, lastHeartCpuLog, &usage);
// Insert battery usage
return true;
}
-bool BatteryMonitor::__insertBatteryUsageLog(std::vector<CtxJson>& usage)
+bool BatteryMonitor::__insertBatteryUsageLog(std::vector<Json::Value>& usage)
{
IF_FAIL_RETURN_TAG(usage.size(), true, _W, "No data");
std::string query("INSERT INTO " BATTERY_USAGE_TABLE \
int stime, utime;
for (unsigned int i = 0; i < usage.size(); i++) {
- usage[i].get(NULL, BATTERY_APP_ID, &appId);
- usage[i].get(NULL, BATTERY_START_TIME, &startTime);
- usage[i].get(NULL, BATTERY_END_TIME, &endTime);
- usage[i].get(NULL, BATTERY_UTIME, &utime);
- usage[i].get(NULL, BATTERY_STIME, &stime);
+ appId = usage[i][BATTERY_APP_ID].asString();
+ startTime = usage[i][BATTERY_START_TIME].asInt();
+ endTime = usage[i][BATTERY_END_TIME].asInt();
+ utime = usage[i][BATTERY_UTIME].asInt();
+ stime = usage[i][BATTERY_STIME].asInt();
query += " ('" + appId + "', "
+ std::to_string(startTime) + ", "
bool __updateLastInfo();
bool __processBatteryUsage();
- bool __insertBatteryUsageLog(std::vector<CtxJson>& usage);
+ bool __insertBatteryUsageLog(std::vector<Json::Value>& usage);
bool __updateLastCpuUsageLog(CpuUsageMap& usage);
bool __getLastCpuUsageTable(CpuUsageMap* lastCpuUsage);
void __modifyLastCpuUsage(int timeDiff);
return supported;
}
-std::string BatteryStatsProvider::getQuery(CtxJson& filter)
+std::string BatteryStatsProvider::getQuery(Json::Value& filter)
{
std::string query;
return query;
}
-std::string BatteryStatsProvider::createBatteryUsageQuery(CtxJson& filter)
+std::string BatteryStatsProvider::createBatteryUsageQuery(const Json::Value& filter)
{
std::stringstream query;
int startTime;
int endTime;
- int timeSpan = DEFAULT_TIME_SPAN;
+ int timeSpan = filter.get(KEY_TIME_SPAN, DEFAULT_TIME_SPAN).asInt();
int timeSpanPoint;
- int resultSize = BATTERY_DEFAULT_LIMIT;
+ int resultSize = filter.get(KEY_RESULT_SIZE, BATTERY_DEFAULT_LIMIT).asInt();
- filter.get(NULL, KEY_TIME_SPAN, &timeSpan);
timeSpanPoint = CURRENT_TIME - timeSpan * SECONDS_IN_A_DAY;
- if (!filter.get(NULL, KEY_START_TIME, &startTime)) {
- startTime = timeSpanPoint;
- }
-
- if (!filter.get(NULL, KEY_END_TIME, &endTime)) {
- endTime = CURRENT_TIME;
- }
+ startTime = filter.get(KEY_START_TIME, timeSpanPoint).asInt();
+ endTime = filter.get(KEY_END_TIME, CURRENT_TIME).asInt();
if (startTime < timeSpanPoint) {
startTime = timeSpanPoint;
}
- filter.get(NULL, KEY_RESULT_SIZE, &resultSize);
-
query <<
"SELECT " BATTERY_APP_ID " AS " KEY_APP_ID ", " \
"ROUND(100.0 * SUM(" BATTERY_TOTAL_TIME ") / " \
return query.str();
}
-std::string BatteryStatsProvider::createRecentBatteryUsageQuery(CtxJson& filter)
+std::string BatteryStatsProvider::createRecentBatteryUsageQuery(const Json::Value& filter)
{
std::stringstream query;
int startTime = BatteryMonitor::getInstance()->getLastFullTime();
int endTime = CURRENT_TIME;
- int resultSize = BATTERY_DEFAULT_LIMIT;
-
- filter.get(NULL, KEY_RESULT_SIZE, &resultSize);
+ int resultSize = filter.get(KEY_RESULT_SIZE, BATTERY_DEFAULT_LIMIT).asInt();
query <<
"SELECT " BATTERY_APP_ID " AS " KEY_APP_ID ", " \
virtual ~BatteryStatsProvider();
bool isSupported(void);
- std::string getQuery(CtxJson& filter);
+ std::string getQuery(Json::Value& filter);
protected:
- std::string createBatteryUsageQuery(CtxJson& filter);
- std::string createRecentBatteryUsageQuery(CtxJson& filter);
+ std::string createBatteryUsageQuery(const Json::Value& filter);
+ std::string createRecentBatteryUsageQuery(const Json::Value& filter);
};
{
}
-int BatteryUsageProvider::read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
+int BatteryUsageProvider::read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
{
BatteryMonitor::getInstance()->prepareData();
BatteryUsageProvider();
~BatteryUsageProvider();
- int read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
+ int read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
};
}
{
}
-void BatteryUsageAnalyzer::calculateBatteryUsage(std::vector<CtxJson>& cpuLog, CpuUsageMap& recentCpuUsageMap, std::vector<CtxJson>* usage)
+void BatteryUsageAnalyzer::calculateBatteryUsage(std::vector<Json::Value>& cpuLog, CpuUsageMap& recentCpuUsageMap, std::vector<Json::Value>* usage)
{
std::string appId;
int timestamp;
int pid;
for (unsigned int i = 0; i < cpuLog.size(); i++) {
- cpuLog[i].get(NULL, BATTERY_APP_ID, &appId);
- cpuLog[i].get(NULL, BATTERY_TIMESTAMP, ×tamp);
- cpuLog[i].get(NULL, BATTERY_UTIME, &utime);
- cpuLog[i].get(NULL, BATTERY_STIME, &stime);
- cpuLog[i].get(NULL, BATTERY_INDEX, &idx);
- cpuLog[i].get(NULL, BATTERY_PID, &pid);
+ appId = cpuLog[i][BATTERY_APP_ID].asString();
+ timestamp = cpuLog[i][BATTERY_TIMESTAMP].asInt();
+ utime = cpuLog[i][BATTERY_UTIME].asInt();
+ stime = cpuLog[i][BATTERY_STIME].asInt();
+ idx = cpuLog[i][BATTERY_INDEX].asInt();
+ pid = cpuLog[i][BATTERY_PID].asInt();
//If CPU table is reset, clear last cpu usage
if (idx == 0) {
if (prevTimestamp > timestamp)
prevTimestamp = timestamp;
- CtxJson row;
- row.set(NULL, BATTERY_APP_ID, appId);
- row.set(NULL, BATTERY_START_TIME, prevTimestamp);
- row.set(NULL, BATTERY_END_TIME, timestamp);
- row.set(NULL, BATTERY_UTIME, utime - prevUtime);
- row.set(NULL, BATTERY_STIME, stime - prevStime);
+ Json::Value row;
+ row[BATTERY_APP_ID] = appId;
+ row[BATTERY_START_TIME] = prevTimestamp;
+ row[BATTERY_END_TIME] = timestamp;
+ row[BATTERY_UTIME] = utime - prevUtime;
+ row[BATTERY_STIME] = stime - prevStime;
usage->push_back(row);
#define __CONTEXT_BATTERY_USAGE_ANALYZER_H__
#include <vector>
-#include <CtxJson.h>
+#include <json/json.h>
#include "BatteryStatisticsTypes.h"
namespace ctx {
BatteryUsageAnalyzer();
~BatteryUsageAnalyzer();
- static void calculateBatteryUsage(std::vector<CtxJson>& cpuUsageLog, CpuUsageMap& lastCpuUsage, std::vector<CtxJson>* usage);
+ static void calculateBatteryUsage(std::vector<Json::Value>& cpuUsageLog, CpuUsageMap& lastCpuUsage, std::vector<Json::Value>* usage);
};
} /* namespace ctx */
*/
#include <sstream>
-#include <CtxJson.h>
+#include <json/json.h>
#include <ServerUtil.h>
#include "BatteryStatisticsTypes.h"
#include "HeartDbReader.h"
__dbRefCount = 0;
}
-bool HeartDbReader::readCpuLog(int lastHeartAccessTime, std::vector<CtxJson>* cpuUsageLog)
+bool HeartDbReader::readCpuLog(int lastHeartAccessTime, std::vector<Json::Value>* cpuUsageLog)
{
IF_FAIL_RETURN(__heartDb, false);
{
IF_FAIL_RETURN(userData, 0);
- std::vector<CtxJson> *records = static_cast<std::vector<CtxJson>*>(userData);
- CtxJson row;
- CtxJson newRow;
+ std::vector<Json::Value> *records = static_cast<std::vector<Json::Value>*>(userData);
+ std::map<std::string, std::string> row;
+
bool columnNull = false;
for (int i = 0; i < dim; ++i) {
break;
}
- row.set(NULL, column[i], value[i]);
+ row[column[i]] = value[i];
}
- if (!columnNull) {
- __convertCpuUsageLog(row, &newRow);
- records->push_back(newRow);
- }
+ if (columnNull)
+ return 0;
- return 0;
-}
+ auto convToJson = [](std::map<std::string, std::string>& in)->Json::Value {
+ Json::Value jval;
+ int utime;
+ int stime;
+ int pid;
+ int type;
-void HeartDbReader::__convertCpuUsageLog(CtxJson& row, CtxJson* newRow)
-{
- std::string appId;
- std::string timestamp;
- std::string data;
- int utime;
- int stime;
- int pid;
- int type;
- int index;
-
- row.get(NULL, HEART_APP_ID, &appId);
- row.get(NULL, HEART_TIME, ×tamp);
- row.get(NULL, HEART_DATA, &data);
- row.get(NULL, HEART_INDEX, &index);
-
- std::stringstream buf(data);
- buf >> utime >> stime >> pid >> type;
-
- newRow->set(NULL, BATTERY_APP_ID, appId);
- newRow->set(NULL, BATTERY_TIMESTAMP, atoi(timestamp.c_str()));
- newRow->set(NULL, BATTERY_UTIME, utime);
- newRow->set(NULL, BATTERY_STIME, stime);
- newRow->set(NULL, BATTERY_TYPE, type);
- newRow->set(NULL, BATTERY_INDEX, index);
- newRow->set(NULL, BATTERY_PID, pid);
+ std::stringstream buf(in[HEART_DATA]);
+ buf >> utime >> stime >> pid >> type;
+
+ jval[BATTERY_APP_ID] = in[HEART_APP_ID];
+ jval[BATTERY_TIMESTAMP] = atoi(in[HEART_TIME].c_str());
+ jval[BATTERY_INDEX] = atoi(in[HEART_INDEX].c_str());
+
+ jval[BATTERY_UTIME] = utime;
+ jval[BATTERY_STIME] = stime;
+ jval[BATTERY_TYPE] = type;
+ jval[BATTERY_PID] = pid;
+
+ return jval;
+ };
+
+ records->push_back(convToJson(row));
+
+ return 0;
}
bool HeartDbReader::__initializeDBusConnection()
bool dbOpen();
void dbClose();
- bool readCpuLog(int __lastHeartAccessTime, std::vector<CtxJson>* cpuUsageLog);
+ bool readCpuLog(int __lastHeartAccessTime, std::vector<Json::Value>* cpuUsageLog);
bool requestSync();
private:
static int __cpuUsageLogCb(void *userData, int dim, char **value, char **column);
- static void __convertCpuUsageLog(CtxJson& row, CtxJson* newRow);
bool __initializeDBusConnection();
void __releaseDBusConnection();
{
}
-int RecentBatteryUsageProvider::read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
+int RecentBatteryUsageProvider::read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
{
BatteryMonitor::getInstance()->prepareData();
RecentBatteryUsageProvider();
~RecentBatteryUsageProvider();
- int read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
+ int read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
};
}
{
}
-int UsageStatsProvider::read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
+int UsageStatsProvider::read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records)
{
std::string query = getQuery(filter);
bool ret = execute(query, COL_STRING COL_INT64 COL_INT64 COL_INT64, columnNames, records);
return E_NONE;
}
-std::string UsageStatsProvider::getQuery(CtxJson& filter)
+std::string UsageStatsProvider::getQuery(Json::Value& filter)
{
std::string query;
return query;
}
-std::string UsageStatsProvider::__createSqlRecentlyUsed(CtxJson filter)
+std::string UsageStatsProvider::__createSqlRecentlyUsed(const Json::Value& filter)
{
std::stringstream query;
- int limit = DEFAULT_LIMIT;
-
- filter.get(NULL, KEY_RESULT_SIZE, &limit);
+ int limit = filter.get(KEY_RESULT_SIZE, DEFAULT_LIMIT).asInt();
query <<
"SELECT " KEY_APP_ID ", " \
return query.str();
}
-std::string UsageStatsProvider::__createSqlFrequentlyUsed(CtxJson filter)
+std::string UsageStatsProvider::__createSqlFrequentlyUsed(const Json::Value& filter)
{
std::stringstream query;
- int limit = DEFAULT_LIMIT;
-
- filter.get(NULL, KEY_RESULT_SIZE, &limit);
+ int limit = filter.get(KEY_RESULT_SIZE, DEFAULT_LIMIT).asInt();
query <<
"SELECT " KEY_APP_ID ", " \
return query.str();
}
-std::string UsageStatsProvider::__createSqlRarelyUsed(CtxJson filter)
+std::string UsageStatsProvider::__createSqlRarelyUsed(const Json::Value& filter)
{
std::stringstream query;
- int limit = DEFAULT_LIMIT;
-
- filter.get(NULL, KEY_RESULT_SIZE, &limit);
+ int limit = filter.get(KEY_RESULT_SIZE, DEFAULT_LIMIT).asInt();
query <<
"SELECT i." KEY_APP_ID ", " \
return query.str();
}
-std::string UsageStatsProvider::__createWhereClause(CtxJson filter)
+std::string UsageStatsProvider::__createWhereClause(const Json::Value& filter)
{
std::stringstream whereClause;
- int start = 0;
- int end = 0;
- int timeSpan = DEFAULT_TIME_SPAN;
- if (filter.get(NULL, KEY_START_TIME, &start))
- whereClause << KEY_UNIV_TIME " >= " << start << " AND ";
+ if (filter.isMember(KEY_START_TIME))
+ whereClause << KEY_UNIV_TIME " >= " << filter[KEY_START_TIME].asInt() << " AND ";
- if (filter.get(NULL, KEY_END_TIME, &end))
- whereClause << KEY_UNIV_TIME " <= " << end << " AND ";
+ if (filter.isMember(KEY_END_TIME))
+ whereClause << KEY_UNIV_TIME " <= " << filter[KEY_END_TIME].asInt() << " AND ";
/* TODO */
- filter.get(NULL, KEY_TIME_SPAN, &timeSpan);
- whereClause << KEY_UNIV_TIME " > strftime('%s', 'now', '-" << timeSpan <<" day')";
+ whereClause << KEY_UNIV_TIME " > strftime('%s', 'now', '-" << filter.get(KEY_TIME_SPAN, DEFAULT_TIME_SPAN).asInt() <<" day')";
return whereClause.str();
}
class UsageStatsProvider : public StatsProvider {
public:
- int read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
+ int read(Json::Value& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);
protected:
UsageStatsProvider(const char *subject);
virtual ~UsageStatsProvider();
- std::string getQuery(CtxJson& filter);
+ std::string getQuery(Json::Value& filter);
private:
- std::string __createSqlRecentlyUsed(CtxJson filter);
- std::string __createSqlFrequentlyUsed(CtxJson filter);
- std::string __createSqlRarelyUsed(CtxJson filter);
- std::string __createWhereClause(CtxJson filter);
+ std::string __createSqlRecentlyUsed(const Json::Value& filter);
+ std::string __createSqlFrequentlyUsed(const Json::Value& filter);
+ std::string __createSqlRarelyUsed(const Json::Value& filter);
+ std::string __createWhereClause(const Json::Value& filter);
};