* limitations under the License.
*/
-#include <time.h>
-#include <sys/time.h>
-#include <cmath>
#include <sqlite3.h>
#include <SensorRecorderTypes.h>
#include "TypesInternal.h"
+#include "TimeUtil.h"
#include "SensorLogger.h"
using namespace ctx;
{
}
-uint64_t SensorLogger::getTime()
-{
- struct timeval tv;
- double timestamp;
-
- gettimeofday(&tv, NULL);
- timestamp = tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
- return static_cast<uint64_t>(round(timestamp));
-}
-
-uint64_t SensorLogger::getTime(unsigned long long monotonic)
-{
- struct timespec ts;
- double timestamp;
- uint64_t currentTime = getTime();
-
- if (abs(currentTime / 1000 - monotonic / 1000000) < SECONDS_PER_DAY)
- return static_cast<uint64_t>(round(monotonic / 1000.0));
-
- clock_gettime(CLOCK_MONOTONIC, &ts);
- timestamp = static_cast<double>(currentTime) - (ts.tv_sec * 1000000000.0 + ts.tv_nsec) / 1000000.0 + monotonic / 1000.0;
- return static_cast<uint64_t>(round(timestamp));
-}
-
bool SensorLogger::executeQuery(const char *query)
{
return __dbMgr.execute(0, query, NULL);
void SensorLogger::removeExpired(const char *subject, const char *tableName, const char *timeKey)
{
- uint64_t timestamp = getTime();
+ uint64_t timestamp = TimeUtil::getTime();
if (timestamp - __lastRemovalTime < SEC_TO_MS(SECONDS_PER_HOUR))
return;
virtual void stop() = 0;
protected:
- uint64_t getTime();
- uint64_t getTime(unsigned long long monotonic);
bool executeQuery(const char *query);
virtual void removeExpired(const char *subject, const char *tableName, const char *timeKey);
--- /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 <time.h>
+#include <sys/time.h>
+#include <cmath>
+#include "TypesInternal.h"
+#include "TimeUtil.h"
+
+using namespace ctx;
+
+TimeUtil::TimeUtil()
+{
+}
+
+uint64_t TimeUtil::getTime()
+{
+ struct timeval tv;
+ double timestamp;
+
+ gettimeofday(&tv, NULL);
+ timestamp = tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
+ return static_cast<uint64_t>(round(timestamp));
+}
+
+uint64_t TimeUtil::getTime(unsigned long long monotonic)
+{
+ struct timespec ts;
+ double timestamp;
+ uint64_t currentTime = getTime();
+
+ if (std::abs(currentTime / 1000 - monotonic / 1000000) < SECONDS_PER_DAY)
+ return static_cast<uint64_t>(round(monotonic / 1000.0));
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ timestamp = static_cast<double>(currentTime) - (ts.tv_sec * 1000000000.0 + ts.tv_nsec) / 1000000.0 + monotonic / 1000.0;
+ return static_cast<uint64_t>(round(timestamp));
+}
--- /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_TIME_UTIL_H__
+#define __CONTEXT_TIME_UTIL_H__
+
+#include <stdint.h>
+
+namespace ctx {
+
+ class TimeUtil {
+ public:
+ static uint64_t getTime();
+ static uint64_t getTime(unsigned long long monotonic);
+
+ private:
+ TimeUtil();
+ };
+
+}
+
+#endif /* __CONTEXT_TIME_UTIL_H__ */
#include <SensorRecorderTypes.h>
#include "../TypesInternal.h"
#include "../ClientInfo.h"
+#include "../TimeUtil.h"
#include "PedometerLogger.h"
using namespace ctx;
void PedometerLogger::onEvent(sensor_data_t *eventData)
{
sensor_pedometer_data_t *pedometerData = reinterpret_cast<sensor_pedometer_data_t*>(eventData);
- uint64_t timestamp = getTime();
+ uint64_t timestamp = TimeUtil::getTime();
if (__firstEvent) {
_D("Baseline event");
#include <SensorRecorderTypes.h>
#include "../TypesInternal.h"
#include "../ClientInfo.h"
+#include "../TimeUtil.h"
#include "PressureLogger.h"
#define INSERTION_THRESHOLD 20000
_I(GREEN("Start to record"));
- __lastInsertionTime = getTime();
+ __lastInsertionTime = TimeUtil::getTime();
__resetInsertionQuery();
return SensorProxy::start();
void PressureLogger::onEvent(sensor_data_t *eventData)
{
- uint64_t receivedTime = getTime();
+ uint64_t receivedTime = TimeUtil::getTime();
__record(eventData, receivedTime);
removeExpired(SUBJ_SENSOR_PRESSURE, PRESSURE_RECORD, KEY_UNIV_TIME);
}
{
char buffer[64];
g_snprintf(buffer, sizeof(buffer), "(%llu, %.5f),",
- getTime(eventData->timestamp), eventData->values[0]);
+ TimeUtil::getTime(eventData->timestamp), eventData->values[0]);
__insertionQuery += buffer;