Sub-folders for pedometer & pressure recorders are created.
Change-Id: Ic4adeb1d52b257f5228e4176886841ef88f95d4c
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
sensor
)
-FILE(GLOB SRCS *.cpp)
+FILE(GLOB_RECURSE SRCS *.cpp)
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(PKG_SENSOR REQUIRED ${DEPS})
#include <SensorRecorderTypes.h>
#include <CreateProvider.h>
-#include "Pedometer.h"
-#include "Pressure.h"
+#include "pedometer/Pedometer.h"
+#include "pressure/Pressure.h"
using namespace ctx;
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <SensorRecorderTypes.h>
-#include <Util.h>
-#include "TypesInternal.h"
-#include "PedometerLogger.h"
-#include "PedometerQuerier.h"
-#include "Pedometer.h"
-
-using namespace ctx;
-
-PedometerProvider::PedometerProvider() :
- SensorProvider(SUBJ_SENSOR_PEDOMETER)
-{
- IF_FAIL_VOID(isSupported());
-
- sensorLogger = new(std::nothrow) PedometerLogger();
- IF_FAIL_VOID_TAG(sensorLogger, _E, "Memory allocation failed");
-}
-
-PedometerProvider::~PedometerProvider()
-{
-}
-
-void PedometerProvider::getPrivilege(std::vector<const char*> &privilege)
-{
- privilege.push_back(PRIV_HEALTHINFO);
-}
-
-bool PedometerProvider::isSupported()
-{
- return util::getSystemInfoBool("tizen.org/feature/sensor.pedometer");
-}
-
-Querier* PedometerProvider::getQuerier(Json option)
-{
- PedometerQuerier *querier = new(std::nothrow) PedometerQuerier(this, option);
- IF_FAIL_RETURN_TAG(querier, NULL, _E, "Memory allocation failed");
- return querier;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PEDOMETER_PROVIDER_H__
-#define __CONTEXT_PEDOMETER_PROVIDER_H__
-
-#include "SensorProvider.h"
-
-namespace ctx {
-
- class PedometerProvider : public SensorProvider {
- public:
- PedometerProvider();
- ~PedometerProvider();
-
- bool isSupported();
- void getPrivilege(std::vector<const char*> &privilege);
-
- protected:
- Querier* getQuerier(Json option);
- };
-}
-
-#endif /* _CONTEXT_PEDOMETER_PROVIDER_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <sqlite3.h>
-#include <SensorRecorderTypes.h>
-#include "TypesInternal.h"
-#include "ClientInfo.h"
-#include "PedometerLogger.h"
-
-using namespace ctx;
-
-PedometerLogger::PedometerLogger() :
- __firstEvent(true)
-{
- setSensor(HUMAN_PEDOMETER_SENSOR);
- setPowerSave(false);
-
- /* Create the log table */
- executeQuery(
- "CREATE TABLE IF NOT EXISTS " PEDOMETER_RECORD " (" \
- KEY_START_TIME " INTEGER NOT NULL, " \
- KEY_END_TIME " INTEGER NOT NULL PRIMARY KEY, " \
- KEY_WALK_STEPS " INTEGER NOT NULL, " \
- KEY_RUN_STEPS " INTEGER NOT NULL, " \
- KEY_DISTANCE " REAL NOT NULL, " \
- KEY_CALORIES " REAL NOT NULL" \
- ")");
-
- ClientInfo clientInfo;
- if (clientInfo.exist(SUBJ_SENSOR_PEDOMETER))
- start();
-}
-
-PedometerLogger::~PedometerLogger()
-{
-}
-
-bool PedometerLogger::start()
-{
- if (SensorProxy::isRunning())
- return true;
-
- _I(GREEN("Start to record"));
-
- if (SensorProxy::start()) {
- flush();
- return true;
- }
-
- return false;
-}
-
-void PedometerLogger::stop()
-{
- _I(GREEN("Stop recording"));
-
- SensorProxy::stop();
- __firstEvent = true;
-}
-
-void PedometerLogger::onEvent(sensor_data_t *eventData)
-{
- sensor_pedometer_data_t *pedometerData = reinterpret_cast<sensor_pedometer_data_t*>(eventData);
- uint64_t timestamp = getTime();
-
- if (__firstEvent) {
- _D("Baseline event");
- __firstEvent = false;
- } else if (pedometerData->diffs_count == 0) {
- _D("Single event");
- __recordSingle(pedometerData, timestamp);
- } else {
- _D("Batch event");
- __recordBatch(pedometerData, timestamp);
- }
-
- __baseline.timestamp = timestamp;
- __baseline.walkSteps = eventData->values[1];
- __baseline.runSteps = eventData->values[2];
- __baseline.distance = eventData->values[3];
- __baseline.calories = eventData->values[4];
-
- _D("Baseline: %u, %u, %.3f, %.3f",
- __baseline.walkSteps, __baseline.runSteps, __baseline.distance, __baseline.calories);
-
- removeExpired(SUBJ_SENSOR_PEDOMETER, PEDOMETER_RECORD, KEY_END_TIME);
-}
-
-void PedometerLogger::__recordSingle(sensor_pedometer_data_t *eventData, uint64_t timestamp)
-{
- DataRecord record;
- record.walkSteps = static_cast<unsigned int>(eventData->values[1]) - __baseline.walkSteps;
- record.runSteps = static_cast<unsigned int>(eventData->values[2]) - __baseline.runSteps;
- record.distance = eventData->values[3] - __baseline.distance;
- record.calories = eventData->values[4] - __baseline.calories;
-
- IF_FAIL_VOID_TAG(record.walkSteps + record.runSteps > 0, _D, "Skipping zero-count event");
-
- char *query = sqlite3_mprintf(
- "INSERT INTO " PEDOMETER_RECORD "(" \
- KEY_START_TIME ", " \
- KEY_END_TIME ", " \
- KEY_WALK_STEPS ", " \
- KEY_RUN_STEPS ", " \
- KEY_DISTANCE ", " \
- KEY_CALORIES ") " \
- "VALUES (%llu, %llu, %u, %u, %.3f, %.3f)",
- __baseline.timestamp, timestamp, record.walkSteps, record.runSteps, record.distance, record.calories);
- executeQuery(query);
- sqlite3_free(query);
-}
-
-void PedometerLogger::__recordBatch(sensor_pedometer_data_t *eventData, uint64_t timestamp)
-{
- std::string query("INSERT INTO " PEDOMETER_RECORD "(" \
- KEY_START_TIME ", " \
- KEY_END_TIME ", " \
- KEY_WALK_STEPS ", " \
- KEY_RUN_STEPS ", " \
- KEY_DISTANCE ", " \
- KEY_CALORIES ") VALUES ");
- char buffer[256];
-
- for (int i = 0; i < eventData->diffs_count; ++i) {
- if (eventData->diffs[i].walk_steps + eventData->diffs[i].run_steps == 0) {
- _D("Skipping zero-count event");
- continue;
- }
-
- /* TODO: check the timestamps.. they look strange.. */
- g_snprintf(buffer, sizeof(buffer), "(%llu, %llu, %d, %d, %.3f, %.3f),",
- i == 0 ? __baseline.timestamp : SEC_TO_MS(static_cast<uint64_t>(eventData->diffs[i-1].timestamp)),
- SEC_TO_MS(static_cast<uint64_t>(eventData->diffs[i].timestamp)),
- eventData->diffs[i].walk_steps,
- eventData->diffs[i].run_steps,
- eventData->diffs[i].distance,
- eventData->diffs[i].calories);
- query += buffer;
- }
-
- query.resize(query.size() - 1);
- IF_FAIL_VOID_TAG(query.at(query.size() - 1) == ')', _D, "No records");
-
- executeQuery(query.c_str());
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PEDOMETER_LOGGER_H__
-#define __CONTEXT_PEDOMETER_LOGGER_H__
-
-#include "SensorLogger.h"
-#include "SensorProxy.h"
-
-namespace ctx {
-
- class PedometerLogger : public SensorLogger, public SensorProxy {
- public:
- PedometerLogger();
- ~PedometerLogger();
-
- bool start();
- void stop();
-
- protected:
- void onEvent(sensor_data_t *eventData);
-
- private:
- struct DataRecord {
- uint64_t timestamp;
- unsigned int walkSteps;
- unsigned int runSteps;
- float distance;
- float calories;
- };
-
- void __recordSingle(sensor_pedometer_data_t *eventData, uint64_t timestamp);
- void __recordBatch(sensor_pedometer_data_t *eventData, uint64_t timestamp);
-
- bool __firstEvent;
- DataRecord __baseline;
- };
-}
-
-#endif /* __CONTEXT_PEDOMETER_LOGGER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <sqlite3.h>
-#include <SensorRecorderTypes.h>
-#include "TypesInternal.h"
-#include "PedometerQuerier.h"
-
-#define PROJECTION \
- "SUM(" KEY_WALK_STEPS " + " KEY_RUN_STEPS ") AS " KEY_STEPS ", " \
- "SUM(" KEY_WALK_STEPS ") AS " KEY_WALK_STEPS ", " \
- "SUM(" KEY_RUN_STEPS ") AS " KEY_RUN_STEPS ", " \
- "SUM(" KEY_DISTANCE ") AS " KEY_DISTANCE ", " \
- "SUM(" KEY_CALORIES ") AS " KEY_CALORIES ", " \
- "MIN(" KEY_START_TIME ") AS " KEY_START_TIME ", " \
- "MAX(" KEY_END_TIME ") AS " KEY_END_TIME
-
-using namespace ctx;
-
-PedometerQuerier::PedometerQuerier(ContextProvider *provider, Json option) :
- Querier(provider, option)
-{
-}
-
-PedometerQuerier::~PedometerQuerier()
-{
-}
-
-int PedometerQuerier::query(int startTime, int endTime)
-{
- char *sql = sqlite3_mprintf(
- "SELECT " PROJECTION \
- " FROM " PEDOMETER_RECORD \
- " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu",
- SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
-
- int ret = Querier::query(sql);
- sqlite3_free(sql);
-
- return ret;
-}
-
-int PedometerQuerier::query(int startTime, int endTime, int anchor, int interval)
-{
- char *sql = sqlite3_mprintf(
- "SELECT " PROJECTION \
- " FROM " PEDOMETER_RECORD \
- " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu" \
- " GROUP BY ROUND((" KEY_END_TIME " - %llu) / %llu + 0.5)" \
- " ORDER BY " KEY_END_TIME " ASC",
- SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
- SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
-
- int ret = Querier::query(sql);
- sqlite3_free(sql);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PEDOMETER_QUERIER_H__
-#define __CONTEXT_PEDOMETER_QUERIER_H__
-
-#include "Querier.h"
-
-namespace ctx {
-
- class PedometerQuerier : public Querier {
- public:
- PedometerQuerier(ContextProvider *provider, Json option);
- ~PedometerQuerier();
-
- int query(int startTime, int endTime);
- int query(int startTime, int endTime, int anchor, int interval);
- };
-}
-
-#endif /* __CONTEXT_PEDOMETER_QUERIER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <SensorRecorderTypes.h>
-#include <Util.h>
-#include "TypesInternal.h"
-#include "PressureLogger.h"
-#include "PressureQuerier.h"
-#include "Pressure.h"
-
-using namespace ctx;
-
-PressureProvider::PressureProvider() :
- SensorProvider(SUBJ_SENSOR_PRESSURE)
-{
- IF_FAIL_VOID(isSupported());
-
- sensorLogger = new(std::nothrow) PressureLogger();
- IF_FAIL_VOID_TAG(sensorLogger, _E, "Memory allocation failed");
-}
-
-PressureProvider::~PressureProvider()
-{
-}
-
-bool PressureProvider::isSupported()
-{
- return util::getSystemInfoBool("tizen.org/feature/sensor.barometer");
-}
-
-Querier* PressureProvider::getQuerier(Json option)
-{
- PressureQuerier *querier = new(std::nothrow) PressureQuerier(this, option);
- IF_FAIL_RETURN_TAG(querier, NULL, _E, "Memory allocation failed");
- return querier;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PRESSURE_PROVIDER_H__
-#define __CONTEXT_PRESSURE_PROVIDER_H__
-
-#include "SensorProvider.h"
-
-namespace ctx {
-
- class PressureProvider : public SensorProvider {
- public:
- PressureProvider();
- ~PressureProvider();
-
- bool isSupported();
-
- protected:
- Querier* getQuerier(Json option);
- };
-}
-
-#endif /* _CONTEXT_PRESSURE_PROVIDER_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <sqlite3.h>
-#include <SensorRecorderTypes.h>
-#include "TypesInternal.h"
-#include "ClientInfo.h"
-#include "PressureLogger.h"
-
-#define INSERTION_THRESHOLD 20000
-#define SAMPLING_INTERVAL 60000
-#define BATCH_LATENCY INT_MAX
-#define MAX_QUERY_LENGTH 1000
-
-using namespace ctx;
-
-PressureLogger::PressureLogger()
-{
- setSensor(PRESSURE_SENSOR);
- setPowerSave(false);
- setSamplingInterval(SAMPLING_INTERVAL);
- setBatchLatency(BATCH_LATENCY);
-
- /* Create the log table */
- executeQuery(
- "CREATE TABLE IF NOT EXISTS " PRESSURE_RECORD " (" \
- KEY_UNIV_TIME " INTEGER NOT NULL PRIMARY KEY, " \
- KEY_PRESSURE " REAL NOT NULL" \
- ")");
-
- ClientInfo clientInfo;
- if (clientInfo.exist(SUBJ_SENSOR_PRESSURE))
- start();
-}
-
-PressureLogger::~PressureLogger()
-{
-}
-
-bool PressureLogger::start()
-{
- if (SensorProxy::isRunning())
- return true;
-
- _I(GREEN("Start to record"));
-
- __lastInsertionTime = getTime();
- __resetInsertionQuery();
-
- return SensorProxy::start();
-}
-
-void PressureLogger::stop()
-{
- _I(GREEN("Stop recording"));
-
- SensorProxy::stop();
-}
-
-void PressureLogger::onEvent(sensor_data_t *eventData)
-{
- uint64_t receivedTime = getTime();
- __record(eventData, receivedTime);
- removeExpired(SUBJ_SENSOR_PRESSURE, PRESSURE_RECORD, KEY_UNIV_TIME);
-}
-
-void PressureLogger::__record(sensor_data_t *eventData, uint64_t receivedTime)
-{
- char buffer[64];
- g_snprintf(buffer, sizeof(buffer), "(%llu, %.5f),",
- getTime(eventData->timestamp), eventData->values[0]);
-
- __insertionQuery += buffer;
-
- if (receivedTime - __lastInsertionTime < INSERTION_THRESHOLD && __insertionQuery.size() < MAX_QUERY_LENGTH)
- return;
-
- __insertionQuery.resize(__insertionQuery.size() - 1);
- if (__insertionQuery.at(__insertionQuery.size() - 1) == ')')
- executeQuery(__insertionQuery.c_str());
-
- __lastInsertionTime = receivedTime;
- __resetInsertionQuery();
-}
-
-void PressureLogger::__resetInsertionQuery()
-{
- __insertionQuery =
- "INSERT INTO " PRESSURE_RECORD \
- " (" KEY_UNIV_TIME ", " KEY_PRESSURE ") VALUES ";
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PRESSURE_LOGGER_H__
-#define __CONTEXT_PRESSURE_LOGGER_H__
-
-#include "SensorLogger.h"
-#include "SensorProxy.h"
-
-namespace ctx {
-
- class PressureLogger : public SensorLogger, public SensorProxy {
- public:
- PressureLogger();
- ~PressureLogger();
-
- bool start();
- void stop();
-
- protected:
- void onEvent(sensor_data_t *eventData);
-
- private:
- void __record(sensor_data_t *eventData, uint64_t receivedTime);
- void __resetInsertionQuery();
-
- uint64_t __lastInsertionTime;
- std::string __insertionQuery;
- };
-}
-
-#endif /* __CONTEXT_PRESSURE_LOGGER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <sqlite3.h>
-#include <SensorRecorderTypes.h>
-#include "TypesInternal.h"
-#include "PressureQuerier.h"
-
-#define PROJECTION \
- "AVG(" KEY_PRESSURE ") AS " KEY_PRESSURE ", " \
- "MIN(" KEY_PRESSURE ") AS " KEY_MIN_PRESSURE ", " \
- "MAX(" KEY_PRESSURE ") AS " KEY_MAX_PRESSURE ", " \
- "AVG(" KEY_PRESSURE ") AS " KEY_AVG_PRESSURE ", " \
- "MIN(" KEY_UNIV_TIME ") AS " KEY_START_TIME ", " \
- "MAX(" KEY_UNIV_TIME ") AS " KEY_END_TIME
-
-#define PROJECTION_RAW \
- KEY_PRESSURE ", " \
- KEY_PRESSURE " AS " KEY_MIN_PRESSURE ", " \
- KEY_PRESSURE " AS " KEY_MAX_PRESSURE ", " \
- KEY_PRESSURE " AS " KEY_AVG_PRESSURE ", " \
- KEY_UNIV_TIME " AS " KEY_START_TIME ", " \
- KEY_UNIV_TIME " AS " KEY_END_TIME
-
-using namespace ctx;
-
-PressureQuerier::PressureQuerier(ContextProvider *provider, Json option) :
- Querier(provider, option)
-{
-}
-
-PressureQuerier::~PressureQuerier()
-{
-}
-
-int PressureQuerier::queryRaw(int startTime, int endTime)
-{
- char *sql = sqlite3_mprintf(
- "SELECT " PROJECTION_RAW \
- " FROM " PRESSURE_RECORD \
- " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu",
- SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
-
- int ret = Querier::query(sql);
- sqlite3_free(sql);
-
- return ret;
-}
-
-int PressureQuerier::query(int startTime, int endTime)
-{
- char *sql = sqlite3_mprintf(
- "SELECT " PROJECTION \
- " FROM " PRESSURE_RECORD \
- " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu",
- SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
-
- int ret = Querier::query(sql);
- sqlite3_free(sql);
-
- return ret;
-}
-
-int PressureQuerier::query(int startTime, int endTime, int anchor, int interval)
-{
- char *sql = sqlite3_mprintf(
- "SELECT " PROJECTION \
- " FROM " PRESSURE_RECORD \
- " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu" \
- " GROUP BY ROUND((" KEY_UNIV_TIME " - %llu) / %llu + 0.5)" \
- " ORDER BY " KEY_END_TIME " ASC",
- SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
- SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
-
- int ret = Querier::query(sql);
- sqlite3_free(sql);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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_PRESSURE_QUERIER_H__
-#define __CONTEXT_PRESSURE_QUERIER_H__
-
-#include "Querier.h"
-
-namespace ctx {
-
- class PressureQuerier : public Querier {
- public:
- PressureQuerier(ContextProvider *provider, Json option);
- ~PressureQuerier();
-
- int queryRaw(int startTime, int endTime);
- int query(int startTime, int endTime);
- int query(int startTime, int endTime, int anchor, int interval);
- };
-}
-
-#endif /* __CONTEXT_PRESSURE_QUERIER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <SensorRecorderTypes.h>
+#include <Util.h>
+#include "../TypesInternal.h"
+#include "PedometerLogger.h"
+#include "PedometerQuerier.h"
+#include "Pedometer.h"
+
+using namespace ctx;
+
+PedometerProvider::PedometerProvider() :
+ SensorProvider(SUBJ_SENSOR_PEDOMETER)
+{
+ IF_FAIL_VOID(isSupported());
+
+ sensorLogger = new(std::nothrow) PedometerLogger();
+ IF_FAIL_VOID_TAG(sensorLogger, _E, "Memory allocation failed");
+}
+
+PedometerProvider::~PedometerProvider()
+{
+}
+
+void PedometerProvider::getPrivilege(std::vector<const char*> &privilege)
+{
+ privilege.push_back(PRIV_HEALTHINFO);
+}
+
+bool PedometerProvider::isSupported()
+{
+ return util::getSystemInfoBool("tizen.org/feature/sensor.pedometer");
+}
+
+Querier* PedometerProvider::getQuerier(Json option)
+{
+ PedometerQuerier *querier = new(std::nothrow) PedometerQuerier(this, option);
+ IF_FAIL_RETURN_TAG(querier, NULL, _E, "Memory allocation failed");
+ return querier;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PEDOMETER_PROVIDER_H__
+#define __CONTEXT_PEDOMETER_PROVIDER_H__
+
+#include "../SensorProvider.h"
+
+namespace ctx {
+
+ class PedometerProvider : public SensorProvider {
+ public:
+ PedometerProvider();
+ ~PedometerProvider();
+
+ bool isSupported();
+ void getPrivilege(std::vector<const char*> &privilege);
+
+ protected:
+ Querier* getQuerier(Json option);
+ };
+}
+
+#endif /* _CONTEXT_PEDOMETER_PROVIDER_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <sqlite3.h>
+#include <SensorRecorderTypes.h>
+#include "../TypesInternal.h"
+#include "../ClientInfo.h"
+#include "PedometerLogger.h"
+
+using namespace ctx;
+
+PedometerLogger::PedometerLogger() :
+ __firstEvent(true)
+{
+ setSensor(HUMAN_PEDOMETER_SENSOR);
+ setPowerSave(false);
+
+ /* Create the log table */
+ executeQuery(
+ "CREATE TABLE IF NOT EXISTS " PEDOMETER_RECORD " (" \
+ KEY_START_TIME " INTEGER NOT NULL, " \
+ KEY_END_TIME " INTEGER NOT NULL PRIMARY KEY, " \
+ KEY_WALK_STEPS " INTEGER NOT NULL, " \
+ KEY_RUN_STEPS " INTEGER NOT NULL, " \
+ KEY_DISTANCE " REAL NOT NULL, " \
+ KEY_CALORIES " REAL NOT NULL" \
+ ")");
+
+ ClientInfo clientInfo;
+ if (clientInfo.exist(SUBJ_SENSOR_PEDOMETER))
+ start();
+}
+
+PedometerLogger::~PedometerLogger()
+{
+}
+
+bool PedometerLogger::start()
+{
+ if (SensorProxy::isRunning())
+ return true;
+
+ _I(GREEN("Start to record"));
+
+ if (SensorProxy::start()) {
+ flush();
+ return true;
+ }
+
+ return false;
+}
+
+void PedometerLogger::stop()
+{
+ _I(GREEN("Stop recording"));
+
+ SensorProxy::stop();
+ __firstEvent = true;
+}
+
+void PedometerLogger::onEvent(sensor_data_t *eventData)
+{
+ sensor_pedometer_data_t *pedometerData = reinterpret_cast<sensor_pedometer_data_t*>(eventData);
+ uint64_t timestamp = getTime();
+
+ if (__firstEvent) {
+ _D("Baseline event");
+ __firstEvent = false;
+ } else if (pedometerData->diffs_count == 0) {
+ _D("Single event");
+ __recordSingle(pedometerData, timestamp);
+ } else {
+ _D("Batch event");
+ __recordBatch(pedometerData, timestamp);
+ }
+
+ __baseline.timestamp = timestamp;
+ __baseline.walkSteps = eventData->values[1];
+ __baseline.runSteps = eventData->values[2];
+ __baseline.distance = eventData->values[3];
+ __baseline.calories = eventData->values[4];
+
+ _D("Baseline: %u, %u, %.3f, %.3f",
+ __baseline.walkSteps, __baseline.runSteps, __baseline.distance, __baseline.calories);
+
+ removeExpired(SUBJ_SENSOR_PEDOMETER, PEDOMETER_RECORD, KEY_END_TIME);
+}
+
+void PedometerLogger::__recordSingle(sensor_pedometer_data_t *eventData, uint64_t timestamp)
+{
+ DataRecord record;
+ record.walkSteps = static_cast<unsigned int>(eventData->values[1]) - __baseline.walkSteps;
+ record.runSteps = static_cast<unsigned int>(eventData->values[2]) - __baseline.runSteps;
+ record.distance = eventData->values[3] - __baseline.distance;
+ record.calories = eventData->values[4] - __baseline.calories;
+
+ IF_FAIL_VOID_TAG(record.walkSteps + record.runSteps > 0, _D, "Skipping zero-count event");
+
+ char *query = sqlite3_mprintf(
+ "INSERT INTO " PEDOMETER_RECORD "(" \
+ KEY_START_TIME ", " \
+ KEY_END_TIME ", " \
+ KEY_WALK_STEPS ", " \
+ KEY_RUN_STEPS ", " \
+ KEY_DISTANCE ", " \
+ KEY_CALORIES ") " \
+ "VALUES (%llu, %llu, %u, %u, %.3f, %.3f)",
+ __baseline.timestamp, timestamp, record.walkSteps, record.runSteps, record.distance, record.calories);
+ executeQuery(query);
+ sqlite3_free(query);
+}
+
+void PedometerLogger::__recordBatch(sensor_pedometer_data_t *eventData, uint64_t timestamp)
+{
+ std::string query("INSERT INTO " PEDOMETER_RECORD "(" \
+ KEY_START_TIME ", " \
+ KEY_END_TIME ", " \
+ KEY_WALK_STEPS ", " \
+ KEY_RUN_STEPS ", " \
+ KEY_DISTANCE ", " \
+ KEY_CALORIES ") VALUES ");
+ char buffer[256];
+
+ for (int i = 0; i < eventData->diffs_count; ++i) {
+ if (eventData->diffs[i].walk_steps + eventData->diffs[i].run_steps == 0) {
+ _D("Skipping zero-count event");
+ continue;
+ }
+
+ /* TODO: check the timestamps.. they look strange.. */
+ g_snprintf(buffer, sizeof(buffer), "(%llu, %llu, %d, %d, %.3f, %.3f),",
+ i == 0 ? __baseline.timestamp : SEC_TO_MS(static_cast<uint64_t>(eventData->diffs[i-1].timestamp)),
+ SEC_TO_MS(static_cast<uint64_t>(eventData->diffs[i].timestamp)),
+ eventData->diffs[i].walk_steps,
+ eventData->diffs[i].run_steps,
+ eventData->diffs[i].distance,
+ eventData->diffs[i].calories);
+ query += buffer;
+ }
+
+ query.resize(query.size() - 1);
+ IF_FAIL_VOID_TAG(query.at(query.size() - 1) == ')', _D, "No records");
+
+ executeQuery(query.c_str());
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PEDOMETER_LOGGER_H__
+#define __CONTEXT_PEDOMETER_LOGGER_H__
+
+#include "../SensorLogger.h"
+#include "../SensorProxy.h"
+
+namespace ctx {
+
+ class PedometerLogger : public SensorLogger, public SensorProxy {
+ public:
+ PedometerLogger();
+ ~PedometerLogger();
+
+ bool start();
+ void stop();
+
+ protected:
+ void onEvent(sensor_data_t *eventData);
+
+ private:
+ struct DataRecord {
+ uint64_t timestamp;
+ unsigned int walkSteps;
+ unsigned int runSteps;
+ float distance;
+ float calories;
+ };
+
+ void __recordSingle(sensor_pedometer_data_t *eventData, uint64_t timestamp);
+ void __recordBatch(sensor_pedometer_data_t *eventData, uint64_t timestamp);
+
+ bool __firstEvent;
+ DataRecord __baseline;
+ };
+}
+
+#endif /* __CONTEXT_PEDOMETER_LOGGER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <sqlite3.h>
+#include <SensorRecorderTypes.h>
+#include "../TypesInternal.h"
+#include "PedometerQuerier.h"
+
+#define PROJECTION \
+ "SUM(" KEY_WALK_STEPS " + " KEY_RUN_STEPS ") AS " KEY_STEPS ", " \
+ "SUM(" KEY_WALK_STEPS ") AS " KEY_WALK_STEPS ", " \
+ "SUM(" KEY_RUN_STEPS ") AS " KEY_RUN_STEPS ", " \
+ "SUM(" KEY_DISTANCE ") AS " KEY_DISTANCE ", " \
+ "SUM(" KEY_CALORIES ") AS " KEY_CALORIES ", " \
+ "MIN(" KEY_START_TIME ") AS " KEY_START_TIME ", " \
+ "MAX(" KEY_END_TIME ") AS " KEY_END_TIME
+
+using namespace ctx;
+
+PedometerQuerier::PedometerQuerier(ContextProvider *provider, Json option) :
+ Querier(provider, option)
+{
+}
+
+PedometerQuerier::~PedometerQuerier()
+{
+}
+
+int PedometerQuerier::query(int startTime, int endTime)
+{
+ char *sql = sqlite3_mprintf(
+ "SELECT " PROJECTION \
+ " FROM " PEDOMETER_RECORD \
+ " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu",
+ SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
+
+ int ret = Querier::query(sql);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int PedometerQuerier::query(int startTime, int endTime, int anchor, int interval)
+{
+ char *sql = sqlite3_mprintf(
+ "SELECT " PROJECTION \
+ " FROM " PEDOMETER_RECORD \
+ " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu" \
+ " GROUP BY ROUND((" KEY_END_TIME " - %llu) / %llu + 0.5)" \
+ " ORDER BY " KEY_END_TIME " ASC",
+ SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
+ SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
+
+ int ret = Querier::query(sql);
+ sqlite3_free(sql);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PEDOMETER_QUERIER_H__
+#define __CONTEXT_PEDOMETER_QUERIER_H__
+
+#include "../Querier.h"
+
+namespace ctx {
+
+ class PedometerQuerier : public Querier {
+ public:
+ PedometerQuerier(ContextProvider *provider, Json option);
+ ~PedometerQuerier();
+
+ int query(int startTime, int endTime);
+ int query(int startTime, int endTime, int anchor, int interval);
+ };
+}
+
+#endif /* __CONTEXT_PEDOMETER_QUERIER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <SensorRecorderTypes.h>
+#include <Util.h>
+#include "../TypesInternal.h"
+#include "PressureLogger.h"
+#include "PressureQuerier.h"
+#include "Pressure.h"
+
+using namespace ctx;
+
+PressureProvider::PressureProvider() :
+ SensorProvider(SUBJ_SENSOR_PRESSURE)
+{
+ IF_FAIL_VOID(isSupported());
+
+ sensorLogger = new(std::nothrow) PressureLogger();
+ IF_FAIL_VOID_TAG(sensorLogger, _E, "Memory allocation failed");
+}
+
+PressureProvider::~PressureProvider()
+{
+}
+
+bool PressureProvider::isSupported()
+{
+ return util::getSystemInfoBool("tizen.org/feature/sensor.barometer");
+}
+
+Querier* PressureProvider::getQuerier(Json option)
+{
+ PressureQuerier *querier = new(std::nothrow) PressureQuerier(this, option);
+ IF_FAIL_RETURN_TAG(querier, NULL, _E, "Memory allocation failed");
+ return querier;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PRESSURE_PROVIDER_H__
+#define __CONTEXT_PRESSURE_PROVIDER_H__
+
+#include "../SensorProvider.h"
+
+namespace ctx {
+
+ class PressureProvider : public SensorProvider {
+ public:
+ PressureProvider();
+ ~PressureProvider();
+
+ bool isSupported();
+
+ protected:
+ Querier* getQuerier(Json option);
+ };
+}
+
+#endif /* _CONTEXT_PRESSURE_PROVIDER_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <sqlite3.h>
+#include <SensorRecorderTypes.h>
+#include "../TypesInternal.h"
+#include "../ClientInfo.h"
+#include "PressureLogger.h"
+
+#define INSERTION_THRESHOLD 20000
+#define SAMPLING_INTERVAL 60000
+#define BATCH_LATENCY INT_MAX
+#define MAX_QUERY_LENGTH 1000
+
+using namespace ctx;
+
+PressureLogger::PressureLogger()
+{
+ setSensor(PRESSURE_SENSOR);
+ setPowerSave(false);
+ setSamplingInterval(SAMPLING_INTERVAL);
+ setBatchLatency(BATCH_LATENCY);
+
+ /* Create the log table */
+ executeQuery(
+ "CREATE TABLE IF NOT EXISTS " PRESSURE_RECORD " (" \
+ KEY_UNIV_TIME " INTEGER NOT NULL PRIMARY KEY, " \
+ KEY_PRESSURE " REAL NOT NULL" \
+ ")");
+
+ ClientInfo clientInfo;
+ if (clientInfo.exist(SUBJ_SENSOR_PRESSURE))
+ start();
+}
+
+PressureLogger::~PressureLogger()
+{
+}
+
+bool PressureLogger::start()
+{
+ if (SensorProxy::isRunning())
+ return true;
+
+ _I(GREEN("Start to record"));
+
+ __lastInsertionTime = getTime();
+ __resetInsertionQuery();
+
+ return SensorProxy::start();
+}
+
+void PressureLogger::stop()
+{
+ _I(GREEN("Stop recording"));
+
+ SensorProxy::stop();
+}
+
+void PressureLogger::onEvent(sensor_data_t *eventData)
+{
+ uint64_t receivedTime = getTime();
+ __record(eventData, receivedTime);
+ removeExpired(SUBJ_SENSOR_PRESSURE, PRESSURE_RECORD, KEY_UNIV_TIME);
+}
+
+void PressureLogger::__record(sensor_data_t *eventData, uint64_t receivedTime)
+{
+ char buffer[64];
+ g_snprintf(buffer, sizeof(buffer), "(%llu, %.5f),",
+ getTime(eventData->timestamp), eventData->values[0]);
+
+ __insertionQuery += buffer;
+
+ if (receivedTime - __lastInsertionTime < INSERTION_THRESHOLD && __insertionQuery.size() < MAX_QUERY_LENGTH)
+ return;
+
+ __insertionQuery.resize(__insertionQuery.size() - 1);
+ if (__insertionQuery.at(__insertionQuery.size() - 1) == ')')
+ executeQuery(__insertionQuery.c_str());
+
+ __lastInsertionTime = receivedTime;
+ __resetInsertionQuery();
+}
+
+void PressureLogger::__resetInsertionQuery()
+{
+ __insertionQuery =
+ "INSERT INTO " PRESSURE_RECORD \
+ " (" KEY_UNIV_TIME ", " KEY_PRESSURE ") VALUES ";
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PRESSURE_LOGGER_H__
+#define __CONTEXT_PRESSURE_LOGGER_H__
+
+#include "../SensorLogger.h"
+#include "../SensorProxy.h"
+
+namespace ctx {
+
+ class PressureLogger : public SensorLogger, public SensorProxy {
+ public:
+ PressureLogger();
+ ~PressureLogger();
+
+ bool start();
+ void stop();
+
+ protected:
+ void onEvent(sensor_data_t *eventData);
+
+ private:
+ void __record(sensor_data_t *eventData, uint64_t receivedTime);
+ void __resetInsertionQuery();
+
+ uint64_t __lastInsertionTime;
+ std::string __insertionQuery;
+ };
+}
+
+#endif /* __CONTEXT_PRESSURE_LOGGER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <sqlite3.h>
+#include <SensorRecorderTypes.h>
+#include "../TypesInternal.h"
+#include "PressureQuerier.h"
+
+#define PROJECTION \
+ "AVG(" KEY_PRESSURE ") AS " KEY_PRESSURE ", " \
+ "MIN(" KEY_PRESSURE ") AS " KEY_MIN_PRESSURE ", " \
+ "MAX(" KEY_PRESSURE ") AS " KEY_MAX_PRESSURE ", " \
+ "AVG(" KEY_PRESSURE ") AS " KEY_AVG_PRESSURE ", " \
+ "MIN(" KEY_UNIV_TIME ") AS " KEY_START_TIME ", " \
+ "MAX(" KEY_UNIV_TIME ") AS " KEY_END_TIME
+
+#define PROJECTION_RAW \
+ KEY_PRESSURE ", " \
+ KEY_PRESSURE " AS " KEY_MIN_PRESSURE ", " \
+ KEY_PRESSURE " AS " KEY_MAX_PRESSURE ", " \
+ KEY_PRESSURE " AS " KEY_AVG_PRESSURE ", " \
+ KEY_UNIV_TIME " AS " KEY_START_TIME ", " \
+ KEY_UNIV_TIME " AS " KEY_END_TIME
+
+using namespace ctx;
+
+PressureQuerier::PressureQuerier(ContextProvider *provider, Json option) :
+ Querier(provider, option)
+{
+}
+
+PressureQuerier::~PressureQuerier()
+{
+}
+
+int PressureQuerier::queryRaw(int startTime, int endTime)
+{
+ char *sql = sqlite3_mprintf(
+ "SELECT " PROJECTION_RAW \
+ " FROM " PRESSURE_RECORD \
+ " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu",
+ SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
+
+ int ret = Querier::query(sql);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int PressureQuerier::query(int startTime, int endTime)
+{
+ char *sql = sqlite3_mprintf(
+ "SELECT " PROJECTION \
+ " FROM " PRESSURE_RECORD \
+ " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu",
+ SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)));
+
+ int ret = Querier::query(sql);
+ sqlite3_free(sql);
+
+ return ret;
+}
+
+int PressureQuerier::query(int startTime, int endTime, int anchor, int interval)
+{
+ char *sql = sqlite3_mprintf(
+ "SELECT " PROJECTION \
+ " FROM " PRESSURE_RECORD \
+ " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu" \
+ " GROUP BY ROUND((" KEY_UNIV_TIME " - %llu) / %llu + 0.5)" \
+ " ORDER BY " KEY_END_TIME " ASC",
+ SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
+ SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
+
+ int ret = Querier::query(sql);
+ sqlite3_free(sql);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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_PRESSURE_QUERIER_H__
+#define __CONTEXT_PRESSURE_QUERIER_H__
+
+#include "../Querier.h"
+
+namespace ctx {
+
+ class PressureQuerier : public Querier {
+ public:
+ PressureQuerier(ContextProvider *provider, Json option);
+ ~PressureQuerier();
+
+ int queryRaw(int startTime, int endTime);
+ int query(int startTime, int endTime);
+ int query(int startTime, int endTime, int anchor, int interval);
+ };
+}
+
+#endif /* __CONTEXT_PRESSURE_QUERIER_H__ */