From: Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics Date: Wed, 27 Nov 2019 13:16:11 +0000 (+0100) Subject: [ham] Fixed sleep recorder, returned value X-Git-Tag: accepted/tizen/5.5/unified/20200221.094157~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F44%2F219144%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [ham] Fixed sleep recorder, returned value [Bug] there was missing conversion from numerical value from database to string value used in Web API [Verification] TCT passrate 100% on wearable TW3. Below code works when activity added manually to database. var data = []; date = new Date(), startTime = date.getTime(), endTime = date.setDate(date.getDate() + 1), query = { startTime: startTime/1000, endTime: endTime/1000, interval: 1440 }; tizen.humanactivitymonitor.readRecorderData("SLEEP_MONITOR", query, (s) => console.log(data = s), (s) => console.log(s)) returns one of values of "ASLEEP", "AWAKE", or "UNKNOWN" Change-Id: I86b6bead534638bafcb5abcb16512bb462c79374 --- diff --git a/src/humanactivitymonitor/humanactivitymonitor_instance.cc b/src/humanactivitymonitor/humanactivitymonitor_instance.cc index ca17b35..c1c6cc8 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_instance.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_instance.cc @@ -48,10 +48,8 @@ HumanActivityMonitorInstance::HumanActivityMonitorInstance() : gesture_manager_( using std::placeholders::_1; using std::placeholders::_2; - - #define REGISTER_METHOD(M) \ - RegisterSyncHandler(#M, std::bind(&HumanActivityMonitorInstance::M, this, _1, _2)) + RegisterSyncHandler(#M, std::bind(&HumanActivityMonitorInstance::M, this, _1, _2)) REGISTER_METHOD(HumanActivityMonitorManagerGetHumanActivityData); REGISTER_METHOD(HumanActivityMonitorManagerStart); @@ -66,7 +64,6 @@ HumanActivityMonitorInstance::HumanActivityMonitorInstance() : gesture_manager_( REGISTER_METHOD(GestureManagerRemoveGestureRecognitionListener); #undef REGISTER_METHOD - } HumanActivityMonitorInstance::~HumanActivityMonitorInstance() { diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 0762f54..1b2498a 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -1413,6 +1413,29 @@ class HumanActivityMonitorManager::ActivityRecognition { std::map> activity_data_; }; +PlatformResult SleepStateToString(int state, std::string* sleep_state) { + ScopeLogger("%d", state); + if (sleep_state) { + switch (state) { + case SENSOR_SLEEP_STATE_WAKE: + *sleep_state = kSleepStateAwake; + break; + case SENSOR_SLEEP_STATE_SLEEP: + *sleep_state = kSleepStateAsleep; + break; + case SENSOR_SLEEP_STATE_UNKNOWN: + *sleep_state = kSleepStateUnknown; + break; + default: + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown sleep state", + ("Unknown sleep state: %d", state)); + } + return PlatformResult(ErrorCode::NO_ERROR); + } + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Cannot return sleep state, return pointer is null"); +} + HumanActivityMonitorManager::HumanActivityMonitorManager() : activity_recognition_(std::make_shared()) { ScopeLogger(); @@ -1457,23 +1480,9 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() sensor_sleep_state_e state = static_cast(event->values[0]); std::string sleep_state; - - switch (state) { - case SENSOR_SLEEP_STATE_WAKE: - sleep_state = kSleepStateAwake; - break; - - case SENSOR_SLEEP_STATE_SLEEP: - sleep_state = kSleepStateAsleep; - break; - - case SENSOR_SLEEP_STATE_UNKNOWN: - sleep_state = kSleepStateUnknown; - break; - - default: - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown sleep state", - ("Unknown sleep state: %d", state)); + PlatformResult result = SleepStateToString(state, &sleep_state); + if (!result) { + return result; } data->insert(std::make_pair(kStatus, picojson::value(sleep_state))); @@ -1493,23 +1502,9 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() sensor_sleep_state_e state = static_cast(event->values[0]); std::string sleep_state; - - switch (state) { - case SENSOR_SLEEP_STATE_WAKE: - sleep_state = kSleepStateAwake; - break; - - case SENSOR_SLEEP_STATE_SLEEP: - sleep_state = kSleepStateAsleep; - break; - - case SENSOR_SLEEP_STATE_UNKNOWN: - sleep_state = kSleepStateUnknown; - break; - - default: - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown sleep state", - ("Unknown sleep state: %d", state)); + PlatformResult result = SleepStateToString(state, &sleep_state); + if (!result) { + return result; } data->insert(std::make_pair(kStatus, picojson::value(sleep_state))); @@ -1548,13 +1543,22 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() auto convert_recorded_sleep_monitor = [](void* data, picojson::object* obj) -> PlatformResult { ScopeLogger("Entered into asynchronous function, convert_recorded_sleep_monitor"); - SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_SLEEP_STATE, kStatus}}; + int state = 0; + int ret = sensor_recorder_data_get_int(data, SENSOR_RECORDER_DATA_SLEEP_STATE, &state); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult( + getErrorCode(ret), "Failed to get int value", + ("Failed to get int value, error: %d (%s)", ret, get_error_message(ret))); + } - auto result = ConvertRecordedInt(data, obj, map_int); + std::string sleep_state; + PlatformResult result = SleepStateToString(state, &sleep_state); if (!result) { return result; } + obj->insert(std::make_pair(kStatus, picojson::value(sleep_state))); + return ConvertRecordedTime(data, obj); };