BuildRequires: cmake
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gio-2.0)
-BuildRequires: pkgconfig(jsoncpp)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(sensor)
BuildRequires: pkgconfig(capi-base-common)
SET(target "${PROJECT_NAME}-client-genuine")
-SET(DEPS "${DEPS} jsoncpp context-common-client")
+SET(DEPS "${DEPS} context-common-client")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
* limitations under the License.
*/
-#include <json/json.h>
#include <sensor_recorder_internal.h>
#include <SensorRecorderTypesPrivate.h>
#include <ServiceProxy.h>
+#include <CtxJson.h>
#include "QueryResultListener.h"
#define STR_BUFFER_SIZE 128
IF_FAIL_RETURN(subject, E_PARAM);
std::string optionStr;
- if (option) {
- Json::FastWriter fw;
- fw.omitEndingLineFeed();
- optionStr = fw.write(*static_cast<Json::Value*>(option));
- }
+ if (option)
+ optionStr = static_cast<ctx::CtxJson *>(option)->str();
GVariant* param = g_variant_new("(ss)", subject, optionStr.c_str());
{
IF_FAIL_RETURN(option, E_PARAM);
- *option = new(std::nothrow) Json::Value;
+ *option = new(std::nothrow) ctx::CtxJson;
IF_FAIL_RETURN(*option, E_NO_MEM);
return E_NONE;
{
IF_FAIL_RETURN(option, E_PARAM);
- delete static_cast<Json::Value*>(option);
+ delete static_cast<ctx::CtxJson*>(option);
return E_NONE;
}
IF_FAIL_RETURN(STR_EQ(param, CTX_SENSOR_RECORDER_KEY_INTERVAL) ||
STR_EQ(param, CTX_SENSOR_RECORDER_KEY_RETENTION), E_PARAM);
- Json::Value& optionJson = *static_cast<Json::Value*>(option);
- optionJson[param] = value;
+ ctx::CtxJson* optionCtxJson = static_cast<ctx::CtxJson*>(option);
+ optionCtxJson->set(NULL, param, static_cast<int64_t>(value));
return E_NONE;
}
{
IF_FAIL_RETURN(query, E_PARAM);
- *query = new(std::nothrow) Json::Value;
+ *query = new(std::nothrow) ctx::CtxJson;
IF_FAIL_RETURN(*query, E_NO_MEM);
return E_NONE;
{
IF_FAIL_RETURN(query, E_PARAM);
- delete static_cast<Json::Value*>(query);
+ delete static_cast<ctx::CtxJson*>(query);
return E_NONE;
}
STR_EQ(param, CTX_SENSOR_RECORDER_KEY_START_TIME) ||
STR_EQ(param, CTX_SENSOR_RECORDER_KEY_END_TIME), E_PARAM);
- Json::Value& queryJson = *static_cast<Json::Value*>(query);
- queryJson[param] = value;
+ ctx::CtxJson* queryCtxJson = static_cast<ctx::CtxJson*>(query);
+ queryCtxJson->set(NULL, param, static_cast<int64_t>(value));
return E_NONE;
}
STR_EQ(param, CTX_SENSOR_RECORDER_KEY_START_TIME) ||
STR_EQ(param, CTX_SENSOR_RECORDER_KEY_END_TIME), E_PARAM);
- Json::Value& queryJson = *static_cast<Json::Value*>(query);
- queryJson[param] = static_cast<int64_t>(t);
+ ctx::CtxJson* queryCtxJson = static_cast<ctx::CtxJson*>(query);
+ queryCtxJson->set(NULL, param, static_cast<int64_t>(t));
return E_NONE;
}
QueryResultListener* listener = new(std::nothrow) QueryResultListener(subject, cb, user_data);
IF_FAIL_RETURN_TAG(listener, E_NO_MEM, _E, E_STR_ALLOC);
- Json::FastWriter fw;
- fw.omitEndingLineFeed();
- std::string queryStr = fw.write(*static_cast<Json::Value*>(query));
+ std::string queryStr = static_cast<ctx::CtxJson*>(query)->str();
GVariant* param = g_variant_new("(ss)", subject, queryStr.c_str());
int error = __getServiceProxy()->call(METHOD_READ_REC, param, listener);
QueryResultListener* listener = new(std::nothrow) QueryResultListener(subject, cb, user_data);
IF_FAIL_RETURN_TAG(listener, E_NO_MEM, _E, E_STR_ALLOC);
- Json::FastWriter fw;
- fw.omitEndingLineFeed();
- std::string queryStr = fw.write(*static_cast<Json::Value*>(query));
+ std::string queryStr = static_cast<ctx::CtxJson*>(query)->str();
GVariant* param = g_variant_new("(ss)", subject, queryStr.c_str());
GVariant* outParam = NULL;
SET(target "${PROJECT_NAME}-server-genuine")
-SET(DEPS "${DEPS} jsoncpp context-common-server capi-system-info sensor")
+SET(DEPS "${DEPS} context-common-server capi-system-info sensor")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
return ret ? E_NONE : E_FAILED;
}
-int Querier::queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int Querier::queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
return E_PARAM;
}
-int Querier::query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int Querier::query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
return E_PARAM;
}
-int Querier::query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
+int Querier::query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
{
_D("Ignore anchor & interval");
return query(startTime, endTime, tuples);
virtual std::string getProjection();
- virtual int queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- virtual int query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- virtual int query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
+ virtual int queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ virtual int query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ virtual int query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
protected:
int query(const char *sql, std::vector<std::shared_ptr<Tuple>>* tuples);
__uninstallMonitor = NULL;
}
-int RecorderClientInfo::get(std::string subject, std::string pkgId, Json::Value& option)
+int RecorderClientInfo::get(std::string subject, std::string pkgId, CtxJson& option)
{
bool ret;
std::string optStr;
IF_FAIL_RETURN(!tuples.empty(), E_NO_DATA);
tuples[0]->getAt(0, &optStr);
-
- Json::Reader jr;
- jr.parse(optStr, option);
+ option = optStr;
return E_NONE;
}
-int RecorderClientInfo::get(std::string subject, std::vector<Json::Value>& options)
+int RecorderClientInfo::get(std::string subject, std::vector<CtxJson>& options)
{
bool ret;
std::string optStr;
IF_FAIL_RETURN(ret, E_FAILED);
IF_FAIL_RETURN(!tuples.empty(), E_NO_DATA);
- Json::Reader jr;
-
for (auto& tuple : tuples) {
tuple->getAt(0, &optStr);
-
- Json::Value opt;
- jr.parse(optStr, opt);
-
- options.push_back(opt);
+ options.push_back(CtxJson(optStr));
}
return E_NONE;
return true;
}
-bool RecorderClientInfo::set(std::string subject, std::string pkgId, const Json::Value& option, int retentionPeriod)
+bool RecorderClientInfo::set(std::string subject, std::string pkgId, CtxJson option, int retentionPeriod)
{
bool ret;
- Json::FastWriter fw;
- fw.omitEndingLineFeed();
-
char *query = sqlite3_mprintf(
"INSERT INTO " CLIENT_INFO " VALUES ('%q', '%q', '%q', %d)",
- subject.c_str(), pkgId.c_str(), fw.write(option).c_str(), retentionPeriod);
+ subject.c_str(), pkgId.c_str(), option.str().c_str(), retentionPeriod);
ret = SensorDatabase::execute(query, NULL);
sqlite3_free(query);
return ret;
}
-void RecorderClientInfo::getParam(std::vector<Json::Value> &options, const char *key, float *min, float *max)
+void RecorderClientInfo::getParam(std::vector<CtxJson> &options, const char *key, float *min, float *max)
{
- for (auto& opt : options) {
- if (!opt.isMember(key))
+ double val;
+
+ for (CtxJson& opt : options) {
+ if (!opt.get(NULL, key, &val))
continue;
if (min)
- *min = MIN(*min, static_cast<float>(opt[key].asInt64()));
+ *min = MIN(*min, static_cast<float>(val));
if (max)
- *max = MAX(*max, static_cast<float>(opt[key].asInt64()));
+ *max = MAX(*max, static_cast<float>(val));
}
}
#ifndef __SENSOR_RECORDER_CLIENT_INFO_H__
#define __SENSOR_RECORDER_CLIENT_INFO_H__
-#include <json/json.h>
#include <string>
#include <vector>
+#include <CtxJson.h>
#include <SensorRecorderTypesPrivate.h>
#include "UninstallMonitor.h"
RecorderClientInfo();
~RecorderClientInfo();
- int get(std::string subject, std::string pkgId, Json::Value& option);
- int get(std::string subject, std::vector<Json::Value>& options);
+ int get(std::string subject, std::string pkgId, CtxJson& option);
+ int get(std::string subject, std::vector<CtxJson>& options);
bool exist(std::string subject);
- bool set(std::string subject, std::string pkgId, const Json::Value& option, int retentionPeriod);
+ bool set(std::string subject, std::string pkgId, CtxJson option, int retentionPeriod);
bool remove(std::string subject, std::string pkgId);
- void getParam(std::vector<Json::Value>& options, const char *key, float *min, float *max);
+ void getParam(std::vector<CtxJson>& options, const char *key, float *min, float *max);
static void purgeClient(std::string pkgId);
static void setHostService(SensorRecorderService* hostService);
return NULL;
}
-int SensorProvider::readRecords(const std::string& option, std::string* projection, std::vector<std::shared_ptr<Tuple>>* tuples)
+int SensorProvider::readRecords(CtxJson option, std::string* projection, std::vector<std::shared_ptr<Tuple>>* tuples)
{
- time_t endTime = time(NULL) + 1;
- time_t startTime = endTime - DEFAULT_QUERY_PERIOD - 1;
- time_t anchor = -1;
+ int endTime = static_cast<int>(time(NULL)) + 1;
+ int startTime = endTime - DEFAULT_QUERY_PERIOD - 1;
+ int anchor = -1;
int interval = -1;
- Json::Reader jr;
- Json::Value optionJson;
- jr.parse(option, optionJson);
+ if (option.get(NULL, KEY_START_TIME, &startTime))
+ IF_FAIL_RETURN(startTime >= 0, E_PARAM);
- startTime = static_cast<time_t>(optionJson.get(KEY_START_TIME, static_cast<int64_t>(startTime)).asInt64());
- IF_FAIL_RETURN(startTime >= 0, E_PARAM);
+ if (option.get(NULL, KEY_END_TIME, &endTime))
+ IF_FAIL_RETURN(endTime >= 0, E_PARAM);
- endTime = static_cast<time_t>(optionJson.get(KEY_END_TIME, static_cast<int64_t>(endTime)).asInt64());
- IF_FAIL_RETURN(endTime >= 0, E_PARAM);
-
- if (optionJson.isMember(KEY_ANCHOR)) {
- anchor = static_cast<time_t>(optionJson[KEY_ANCHOR].asInt64());
+ if (option.get(NULL, KEY_ANCHOR, &anchor))
IF_FAIL_RETURN(anchor >= 0, E_PARAM);
- }
- if (optionJson.isMember(KEY_INTERVAL)) {
- interval = optionJson[KEY_INTERVAL].asInt();
+ if (option.get(NULL, KEY_INTERVAL, &interval))
IF_FAIL_RETURN(interval >= 0, E_PARAM);
- }
if (endTime >= 0 && startTime >= endTime)
return E_PARAM;
return ret;
}
-int SensorProvider::startRecording(const std::string& pkgId, const std::string& option)
+int SensorProvider::startRecording(const std::string& pkgId, CtxJson option)
{
int retentionPeriod = DEFAULT_RETENTION;
- _D("PkgId: %s, Option: %s", pkgId.c_str(), option.c_str());
-
- Json::Reader jr;
- Json::Value optionJson;
- jr.parse(option, optionJson);
+ _D("PkgId: %s", pkgId.c_str());
+ _J("Option", option);
- if (optionJson.isMember(KEY_RETENTION)) {
- retentionPeriod = optionJson[KEY_RETENTION].asInt() * SECONDS_PER_HOUR;
- optionJson.removeMember(KEY_RETENTION);
+ if (option.get(NULL, KEY_RETENTION, &retentionPeriod)) {
+ retentionPeriod *= SECONDS_PER_HOUR;
+ option.remove(NULL, KEY_RETENTION);
}
- IF_FAIL_RETURN(verifyOption(optionJson), E_PARAM);
+ IF_FAIL_RETURN(verifyOption(option), E_PARAM);
- return __addClient(pkgId, retentionPeriod, optionJson);
+ return __addClient(pkgId, retentionPeriod, option);
}
int SensorProvider::stopRecording(const std::string& pkgId)
return __removeClient(pkgId);
}
-bool SensorProvider::verifyOption(const Json::Value& option)
+bool SensorProvider::verifyOption(CtxJson option)
{
- return option.empty();
+ std::list<std::string> keys;
+ option.getKeys(&keys);
+ return keys.size() == 0;
}
-int SensorProvider::__addClient(std::string pkgId, int retentionPeriod, Json::Value& option)
+int SensorProvider::__addClient(std::string pkgId, int retentionPeriod, CtxJson option)
{
- Json::Value tmp;
+ CtxJson tmp;
int ret;
/* Validate the retention period */
int SensorProvider::__removeClient(std::string pkgId)
{
- std::vector<Json::Value> options;
+ std::vector<CtxJson> options;
int ret;
/* Remove the app's request first */
const char* getSubject();
- int readRecords(const std::string& option, std::string* projection, std::vector<std::shared_ptr<Tuple>>* tuples);
- int startRecording(const std::string& pkgId, const std::string& option);
+ int readRecords(CtxJson option, std::string* projection, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int startRecording(const std::string& pkgId, CtxJson option);
int stopRecording(const std::string& pkgId);
virtual bool isSupported();
virtual SensorLogger* getLogger() = 0;
virtual Querier* getQuerier() = 0;
- virtual bool verifyOption(const Json::Value& option);
+ virtual bool verifyOption(CtxJson option);
private:
- int __addClient(std::string pkgId, int retentionPeriod, Json::Value& option);
+ int __addClient(std::string pkgId, int retentionPeriod, CtxJson option);
int __removeClient(std::string pkgId);
std::string __subject;
return &__querier;
}
-bool HeartRateProvider::verifyOption(const Json::Value& option)
+bool HeartRateProvider::verifyOption(CtxJson option)
{
- IF_FAIL_RETURN(option.size() <= 1, false);
+ std::list<std::string> keys;
+ option.getKeys(&keys);
- int interval = option.get(KEY_INTERVAL, MIN_MEASURING_INTERVAL).asInt();
- if (interval < MIN_MEASURING_INTERVAL || interval > MAX_MEASURING_INTERVAL)
- return false;
+ IF_FAIL_RETURN(keys.size() <= 1, false);
+
+ int interval = 0;
+ if (option.get(NULL, KEY_INTERVAL, &interval)) {
+ if (interval < MIN_MEASURING_INTERVAL || interval > MAX_MEASURING_INTERVAL)
+ return false;
+ }
return true;
}
protected:
SensorLogger* getLogger();
Querier* getQuerier();
- bool verifyOption(const Json::Value& option);
+ bool verifyOption(CtxJson option);
private:
HeartRateLogger __logger;
bool HeartRateLogger::start()
{
- std::vector<Json::Value> options;
+ std::vector<CtxJson> options;
RecorderClientInfo clientInfo;
float interval = MAX_MEASURING_INTERVAL;
return KEY_HEART_RATE "," KEY_START_TIME "," KEY_END_TIME;
}
-int HeartRateQuerier::queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int HeartRateQuerier::queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
return query(startTime, endTime, tuples);
}
-int HeartRateQuerier::query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int HeartRateQuerier::query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
std::string getProjection();
- int queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
};
}
KEY_END_TIME;
}
-int PedometerQuerier::queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PedometerQuerier::queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION_RAW \
return ret;
}
-int PedometerQuerier::query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PedometerQuerier::query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
return ret;
}
-int PedometerQuerier::query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PedometerQuerier::query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
std::string getProjection();
- int queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
};
}
KEY_END_TIME;
}
-int PressureQuerier::queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PressureQuerier::queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION_RAW \
return ret;
}
-int PressureQuerier::query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PressureQuerier::query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
return ret;
}
-int PressureQuerier::query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
+int PressureQuerier::query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
std::string getProjection();
- int queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, time_t anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, int anchor, int interval, std::vector<std::shared_ptr<Tuple>>* tuples);
};
}
return KEY_STATE "," KEY_START_TIME "," KEY_END_TIME;
}
-int SleepQuerier::queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int SleepQuerier::queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
return query(startTime, endTime, tuples);
}
-int SleepQuerier::query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
+int SleepQuerier::query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples)
{
char *sql = sqlite3_mprintf(
"SELECT " PROJECTION \
std::string getProjection();
- int queryRaw(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
- int query(time_t startTime, time_t endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int queryRaw(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
+ int query(int startTime, int endTime, std::vector<std::shared_ptr<Tuple>>* tuples);
};
}