From 6d9518802013e69822398698752c99a6673d6100 Mon Sep 17 00:00:00 2001 From: Arkadiusz Pietraszek Date: Wed, 20 Jun 2018 10:58:57 +0200 Subject: [PATCH 01/16] [Filesystem] Fix for thread that may outlive object it reffers to [Verification] tizen.filesystem methods work properly. Worker and insstance destructors work properly. Change-Id: I5724bd798c868aaba23e9f4e5c5f4ba0b13d2faf Signed-off-by: Arkadiusz Pietraszek --- src/filesystem/filesystem_instance.cc | 7 +++++++ src/filesystem/filesystem_instance.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index be8e802..52f5948 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -145,6 +145,12 @@ FilesystemInstance::Worker::Worker() } FilesystemInstance::Worker::~Worker() { + if(!exit && thread.joinable()) { + stop(); + } +} + +void FilesystemInstance::Worker::stop() { { // use memory barrier for exit flag (could be std::atomic_flag, but we use lock instead) std::lock_guard lck{jobs_mtx}; @@ -228,6 +234,7 @@ FilesystemInstance::FilesystemInstance() { FilesystemInstance::~FilesystemInstance() { ScopeLogger(); + worker.stop(); FilesystemManager::GetInstance().StopListening(); FilesystemManager::GetInstance().RemoveListener(); } diff --git a/src/filesystem/filesystem_instance.h b/src/filesystem/filesystem_instance.h index 3721496..617fab3 100644 --- a/src/filesystem/filesystem_instance.h +++ b/src/filesystem/filesystem_instance.h @@ -80,6 +80,7 @@ class FilesystemInstance : public common::ParsedInstance, FilesystemStateChangeL void main(void); public: + void stop(); Worker(); ~Worker(); -- 2.7.4 From e0bb8cb548c52464703190e668624a13fa68f718 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Tue, 10 Jul 2018 15:35:36 +0200 Subject: [PATCH 02/16] [HRM] Fix for resetting pedometer data after calling start [Bug] Pedometer properties were not reset back to zero after calling start again. [Verification] Auto TCT passrate 100% Manual (wearable and mobile emulators) 100% Change-Id: I4b961a5c05224accb7ff482c570b3dd3aa352bb4 Signed-off-by: Pawel Kaczmarczyk --- .../humanactivitymonitor_manager.cc | 212 ++++++++++++--------- 1 file changed, 121 insertions(+), 91 deletions(-) diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 9a52f2f..1dc5779 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -269,6 +269,7 @@ class HumanActivityMonitorManager::Monitor { class GestureMonitor; class SensorMonitor; class GpsMonitor; + class PedometerMonitor; explicit Monitor(const std::string& t) : type_(t) { ScopeLogger(type()); @@ -533,10 +534,10 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor SensorMonitor(const std::string& t, sensor_type_e s, const SensorEventConverter& c, const SensorRecordedConverter& r) : Monitor(t), - sensor_(s), - handle_(nullptr), converter_(c), converter_recorded_(r), + sensor_(s), + handle_(nullptr), recorded_data_(nullptr) { ScopeLogger(type()); } @@ -764,6 +765,9 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor recorded_data_->push_back(*data); } + SensorEventConverter converter_; + SensorRecordedConverter converter_recorded_; + private: static void OnSensorEvent(sensor_h, sensor_event_s* event, void* user_data) { ScopeLogger(); @@ -869,12 +873,123 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor sensor_type_e sensor_; sensor_listener_h handle_; - SensorEventConverter converter_; - SensorRecordedConverter converter_recorded_; picojson::array* recorded_data_; std::mutex mutex_; }; +class HumanActivityMonitorManager::Monitor::PedometerMonitor + : public HumanActivityMonitorManager::Monitor::SensorMonitor { + private: + bool is_first_read; + + public: + PedometerMonitor() + : SensorMonitor(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, nullptr, nullptr), + is_first_read(true) { + ScopeLogger(); + converter_ = [this](sensor_event_s* event, picojson::object* data) -> PlatformResult { + + ScopeLogger("Entered into asynchronous function, convert_pedometer"); + + const auto pedometer_data = (PedometerDataWrapper*)event; + + static PedometerDataWrapper initial_pedometer_data; + + if (this->is_first_read) { + initial_pedometer_data = *pedometer_data; + this->is_first_read = false; + } + + static float steps_so_far = 0.0; + + const auto state = pedometer_data->state(); + + data->insert(std::make_pair(kStepStatus, picojson::value(FromSensorPedometerState(state)))); + data->insert(std::make_pair(kSpeed, picojson::value(pedometer_data->speed()))); + data->insert(std::make_pair(kWalkingFrequency, picojson::value(pedometer_data->frequency()))); + + data->insert(std::make_pair( + kCumulativeDistance, + picojson::value(pedometer_data->distance() - initial_pedometer_data.distance()))); + data->insert(std::make_pair( + kCumulativeCalorie, + picojson::value(pedometer_data->calories() - initial_pedometer_data.calories()))); + data->insert(std::make_pair( + kCumulativeTotalStepCount, + picojson::value(pedometer_data->steps() - initial_pedometer_data.steps()))); + data->insert(std::make_pair( + kCumulativeWalkStepCount, + picojson::value(pedometer_data->walk_steps() - initial_pedometer_data.walk_steps()))); + data->insert(std::make_pair( + kCumulativeRunStepCount, + picojson::value(pedometer_data->run_steps() - initial_pedometer_data.run_steps()))); + + data->insert( + std::make_pair(kAccumulativeDistance, picojson::value(pedometer_data->distance()))); + data->insert( + std::make_pair(kAccumulativeCalorie, picojson::value(pedometer_data->calories()))); + data->insert( + std::make_pair(kAccumulativeTotalStepCount, picojson::value(pedometer_data->steps()))); + data->insert(std::make_pair(kAccumulativeWalkStepCount, + picojson::value(pedometer_data->walk_steps()))); + data->insert( + std::make_pair(kAccumulativeRunStepCount, picojson::value(pedometer_data->run_steps()))); + + auto& diffs = + data->insert(std::make_pair(kStepCountDifferences, picojson::value{picojson::array{}})) + .first->second.get(); + LoggerD("pedometer_data->diffs_count: %d", pedometer_data->diffs_count); + if (pedometer_data->diffs_count > 0) { + for (int i = 0; i < pedometer_data->diffs_count; ++i) { + InsertStepDifference(pedometer_data->diffs[i].steps, + getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, + &diffs); + } + } else { + InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, + getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs); + } + + steps_so_far = pedometer_data->steps(); + + return PlatformResult(ErrorCode::NO_ERROR); + }; + + converter_recorded_ = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("Entered into asynchronous function, convert_recorded_pedometer"); + + SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_STEPS, kRecordedTotalStepCount}, + {SENSOR_RECORDER_DATA_WALK_STEPS, kRecordedWalkStepCount}, + {SENSOR_RECORDER_DATA_RUN_STEPS, kRecordedRunStepCount}}; + + SensorRecorderDataMap map_double{{SENSOR_RECORDER_DATA_DISTANCE, kRecordedDistance}, + {SENSOR_RECORDER_DATA_CALORIE, kRecordedCalorie}}; + + auto result = ConvertRecordedInt(data, obj, map_int); + if (!result) { + return result; + } + + result = ConvertRecordedDouble(data, obj, map_double); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + } + + virtual ~PedometerMonitor() { + ScopeLogger(); + } + + virtual PlatformResult SetListenerImpl(const picojson::value& args) override { + ScopeLogger(); + is_first_read = true; + return HumanActivityMonitorManager::Monitor::SensorMonitor::SetListenerImpl(args); + } +}; + class HumanActivityMonitorManager::Monitor::GpsMonitor : public HumanActivityMonitorManager::Monitor { public: @@ -1299,66 +1414,6 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() : activity_recognition_(std::make_shared()) { ScopeLogger(); - auto convert_pedometer = [](sensor_event_s* event, picojson::object* data) -> PlatformResult { - ScopeLogger("Entered into asynchronous function, convert_pedometer"); - - const auto pedometer_data = (PedometerDataWrapper*)event; - - static const auto initial_pedometer_data = *pedometer_data; // will be initialized only once - static float steps_so_far = 0.0; - - const auto state = pedometer_data->state(); - - data->insert(std::make_pair(kStepStatus, picojson::value(FromSensorPedometerState(state)))); - data->insert(std::make_pair(kSpeed, picojson::value(pedometer_data->speed()))); - data->insert(std::make_pair(kWalkingFrequency, picojson::value(pedometer_data->frequency()))); - - data->insert(std::make_pair( - kCumulativeDistance, - picojson::value(pedometer_data->distance() - initial_pedometer_data.distance()))); - data->insert(std::make_pair( - kCumulativeCalorie, - picojson::value(pedometer_data->calories() - initial_pedometer_data.calories()))); - data->insert( - std::make_pair(kCumulativeTotalStepCount, - picojson::value(pedometer_data->steps() - initial_pedometer_data.steps()))); - data->insert(std::make_pair( - kCumulativeWalkStepCount, - picojson::value(pedometer_data->walk_steps() - initial_pedometer_data.walk_steps()))); - data->insert(std::make_pair( - kCumulativeRunStepCount, - picojson::value(pedometer_data->run_steps() - initial_pedometer_data.run_steps()))); - - data->insert( - std::make_pair(kAccumulativeDistance, picojson::value(pedometer_data->distance()))); - data->insert(std::make_pair(kAccumulativeCalorie, picojson::value(pedometer_data->calories()))); - data->insert( - std::make_pair(kAccumulativeTotalStepCount, picojson::value(pedometer_data->steps()))); - data->insert( - std::make_pair(kAccumulativeWalkStepCount, picojson::value(pedometer_data->walk_steps()))); - data->insert( - std::make_pair(kAccumulativeRunStepCount, picojson::value(pedometer_data->run_steps()))); - - auto& diffs = - data->insert(std::make_pair(kStepCountDifferences, picojson::value{picojson::array{}})) - .first->second.get(); - LOGGER(DEBUG) << " pedometer_data->diffs_coun: " << pedometer_data->diffs_count; - if (pedometer_data->diffs_count > 0) { - for (int i = 0; i < pedometer_data->diffs_count; ++i) { - InsertStepDifference(pedometer_data->diffs[i].steps, - getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, - &diffs); - } - } else { - InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, - getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs); - } - - steps_so_far = pedometer_data->steps(); - - return PlatformResult(ErrorCode::NO_ERROR); - }; - auto convert_hrm = [](sensor_event_s* event, picojson::object* data) -> PlatformResult { ScopeLogger("Entered into asynchronous function, convert_hrm"); @@ -1425,29 +1480,6 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return PlatformResult(ErrorCode::NO_ERROR); }; - auto convert_recorded_pedometer = [](void* data, picojson::object* obj) -> PlatformResult { - ScopeLogger("Entered into asynchronous function, convert_recorded_pedometer"); - - SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_STEPS, kRecordedTotalStepCount}, - {SENSOR_RECORDER_DATA_WALK_STEPS, kRecordedWalkStepCount}, - {SENSOR_RECORDER_DATA_RUN_STEPS, kRecordedRunStepCount}}; - - SensorRecorderDataMap map_double{{SENSOR_RECORDER_DATA_DISTANCE, kRecordedDistance}, - {SENSOR_RECORDER_DATA_CALORIE, kRecordedCalorie}}; - - auto result = ConvertRecordedInt(data, obj, map_int); - if (!result) { - return result; - } - - result = ConvertRecordedDouble(data, obj, map_double); - if (!result) { - return result; - } - - return ConvertRecordedTime(data, obj); - }; - auto convert_recorded_hrm = [](void* data, picojson::object* obj) -> PlatformResult { ScopeLogger("Entered into asynchronous function, convert_recorded_hrm"); @@ -1491,10 +1523,8 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return ConvertRecordedTime(data, obj); }; - monitors_.insert(std::make_pair( - kActivityTypePedometer, - std::make_shared(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, - convert_pedometer, convert_recorded_pedometer))); + monitors_.insert(std::make_pair(kActivityTypePedometer, + std::make_shared())); monitors_.insert(std::make_pair(kActivityTypeWristUp, std::make_shared(kActivityTypeWristUp))); monitors_.insert(std::make_pair( -- 2.7.4 From 8cacc6d48ce88fefad4fc89c3f41bacad4e13e06 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Thu, 12 Jul 2018 07:38:20 +0200 Subject: [PATCH 03/16] [version] 2.24 Change-Id: I612a9ec9977025efbbb35fa2c58e4c3ec8226b79 Signed-off-by: Lukasz Bardeli --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index c6a0ee0..70ab9fb 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 2.23 +Version: 2.24 Release: 0 License: Apache-2.0 and BSD-3-Clause and MIT Group: Development/Libraries -- 2.7.4 From 8a4e58ab9b249724f2c21d671bb5ddc2e10aaa3b Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Tue, 10 Jul 2018 15:35:36 +0200 Subject: [PATCH 04/16] [HRM] Fix for resetting pedometer data after calling start [Bug] Pedometer properties were not reset back to zero after calling start again. [Verification] Auto TCT passrate 100% Manual (wearable and mobile emulators) 100% Change-Id: I4b961a5c05224accb7ff482c570b3dd3aa352bb4 Signed-off-by: Pawel Kaczmarczyk --- .../humanactivitymonitor_manager.cc | 212 ++++++++++++--------- 1 file changed, 121 insertions(+), 91 deletions(-) diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 7dd71e1..676d6cb 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -272,6 +272,7 @@ class HumanActivityMonitorManager::Monitor { class GestureMonitor; class SensorMonitor; class GpsMonitor; + class PedometerMonitor; explicit Monitor(const std::string& t) : type_(t) { ScopeLogger("type %s", type().c_str()); @@ -536,10 +537,10 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor SensorMonitor(const std::string& t, sensor_type_e s, const SensorEventConverter& c, const SensorRecordedConverter& r) : Monitor(t), - sensor_(s), - handle_(nullptr), converter_(c), converter_recorded_(r), + sensor_(s), + handle_(nullptr), recorded_data_(nullptr) { ScopeLogger("type %s", type().c_str()); } @@ -767,6 +768,9 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor recorded_data_->push_back(*data); } + SensorEventConverter converter_; + SensorRecordedConverter converter_recorded_; + private: static void OnSensorEvent(sensor_h, sensor_event_s* event, void* user_data) { ScopeLogger(); @@ -872,12 +876,123 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor sensor_type_e sensor_; sensor_listener_h handle_; - SensorEventConverter converter_; - SensorRecordedConverter converter_recorded_; picojson::array* recorded_data_; std::mutex mutex_; }; +class HumanActivityMonitorManager::Monitor::PedometerMonitor + : public HumanActivityMonitorManager::Monitor::SensorMonitor { + private: + bool is_first_read; + + public: + PedometerMonitor() + : SensorMonitor(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, nullptr, nullptr), + is_first_read(true) { + ScopeLogger(); + converter_ = [this](sensor_event_s* event, picojson::object* data) -> PlatformResult { + + ScopeLogger("Entered into asynchronous function, convert_pedometer"); + + const auto pedometer_data = (PedometerDataWrapper*)event; + + static PedometerDataWrapper initial_pedometer_data; + + if (this->is_first_read) { + initial_pedometer_data = *pedometer_data; + this->is_first_read = false; + } + + static float steps_so_far = 0.0; + + const auto state = pedometer_data->state(); + + data->insert(std::make_pair(kStepStatus, picojson::value(FromSensorPedometerState(state)))); + data->insert(std::make_pair(kSpeed, picojson::value(pedometer_data->speed()))); + data->insert(std::make_pair(kWalkingFrequency, picojson::value(pedometer_data->frequency()))); + + data->insert(std::make_pair( + kCumulativeDistance, + picojson::value(pedometer_data->distance() - initial_pedometer_data.distance()))); + data->insert(std::make_pair( + kCumulativeCalorie, + picojson::value(pedometer_data->calories() - initial_pedometer_data.calories()))); + data->insert(std::make_pair( + kCumulativeTotalStepCount, + picojson::value(pedometer_data->steps() - initial_pedometer_data.steps()))); + data->insert(std::make_pair( + kCumulativeWalkStepCount, + picojson::value(pedometer_data->walk_steps() - initial_pedometer_data.walk_steps()))); + data->insert(std::make_pair( + kCumulativeRunStepCount, + picojson::value(pedometer_data->run_steps() - initial_pedometer_data.run_steps()))); + + data->insert( + std::make_pair(kAccumulativeDistance, picojson::value(pedometer_data->distance()))); + data->insert( + std::make_pair(kAccumulativeCalorie, picojson::value(pedometer_data->calories()))); + data->insert( + std::make_pair(kAccumulativeTotalStepCount, picojson::value(pedometer_data->steps()))); + data->insert(std::make_pair(kAccumulativeWalkStepCount, + picojson::value(pedometer_data->walk_steps()))); + data->insert( + std::make_pair(kAccumulativeRunStepCount, picojson::value(pedometer_data->run_steps()))); + + auto& diffs = + data->insert(std::make_pair(kStepCountDifferences, picojson::value{picojson::array{}})) + .first->second.get(); + LoggerD("pedometer_data->diffs_count: %d", pedometer_data->diffs_count); + if (pedometer_data->diffs_count > 0) { + for (int i = 0; i < pedometer_data->diffs_count; ++i) { + InsertStepDifference(pedometer_data->diffs[i].steps, + getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, + &diffs); + } + } else { + InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, + getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs); + } + + steps_so_far = pedometer_data->steps(); + + return PlatformResult(ErrorCode::NO_ERROR); + }; + + converter_recorded_ = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("Entered into asynchronous function, convert_recorded_pedometer"); + + SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_STEPS, kRecordedTotalStepCount}, + {SENSOR_RECORDER_DATA_WALK_STEPS, kRecordedWalkStepCount}, + {SENSOR_RECORDER_DATA_RUN_STEPS, kRecordedRunStepCount}}; + + SensorRecorderDataMap map_double{{SENSOR_RECORDER_DATA_DISTANCE, kRecordedDistance}, + {SENSOR_RECORDER_DATA_CALORIE, kRecordedCalorie}}; + + auto result = ConvertRecordedInt(data, obj, map_int); + if (!result) { + return result; + } + + result = ConvertRecordedDouble(data, obj, map_double); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + } + + virtual ~PedometerMonitor() { + ScopeLogger(); + } + + virtual PlatformResult SetListenerImpl(const picojson::value& args) override { + ScopeLogger(); + is_first_read = true; + return HumanActivityMonitorManager::Monitor::SensorMonitor::SetListenerImpl(args); + } +}; + class HumanActivityMonitorManager::Monitor::GpsMonitor : public HumanActivityMonitorManager::Monitor { public: @@ -1302,66 +1417,6 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() : activity_recognition_(std::make_shared()) { ScopeLogger(); - auto convert_pedometer = [](sensor_event_s* event, picojson::object* data) -> PlatformResult { - ScopeLogger("Entered into asynchronous function, convert_pedometer"); - - const auto pedometer_data = (PedometerDataWrapper*)event; - - static const auto initial_pedometer_data = *pedometer_data; // will be initialized only once - static float steps_so_far = 0.0; - - const auto state = pedometer_data->state(); - - data->insert(std::make_pair(kStepStatus, picojson::value(FromSensorPedometerState(state)))); - data->insert(std::make_pair(kSpeed, picojson::value(pedometer_data->speed()))); - data->insert(std::make_pair(kWalkingFrequency, picojson::value(pedometer_data->frequency()))); - - data->insert(std::make_pair( - kCumulativeDistance, - picojson::value(pedometer_data->distance() - initial_pedometer_data.distance()))); - data->insert(std::make_pair( - kCumulativeCalorie, - picojson::value(pedometer_data->calories() - initial_pedometer_data.calories()))); - data->insert( - std::make_pair(kCumulativeTotalStepCount, - picojson::value(pedometer_data->steps() - initial_pedometer_data.steps()))); - data->insert(std::make_pair( - kCumulativeWalkStepCount, - picojson::value(pedometer_data->walk_steps() - initial_pedometer_data.walk_steps()))); - data->insert(std::make_pair( - kCumulativeRunStepCount, - picojson::value(pedometer_data->run_steps() - initial_pedometer_data.run_steps()))); - - data->insert( - std::make_pair(kAccumulativeDistance, picojson::value(pedometer_data->distance()))); - data->insert(std::make_pair(kAccumulativeCalorie, picojson::value(pedometer_data->calories()))); - data->insert( - std::make_pair(kAccumulativeTotalStepCount, picojson::value(pedometer_data->steps()))); - data->insert( - std::make_pair(kAccumulativeWalkStepCount, picojson::value(pedometer_data->walk_steps()))); - data->insert( - std::make_pair(kAccumulativeRunStepCount, picojson::value(pedometer_data->run_steps()))); - - auto& diffs = - data->insert(std::make_pair(kStepCountDifferences, picojson::value{picojson::array{}})) - .first->second.get(); - LoggerD("pedometer_data->diffs_count: %d", pedometer_data->diffs_count); - if (pedometer_data->diffs_count > 0) { - for (int i = 0; i < pedometer_data->diffs_count; ++i) { - InsertStepDifference(pedometer_data->diffs[i].steps, - getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, - &diffs); - } - } else { - InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, - getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs); - } - - steps_so_far = pedometer_data->steps(); - - return PlatformResult(ErrorCode::NO_ERROR); - }; - auto convert_hrm = [](sensor_event_s* event, picojson::object* data) -> PlatformResult { ScopeLogger("Entered into asynchronous function, convert_hrm"); @@ -1428,29 +1483,6 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return PlatformResult(ErrorCode::NO_ERROR); }; - auto convert_recorded_pedometer = [](void* data, picojson::object* obj) -> PlatformResult { - ScopeLogger("Entered into asynchronous function, convert_recorded_pedometer"); - - SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_STEPS, kRecordedTotalStepCount}, - {SENSOR_RECORDER_DATA_WALK_STEPS, kRecordedWalkStepCount}, - {SENSOR_RECORDER_DATA_RUN_STEPS, kRecordedRunStepCount}}; - - SensorRecorderDataMap map_double{{SENSOR_RECORDER_DATA_DISTANCE, kRecordedDistance}, - {SENSOR_RECORDER_DATA_CALORIE, kRecordedCalorie}}; - - auto result = ConvertRecordedInt(data, obj, map_int); - if (!result) { - return result; - } - - result = ConvertRecordedDouble(data, obj, map_double); - if (!result) { - return result; - } - - return ConvertRecordedTime(data, obj); - }; - auto convert_sleep_detector = [](sensor_event_s* event, picojson::object* data) -> PlatformResult { ScopeLogger("convert_sleep_detector"); @@ -1541,10 +1573,8 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return ConvertRecordedTime(data, obj); }; - monitors_.insert(std::make_pair( - kActivityTypePedometer, - std::make_shared(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, - convert_pedometer, convert_recorded_pedometer))); + monitors_.insert(std::make_pair(kActivityTypePedometer, + std::make_shared())); monitors_.insert(std::make_pair(kActivityTypeWristUp, std::make_shared(kActivityTypeWristUp))); monitors_.insert(std::make_pair(kActivityTypeSleepDetector, -- 2.7.4 From 1d5c74490efe24dbbb60e5f85f49b07b097d5da8 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Thu, 12 Jul 2018 11:45:50 +0200 Subject: [PATCH 05/16] [version] 2.27 Change-Id: I1beaa9f9255ddfc57aae071d15294f33481fce7a Signed-off-by: Lukasz Bardeli --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index aa28e9d..21765e3 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -8,7 +8,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 2.26 +Version: 2.27 Release: 0 License: Apache-2.0 and BSD-3-Clause and MIT Group: Development/Libraries -- 2.7.4 From 41ee8a49f96c04e9b9c69382b140e9e07ce384c2 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Thu, 26 Jul 2018 09:05:03 +0200 Subject: [PATCH 06/16] [NFC] Minor fixes [Bugs] 1. In special cases records objects were created as empty 2. If NFCPeerDetectCallback or NFCTagDetectCallback did not have defined function to call on action an TypeError would be thrown. [Verification] tct-nfc-tizen-tests passrate 100% Change-Id: I32d6cbdc05c491f42100580a1cfe021c4c877bfc Signed-off-by: Pawel Kaczmarczyk --- src/nfc/nfc_api.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js index c282348..4dcead5 100644 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@ -347,7 +347,7 @@ function setTagListener() { return; } } - args.listener[message.action](tagObject); + native_.callIfPossible(args.listener[message.action], tagObject); }; // Register (acivate) core listener if not done yet @@ -380,7 +380,7 @@ function setPeerListener() { if ('onattach' === msg.action) { data = new NFCPeer(msg.id); } - args.listener[msg.action](data); + native_.callIfPossible(args.listener[msg.action], data); }; if (!native_.isListenerSet(PEER_LISTENER)) { @@ -924,7 +924,7 @@ var toRecordsArray = function(array) { var data = new InternalRecordData(array[i].tnf, array[i].type, array[i].payload, array[i].id); if (array[i].recordType == 'Record') { - result.push(new tizen.NDEFRecord(data.tnf_, data.type_, data.payload_, data.id_)); + result.push(new tizen.NDEFRecord(data.tnf, data.type, data.payload, data.id)); continue; } @@ -940,7 +940,7 @@ var toRecordsArray = function(array) { } if (array[i].recordType == 'RecordMedia') { - result.push(new tizen.NDEFRecordMedia(array[i].mimeType, array[i].data, data)); + result.push(new tizen.NDEFRecordMedia(array[i].mimeType, null, data)); continue; } } @@ -1528,11 +1528,11 @@ tizen.NDEFRecordMedia = function(mimeType, data, internal_) { try { if (arguments.length >= 2) { mimeType_ = converter_.toString(mimeType); - data_ = toByteArray(data, Math.pow(2, 32) - 1); if (!type_.isNullOrUndefined(internal_) && (internal_ instanceof InternalRecordData)) { tizen.NDEFRecord.call(this, internal_.tnf, internal_.type, internal_.payload, internal_.id); } else { + data_ = toByteArray(data, Math.pow(2, 32) - 1); var result = native_.callSync( 'NDEFRecordMedia_constructor', { 'mimeType': mimeType_, -- 2.7.4 From fb3a4a2c7b41a2f4af08c606427e467707a3c559 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Wed, 18 Jul 2018 15:45:45 +0200 Subject: [PATCH 07/16] [HAM] Fix throwing exceptions for getHumanActivityData [Bug] getHumanActivityData method accepts only 'PEDOMETER' and 'HRM' values of HumanActivityType enum as type parameter. Any other value should cause NotSupportedError, but implementation leaded to UnknownError instead. [Verification] AutoTCT 100% passrate Change-Id: Id5145d76f8957527e28f42c9b1c3141b11b8e5ca Signed-off-by: Pawel Kaczmarczyk --- src/humanactivitymonitor/humanactivitymonitor_api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js index 3f06004..dccf34c 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@ -191,12 +191,10 @@ HumanActivityMonitorManager.prototype.getHumanActivityData = function(type, succ {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); - if (args.type === HumanActivityType.WRIST_UP) { + if (-1 === [HumanActivityType.HRM, HumanActivityType.PEDOMETER].indexOf(args.type)) { throw new WebAPIException(WebAPIException.NOT_SUPPORTED_ERR); } - var listenerId = 'HumanActivityMonitor_' + args.type; - var data = { type: args.type }; -- 2.7.4 From d7bc239b135e68a98e9c960f09d020962e64bfb8 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Wed, 8 Aug 2018 14:32:16 +0200 Subject: [PATCH 08/16] [SystemInfo][Bluetooth][Push] Add misssing deprecation warnings since Tizen 3.0 [Verification] Code compiles tct-systeminfo-tizen-tests passrate 100% Change-Id: I41db5325ac94ca042069551a41161e5b968e51d3 Signed-off-by: Pawel Kaczmarczyk --- src/bluetooth/bluetooth_adapter.cc | 3 +++ src/bluetooth/bluetooth_api.js | 3 +++ src/push/push_instance.cc | 12 ++++++++++++ src/systeminfo/systeminfo_api.js | 12 +++++++++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/bluetooth/bluetooth_adapter.cc b/src/bluetooth/bluetooth_adapter.cc index 9fbf87e..0da34d5 100644 --- a/src/bluetooth/bluetooth_adapter.cc +++ b/src/bluetooth/bluetooth_adapter.cc @@ -641,6 +641,9 @@ void BluetoothAdapter::SetPowered(const picojson::value& data, picojson::object& void BluetoothAdapter::SetVisible(const picojson::value& data, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: setVisible() is deprecated and will be removed from next release. " + "Let the user change the Bluetooth visibility through the Settings application instead."); CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothManager, &out); diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js index 09979b3..9fb4266 100755 --- a/src/bluetooth/bluetooth_api.js +++ b/src/bluetooth/bluetooth_api.js @@ -2078,6 +2078,9 @@ BluetoothAdapter.prototype.setPowered = function() { // This method is deprecated since Tizen 2.3 and will be removed in Tizen 3.0. BluetoothAdapter.prototype.setVisible = function() { privUtils_.log('Entered BluetoothAdapter.setVisible()'); + privUtils_.warn('DEPRECATION WARNING: setVisible() is deprecated and will be removed from next release. ' + + 'Let the user change the Bluetooth visibility through the Settings application instead.'); + var args = AV.validateMethod(arguments, [ { name : 'visible', diff --git a/src/push/push_instance.cc b/src/push/push_instance.cc index f7b277d..f05e04b 100644 --- a/src/push/push_instance.cc +++ b/src/push/push_instance.cc @@ -64,6 +64,9 @@ PushInstance::PushInstance() { void PushInstance::registerService(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. " + "Use register() instead."); CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); common::PlatformResult result = impl->registerService(args.get("callbackId").get()); @@ -88,6 +91,9 @@ void PushInstance::registerApplication(const picojson::value& args, picojson::ob void PushInstance::unregisterService(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next " + "release. Use unregister() instead."); CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); @@ -114,6 +120,9 @@ void PushInstance::unregisterApplication(const picojson::value& args, picojson:: void PushInstance::connectService(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. " + "Use connect() instead."); CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); @@ -140,6 +149,9 @@ void PushInstance::connect(const picojson::value& args, picojson::object& out) { void PushInstance::disconnectService(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next " + "release. Use disconnect() instead."); CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index 63b3e5e..a14be23 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -441,6 +441,8 @@ function SystemInfoCpu(data) { //class SystemInfoStorageUnit //////////////////////////////////////////////////// function SystemInfoStorageUnit(data) { + var _isRemovable = data.isRemovable; + Object.defineProperties(this, { type : { value: data.type, @@ -463,9 +465,13 @@ function SystemInfoStorageUnit(data) { enumerable : true }, isRemoveable : { - value : data.isRemovable, - writable : false, - enumerable : true + enumerable : true, + get: function() { + privUtils_.warn('DEPRECATION WARNING: SystemInfoStorageUnit.isRemoveable is is deprecated and will be ' + + 'removed from next release. Use SystemInfoStorageUnit.isRemovable instead.'); + return _isRemovable; + }, + set: function() {} } }); } -- 2.7.4 From 07f110666a1c9cb17b2f6cc66d4573b097ad4b8d Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Thu, 9 Aug 2018 10:40:58 +0200 Subject: [PATCH 09/16] [HAM][Notification][Alarm] Add missing deprecation warnings since Tizen 4.0 [Verification] tct-humanactivitymonitor-tizen-tests auto 100% tct-notification-tizen-tests auto 100% tct-alarm-tizen-tests auto 100% Change-Id: I8d0de96c0d6a2ca8a009a25a7c1373dc4064ec36 Signed-off-by: Pawel Kaczmarczyk --- src/alarm/alarm_api.js | 9 +++++++++ src/humanactivitymonitor/humanactivitymonitor_api.js | 10 ++++++++++ src/humanactivitymonitor/humanactivitymonitor_instance.cc | 12 ++++++++++++ src/notification/notification_api.js | 14 ++++++++++++++ src/notification/notification_instance.cc | 15 +++++++++++++-- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js index e8507f6..626756d 100755 --- a/src/alarm/alarm_api.js +++ b/src/alarm/alarm_api.js @@ -443,9 +443,18 @@ tizen.AlarmAbsolute = function(date, second, internal) { }, period: { get: function() { + if(_warningLogs.enableLog){ + privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' + + 'is deprecated, thus period attribute should not be used.'); + } return m_period; }, set: function(v) { + if(_warningLogs.enableLog){ + privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' + + 'is deprecated, thus period attribute should not be used.'); + } + if (_edit.canEdit && v) { m_period = Converter.toLong(v.period); } diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js index 691b953..5c7daf6 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@ -296,6 +296,11 @@ HumanActivityMonitorManager.prototype.start = function(type, changedCallback) { {name: 'options', type : types_.DICTIONARY, optional : true, nullable : true} ]); + if (HumanActivityType.WRIST_UP === args.type) { + utils_.warn('DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since Tizen 4.0. ' + + 'Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture'); + } + var listenerId = 'HumanActivityMonitor_' + args.type; var optionsAttributes = ["callbackInterval", "sampleInterval"], options = args.options || {}; @@ -365,6 +370,11 @@ HumanActivityMonitorManager.prototype.stop = function(type) { {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)} ]); + if (HumanActivityType.WRIST_UP === args.type) { + utils_.warn('DEPRECATION WARNING: HumanActivityType.WRIST_UP is deprecated since Tizen 4.0. ' + + 'Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture'); + } + if (HumanActivityType.PEDOMETER === args.type) { stopListener('HumanActivityMonitor_PEDOMETER', 'HumanActivityMonitorManager_stop', diff --git a/src/humanactivitymonitor/humanactivitymonitor_instance.cc b/src/humanactivitymonitor/humanactivitymonitor_instance.cc index b035f9a..39fceb7 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_instance.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_instance.cc @@ -155,6 +155,12 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStart(const picojs CHECK_PRIVILEGE_ACCESS(kPrivilegeLocation, &out); } + if ("WRIST_UP" == type) { + LoggerW( + "DEPRECATION WARNING: HumanactivityType.WRIST_UP is deprecated since Tizen 4.0. " + "Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture"); + } + PlatformResult result = Init(); if (!result) { LogAndReportError(result, &out, ("Failed: Init()")); @@ -197,6 +203,12 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStop(const picojso CHECK_PRIVILEGE_ACCESS(kPrivilegeLocation, &out); } + if ("WRIST_UP" == type) { + LoggerW( + "DEPRECATION WARNING: HumanactivityType.WRIST_UP is deprecated since Tizen 4.0. " + "Use GestureType and addGestureRecognitionListener to monitor WRIST_UP gesture"); + } + PlatformResult result = Init(); if (!result) { LogAndReportError(result, &out, ("Failed: Init()")); diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js index 1b8bc52..8e186f1 100644 --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@ -94,6 +94,10 @@ NotificationManager.prototype.post = function(notification) { {name: 'notification', type: types_.PLATFORM_OBJECT, values: Notification} ]); + if (args.notification instanceof tizen.StatusNotification) { + utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); + } + var data = { //add marker for UserNotification implementation newImpl: (args.notification instanceof tizen.UserNotification), @@ -126,6 +130,10 @@ NotificationManager.prototype.update = function(notification) { throw new WebAPIException(WebAPIException.UNKNOWN_ERR); } + if (args.notification instanceof tizen.StatusNotification) { + utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); + } + var data = { //add marker for UserNotification implementation newImpl: (args.notification instanceof tizen.UserNotification), @@ -172,6 +180,8 @@ NotificationManager.prototype.get = function(id) { {name: 'id', type: types_.STRING} ]); + utils_.warn('DEPRECATION WARNING: get() is deprecated since Tizen 4.0. Use getNotification() instead.'); + if (!arguments.length) { throw new WebAPIException(WebAPIException.NOT_FOUND_ERR); } @@ -226,6 +236,8 @@ NotificationManager.prototype.getNotification = function(id) { }; NotificationManager.prototype.getAll = function() { + utils_.warn('DEPRECATION WARNING: getAll() is deprecated since Tizen 4.0. Use getAllNotifications() instead.'); + var result = native_.callSync('NotificationManager_getAll', {}); if (native_.isFailure(result)) { @@ -652,6 +664,8 @@ function StatusNotification(statusType, title, notificationInitDict) { NotificationInitDict.call(this, notificationInitDict); Notification.call(this, notificationInitDict); + utils_.warn('DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use UserNotification instead.'); + var _statusType = (Object.keys(StatusNotificationType)).indexOf(statusType) >= 0 ? statusType : StatusNotificationType.SIMPLE; diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc index 433830a..32471a1 100644 --- a/src/notification/notification_instance.cc +++ b/src/notification/notification_instance.cc @@ -79,7 +79,9 @@ void NotificationInstance::NotificationManagerPost(const picojson::value& args, LoggerD("New implementation"); impl = std::bind(&NotificationManager::PostUserNoti, manager_, _1, _2); } else { - LoggerW("Deprecated object used"); + LoggerW( + "DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use " + "UserNotification instead."); impl = std::bind(&NotificationManager::Post, manager_, _1, _2); } @@ -103,7 +105,9 @@ void NotificationInstance::NotificationManagerUpdate(const picojson::value& args LoggerD("New implementation"); impl = std::bind(&NotificationManager::UpdateUserNoti, manager_, _1); } else { - LoggerW("Deprecated object used"); + LoggerW( + "DEPRECATION WARNING: StatusNotification is deprecated since Tizen 4.0. Use " + "UserNotification instead."); impl = std::bind(&NotificationManager::Update, manager_, _1); } @@ -147,6 +151,9 @@ void NotificationInstance::NotificationManagerRemoveAll(const picojson::value& a void NotificationInstance::NotificationManagerGet(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: get() is deprecated since Tizen 4.0. Use getNotifications() instead."); + picojson::value val{picojson::object{}}; PlatformResult status = @@ -163,6 +170,10 @@ void NotificationInstance::NotificationManagerGet(const picojson::value& args, void NotificationInstance::NotificationManagerGetAll(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: getAll() is deprecated since Tizen 4.0. Use getAllNotifications() " + "instead."); + picojson::value val{picojson::array{}}; PlatformResult status = manager_->GetAll( -- 2.7.4 From e1415f85be00d4a2530a547358ac1047a02399e6 Mon Sep 17 00:00:00 2001 From: Szymon Jastrzebski Date: Wed, 1 Aug 2018 09:20:30 +0200 Subject: [PATCH 10/16] [Filesystem] Fixing reported bugs and unifying code + Many IOErrors were thrown synchronously, but they should be reported asynchronously. + JS/C++ code was formatted + Removing unnecessary code + Methods read* returned arrays with size equal to 'size' given by user, which might have been bigger than the size of file. This led to returning arrays with redundant '\0' bytes. + Added 'path' parameter to ListDirectorySuccessCallback [ACR] http://suprem.sec.samsung.net/jira/browse/TWDAPI-121 [Verification] Filesystem TCT 100% Change-Id: If48826e6317f0a09dd927ff0ceca0cd64f26e2fc Signed-off-by: Szymon Jastrzebski --- src/filesystem/filesystem_instance.cc | 220 +++++++++++++++--------------- src/filesystem/js/common.js | 3 +- src/filesystem/js/file_handle.js | 225 ++++++++++++++++++++++++------- src/filesystem/js/file_system_manager.js | 14 +- 4 files changed, 299 insertions(+), 163 deletions(-) diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index be8e802..5941e32 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -42,6 +42,9 @@ using common::tools::GetErrorString; const std::string kPrivilegeFilesystemRead = "http://tizen.org/privilege/filesystem.read"; const std::string kPrivilegeFilesystemWrite = "http://tizen.org/privilege/filesystem.write"; +const std::string kISOEncoding = "ISO-8859-1"; +const std::string kUTF8Encoding = "UTF-8"; + std::string GetFopenMode(const picojson::value& args) { ScopeLogger(); const std::string& open_mode = args.get("openMode").get(); @@ -356,6 +359,23 @@ static std::size_t file_size(FILE* file) { return buf.st_size; } +/** + * Returns the amount of bytes to the EOF starting from current file-position indicator. + * + * On failure throws std::system_error + */ +static std::size_t file_bytes_to_eof(FILE* file) { + ScopeLogger(); + + std::size_t total_fize_size = file_size(file); + long file_position = ftell(file); + if (-1 == file_position) { + throw std::system_error{errno, std::generic_category(), + "Failed to get file position"s + GetErrorString(errno)}; + } + return total_fize_size - static_cast(file_position); +} + static std::vector read_file(FILE* file, std::size_t length = NPOS); /** @@ -403,7 +423,12 @@ static std::vector read_file(FILE* file, std::size_t length /*= NP length = file_size(file); } - std::vector out_buf(length); + std::vector out_buf; + try { + out_buf.resize(length); + } catch (std::bad_alloc& err) { + throw std::runtime_error{"Could not allocate memory"}; + } std::uint8_t* data_p = out_buf.data(); std::uint8_t* end_p = data_p + length; while (data_p != end_p) { @@ -1743,9 +1768,14 @@ void FilesystemInstance::FileSystemManagerListDirectory(const picojson::value& a } } - picojson::value value{picojson::array_type, true}; - picojson::array& names_array = value.get(); + picojson::value value = picojson::value(picojson::object()); + picojson::object& object = value.get(); + + object["names"] = picojson::value{picojson::array_type, true}; + object["path"] = picojson::value(path); + picojson::array& names_array = object["names"].get(); + names_array.reserve(names.size()); for (unsigned int i = 0; i < names.size(); ++i) { names_array.push_back(picojson::value(names[i])); } @@ -1859,40 +1889,33 @@ void FilesystemInstance::FileHandleSeek(const picojson::value& args, picojson::o auto handle = fh->second; auto logic = [handle, whence, offset](decltype(out) out) { - try { - long ret = fseek(handle->file_handle, offset, whence); - if (0 != ret) { - LoggerE("fseek returned failed"); - std::string error_message = - std::string("seek failed, fileHandle may be corrupted, error message: ") + - GetErrorString(errno); - LogAndReportError(IOException(error_message.c_str()), out); - return; - } - - ret = ftell(handle->file_handle); - if (-1L == ret) { - LoggerE("ftell returned failed"); - std::string error_message = - std::string("seek failed, fileHandle may be corrupted, error message: ") + - GetErrorString(errno); - LogAndReportError(IOException(error_message.c_str()), out); - return; - } + long ret = fseek(handle->file_handle, offset, whence); + if (0 != ret) { + LoggerE("fseek returned failed"); + std::string error_message = + std::string("seek failed, fileHandle may be corrupted, error message: ") + + GetErrorString(errno); + LogAndReportError(IOException(error_message.c_str()), out); + return; + } - ReportSuccess(picojson::value((double)ret), out); - } catch (std::runtime_error& e) { - LoggerE("Cannot read, cause: %s", e.what()); - LogAndReportError(IOException(e.what()), out); + ret = ftell(handle->file_handle); + if (-1L == ret) { + LoggerE("ftell returned failed"); + std::string error_message = + std::string("seek failed, fileHandle may be corrupted, error message: ") + + GetErrorString(errno); + LogAndReportError(IOException(error_message.c_str()), out); return; } + + ReportSuccess(picojson::value((double)ret), out); }; bool blocking = args.contains("blocking") ? args.get("blocking").get() : true; if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -1906,7 +1929,6 @@ void FilesystemInstance::FileHandleSeek(const picojson::value& args, picojson::o // Sync return ReportSuccess(out); - return; } } @@ -1915,10 +1937,13 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj CHECK_EXIST(args, "id", out) const int fh_id = static_cast(args.get("id").get()); const std::string& encoding = - args.contains("encoding") ? args.get("encoding").get() : "utf-8"; + args.contains("encoding") ? args.get("encoding").get() : "UTF-8"; + if (encoding != kISOEncoding && encoding != kUTF8Encoding) { + LogAndReportError(NotSupportedException("Given encoding is not supported."), out); + return; + } auto fh = opened_files.find(fh_id); - if (opened_files.end() == fh) { LogAndReportError(IOException("Invalid FileHandle"), out); return; @@ -1927,7 +1952,13 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj size_t count; bool whole_file = false; if (args.contains("count")) { - count = static_cast(args.get("count").get()); + // If user passed 'count' parameter, we need to read at most 'count' characters. + double count_double = args.get("count").get(); + if (std::string::npos <= static_cast(count_double)) { + LogAndReportError(InvalidValuesException("Invalid count was given"), out); + return; + } + count = static_cast(count_double); } else { try { count = file_size(fh->second->file_handle); @@ -1937,23 +1968,18 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj return; } } - LoggerD("count: %d", count); - - if (std::string::npos == count) { - LogAndReportError(InvalidValuesException("Invalid count was given"), out); - return; - } + LoggerD("count: %zu", count); auto handle = fh->second; auto logic = [handle, count, encoding, whole_file](decltype(out) out) { try { std::vector buf = read_file(handle->file_handle, count); - if (encoding == "iso-8859-1") { // for iso-8859-1 1 byte is equal to 1 character + if (encoding == kISOEncoding) { // for iso-8859-1 1 byte is equal to 1 character out["result"] = picojson::value(picojson::string_type, true); latin1::to_utf8(buf, out["result"].get()); ReportSuccess(out); - } else if (encoding == "utf-8") { + } else { // UTF-8 unsigned long char_count; short expected_extension_bytes; if (!validate_and_check_character_count(buf, char_count, expected_extension_bytes)) { @@ -1965,7 +1991,7 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj LoggerD("ftell: %ld", ftell(handle->file_handle)); if (!(std::feof( handle->file_handle))) { // read number of characters if not whole file read - LoggerD("count parameter given: %d", count); + LoggerD("count parameter given: %zu", count); if (!whole_file && !add_utf8_chars_to_buffer(handle->file_handle, buf, count - char_count, expected_extension_bytes)) { @@ -1976,14 +2002,10 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj buf.push_back('\0'); const char* str = (const char*)buf.data(); ReportSuccess(picojson::value{str}, out); - } else { - LogAndReportError(NotSupportedException("Given encoding is not supported."), out); - return; } } catch (std::runtime_error& e) { LoggerE("Cannot read, cause: %s", e.what()); LogAndReportError(IOException(e.what()), out); - return; } }; @@ -1991,7 +2013,6 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2005,7 +2026,6 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj // Sync return ReportSuccess(out); - return; } } @@ -2016,10 +2036,13 @@ void FilesystemInstance::FileHandleWriteString(const picojson::value& args, pico const int fh_id = static_cast(args.get("id").get()); const std::string& str = args.get("string").get(); const std::string& encoding = - args.contains("encoding") ? args.get("encoding").get() : "utf-8"; + args.contains("encoding") ? args.get("encoding").get() : "UTF-8"; + if (encoding != kISOEncoding && encoding != kUTF8Encoding) { + LogAndReportError(NotSupportedException("Given encoding is not supported."), out); + return; + } auto fh = opened_files.find(fh_id); - if (opened_files.end() == fh) { LogAndReportError(IOException("Invalid FileHandle"), out); return; @@ -2032,9 +2055,9 @@ void FilesystemInstance::FileHandleWriteString(const picojson::value& args, pico std::vector data; data.resize(str.size()); - if (encoding == "iso-8859-1") { + if (encoding == kISOEncoding) { latin1::from_utf8(str, data); - } else { + } else { // UTF-8 LoggerD("copying string memory to vector"); std::memcpy(data.data(), str.data(), str.size()); } @@ -2043,7 +2066,6 @@ void FilesystemInstance::FileHandleWriteString(const picojson::value& args, pico } catch (std::runtime_error& e) { LoggerE("Cannot write, cause: %s", e.what()); LogAndReportError(IOException(e.what()), out); - return; } }; @@ -2051,7 +2073,6 @@ void FilesystemInstance::FileHandleWriteString(const picojson::value& args, pico if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2065,7 +2086,6 @@ void FilesystemInstance::FileHandleWriteString(const picojson::value& args, pico // Sync return ReportSuccess(out); - return; } } @@ -2083,22 +2103,29 @@ void FilesystemInstance::FileHandleReadData(const picojson::value& args, picojso size_t size; if (args.contains("size")) { - size = static_cast(args.get("size").get()); - } else { - try { - size = file_size(fh->second->file_handle); - } catch (const std::system_error& e) { - LogAndReportError(IOException(e.what()), out); + // If user passed 'size' parameter, we need to read at most 'size' bytes. + double size_double = args.get("size").get(); + if (std::string::npos <= static_cast(size_double)) { + LogAndReportError(InvalidValuesException("Invalid size was given"), out); return; } + size = static_cast(size_double); } - LoggerD("size: %d", size); - if (std::string::npos == size) { - LogAndReportError(InvalidValuesException("Invalid size was given"), out); + // We need to check how many bytes is it possible to read until the EOF. + try { + // We need to read from file exactly the minimum value of 'size' given by user and the + // 'possible_bytes_to_read' to avoid returning array with redundant data + // (which would be equal to 0). + size_t possible_bytes_to_read = file_bytes_to_eof(fh->second->file_handle); + size = std::min(size, possible_bytes_to_read); + } catch (const std::system_error& e) { + LogAndReportError(IOException(e.what()), out); return; } + LoggerD("size: %zu", size); + auto handle = fh->second; auto logic = [handle, size](decltype(out) out) { @@ -2109,7 +2136,6 @@ void FilesystemInstance::FileHandleReadData(const picojson::value& args, picojso } catch (std::runtime_error& e) { LoggerE("Cannot read, cause: %s", e.what()); LogAndReportError(IOException(e.what()), out); - return; } }; @@ -2117,7 +2143,6 @@ void FilesystemInstance::FileHandleReadData(const picojson::value& args, picojso if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2131,7 +2156,6 @@ void FilesystemInstance::FileHandleReadData(const picojson::value& args, picojso // Sync return ReportSuccess(out); - return; } } @@ -2158,7 +2182,6 @@ void FilesystemInstance::FileHandleWriteData(const picojson::value& args, picojs write_file(bytes.data(), bytes.size(), handle->file_handle); } catch (std::runtime_error& e) { LogAndReportError(IOException(e.what()), out); - return; } }; @@ -2166,7 +2189,6 @@ void FilesystemInstance::FileHandleWriteData(const picojson::value& args, picojs if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2180,7 +2202,6 @@ void FilesystemInstance::FileHandleWriteData(const picojson::value& args, picojs // Sync return ReportSuccess(out); - return; } } @@ -2197,17 +2218,11 @@ void FilesystemInstance::FileHandleFlush(const picojson::value& args, picojson:: auto handle = fh->second; auto logic = [handle](decltype(out) out) { - try { - int ret = fflush(handle->file_handle); - if (ret) { - std::string error_message = - std::string("flush failed, error message: ") + GetErrorString(errno); - LogAndReportError(IOException(error_message.c_str()), out); - return; - } - } catch (std::runtime_error& e) { - LogAndReportError(IOException(e.what()), out); - return; + int ret = fflush(handle->file_handle); + if (ret) { + std::string error_message = + std::string("flush failed, error message: ") + GetErrorString(errno); + LogAndReportError(IOException(error_message.c_str()), out); } }; @@ -2215,7 +2230,6 @@ void FilesystemInstance::FileHandleFlush(const picojson::value& args, picojson:: if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2229,7 +2243,6 @@ void FilesystemInstance::FileHandleFlush(const picojson::value& args, picojson:: // Sync return ReportSuccess(out); - return; } } @@ -2246,17 +2259,11 @@ void FilesystemInstance::FileHandleSync(const picojson::value& args, picojson::o auto handle = fh->second; auto logic = [handle](decltype(out) out) { - try { - int ret = fsync(fileno(handle->file_handle)); - if (ret) { - std::string error_message = - std::string("sync failed, error message: ") + GetErrorString(errno); - LogAndReportError(IOException(error_message.c_str()), out); - return; - } - } catch (std::runtime_error& e) { - LogAndReportError(IOException(e.what()), out); - return; + int ret = fsync(fileno(handle->file_handle)); + if (ret) { + std::string error_message = + std::string("sync failed, error message: ") + GetErrorString(errno); + LogAndReportError(IOException(error_message.c_str()), out); } }; @@ -2264,7 +2271,6 @@ void FilesystemInstance::FileHandleSync(const picojson::value& args, picojson::o if (blocking) { logic(out); - return; } else { // Async logic double callback_id = args.get("callbackId").get(); @@ -2278,7 +2284,6 @@ void FilesystemInstance::FileHandleSync(const picojson::value& args, picojson::o // Sync return ReportSuccess(out); - return; } } @@ -2295,23 +2300,17 @@ void FilesystemInstance::FileHandleClose(const picojson::value& args, picojson:: opened_files.erase(fh); auto logic = [handle](decltype(out) out) { - try { - if (!handle->file_handle) { - LogAndReportError(IOException("File handle already closed."), out); - return; - } - int ret = fclose(handle->file_handle); - handle->file_handle = nullptr; - if (ret) { - std::string error_message = - std::string("close failed, error message: ") + GetErrorString(errno); - LogAndReportError(IOException(error_message.c_str()), out); - return; - } - } catch (std::runtime_error& e) { - LogAndReportError(IOException(e.what()), out); + if (!handle->file_handle) { + LogAndReportError(IOException("File handle already closed."), out); return; } + int ret = fclose(handle->file_handle); + handle->file_handle = nullptr; + if (ret) { + std::string error_message = + std::string("close failed, error message: ") + GetErrorString(errno); + LogAndReportError(IOException(error_message.c_str()), out); + } }; bool blocking = args.contains("blocking") ? args.get("blocking").get() : true; @@ -2360,7 +2359,6 @@ void FilesystemInstance::FileHandleClose(const picojson::value& args, picojson:: // Sync return ReportSuccess(out); - return; } } diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index c473ba5..61ffe4f 100644 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -431,6 +431,7 @@ var commonFS_ = (function() { f_isSubDir: f_isSubDir, f_isCorrectRelativePath: f_isCorrectRelativePath, getStorage: getStorage, - getAllStorages: getAllStorages + getAllStorages: getAllStorages, + mergeMultipleSlashes: mergeMultipleSlashes }; })(); diff --git a/src/filesystem/js/file_handle.js b/src/filesystem/js/file_handle.js index e360259..d45a1d1 100644 --- a/src/filesystem/js/file_handle.js +++ b/src/filesystem/js/file_handle.js @@ -18,7 +18,7 @@ function FileHandle(_id, _path, _mode) { Object.defineProperties(this, { id: {value: _id, writable: false, enumerable: false}, - path: {value: _path, writable: false, enumerable: false}, + path: {value: _path, writable: false, enumerable: true}, mode: {value: _mode, writable: false, enumerable: false}, state: {value: 'opened', writable: true, enumerable: false} }); @@ -63,7 +63,11 @@ FileHandle.prototype.seekNonBlocking = function() { ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } var data = {id: this.id, offset: args.offset, blocking: false}; if (undefined === args.whence) { @@ -82,7 +86,9 @@ FileHandle.prototype.seekNonBlocking = function() { var result = native_.call('FileHandle_seek', data, callback); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + }, 0); } }; @@ -97,7 +103,10 @@ FileHandle.prototype.readString = function() { if ((this.mode === 'w') || (this.mode === 'a')) { throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only'); } - var data = {id: this.id, count: args.count, inputEncoding: args.inputEncoding}; + var data = {id: this.id, encoding: args.inputEncoding}; + if (!type_.isNullOrUndefined(args.count)) { + data.count = args.count; + } var result = native_.callSync('FileHandle_readString', data); if (native_.isFailure(result)) { @@ -110,17 +119,27 @@ FileHandle.prototype.readStringNonBlocking = function() { var args = validator_.validateArgs(arguments, [ {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'size', type: types_.LONG, optional: true, nullable: true}, + {name: 'count', type: types_.LONG, optional: true}, {name: 'inputEncoding', type: types_.STRING, optional: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } if ((this.mode === 'w') || (this.mode === 'a')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only')); + }, 0); + } + var data = {id: this.id, encoding: args.inputEncoding, blocking: false}; + if (!type_.isNullOrUndefined(args.count)) { + data.count = args.count; } - var data = - {id: this.id, size: args.size, inputEncoding: args.inputEncoding, blocking: false}; var callback = function(result) { if (native_.isFailure(result)) { @@ -133,7 +152,14 @@ FileHandle.prototype.readStringNonBlocking = function() { var result = native_.call('FileHandle_readString', data, callback); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + var err = native_.getErrorObject(result); + if ('IOError' === err.name) { + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); + } else { + throw native_.getErrorObject(result); + } } }; @@ -148,7 +174,7 @@ FileHandle.prototype.writeString = function() { if ('r' === this.mode) { throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); } - var data = {id: this.id, string: args.string, outputEncoding: args.outputEncoding}; + var data = {id: this.id, string: args.string, encoding: args.outputEncoding}; var result = native_.callSync('FileHandle_writeString', data); if (native_.isFailure(result)) { @@ -165,17 +191,21 @@ FileHandle.prototype.writeStringNonBlocking = function() { {name: 'outputEncoding', type: types_.STRING, optional: true} ]); if (!('opened' === this.state)) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } if ('r' === this.mode) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only')); + }, 0); } - var data = { - id: this.id, - string: args.string, - outputEncoding: args.outputEncoding, - blocking: false - }; + var data = + {id: this.id, string: args.string, encoding: args.outputEncoding, blocking: false}; var callback = function(result) { if (native_.isFailure(result)) { @@ -188,7 +218,14 @@ FileHandle.prototype.writeStringNonBlocking = function() { var result = native_.call('FileHandle_writeString', data, callback); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + var err = native_.getErrorObject(result); + if ('IOError' === err.name) { + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); + } else { + throw native_.getErrorObject(result); + } } }; @@ -202,9 +239,15 @@ FileHandle.prototype.readBlob = function() { if ((this.mode === 'w') || (this.mode === 'a')) { throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only'); } - var data = {id: this.id, size: args.size}; - + var data = {id: this.id}; + if (!type_.isNullOrUndefined(args.size)) { + data.size = args.size; + } var result = native_.call('FileHandle_readData', data); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } var encodedData = native_.getResultObject(result); var data = StringToArray(encodedData, Uint8Array); return new Blob([data]); @@ -217,10 +260,17 @@ FileHandle.prototype.readBlobNonBlocking = function() { {name: 'size', type: types_.LONG, optional: true, nullable: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } - var data = {id: this.id, size: args.size, blocking: false}; + var data = {id: this.id, blocking: false}; + if (!type_.isNullOrUndefined(args.size)) { + data.size = args.size; + } var callback = function(result) { if (native_.isFailure(result)) { @@ -235,7 +285,14 @@ FileHandle.prototype.readBlobNonBlocking = function() { var result = native_.call('FileHandle_readData', data, callback); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + var err = native_.getErrorObject(result); + if ('IOError' === err.name) { + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); + } else { + throw native_.getErrorObject(result); + } } }; @@ -277,9 +334,17 @@ FileHandle.prototype.writeBlobNonBlocking = function() { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); if (!('opened' === this.state)) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } else if (this.mode === 'r') { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only')); + }, 0); } var encodedData = ArrayToString(blobToUint8Array(args.blob)); @@ -294,21 +359,28 @@ FileHandle.prototype.writeBlobNonBlocking = function() { var result = native_.call('FileHandle_writeData', data, callback); + // Only IOError is possible to be returned synchronously, so it is passed to + // errorCallback in each case. if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + }, 0); } }; FileHandle.prototype.readData = function() { var args = validator_.validateArgs( - arguments, [{name: 'size', type: types_.LONG, optional: true, nullable: true}]); + arguments, [{name: 'size', type: types_.LONG, optional: true}]); if (!(this.state === 'opened')) { throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); } if ((this.mode === 'w') || (this.mode === 'a')) { throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only'); } - var data = {id: this.id, size: args.size}; + var data = {id: this.id}; + if (!type_.isNullOrUndefined(args.size)) { + data.size = args.size; + } var result = native_.callSync('FileHandle_readData', data); if (native_.isFailure(result)) { @@ -326,13 +398,24 @@ FileHandle.prototype.readDataNonBlocking = function() { {name: 'size', type: types_.LONG, optional: true, nullable: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } if ((this.mode === 'w') || (this.mode === 'a')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is write-only')); + }, 0); } - var data = {id: this.id, size: args.size, blocking: false}; + var data = {id: this.id, blocking: false}; + if (!type_.isNullOrUndefined(args.size)) { + data.size = args.size; + } var callback = function(result) { if (native_.isFailure(result)) { @@ -347,7 +430,14 @@ FileHandle.prototype.readDataNonBlocking = function() { var result = native_.call('FileHandle_readData', data, callback); if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + var err = native_.getErrorObject(result); + if ('IOError' === err.name) { + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); + } else { + throw native_.getErrorObject(result); + } } }; @@ -375,9 +465,17 @@ FileHandle.prototype.writeDataNonBlocking = function() { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); if (!('opened' === this.state)) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } else if (this.mode === 'r') { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only')); + }, 0); } var encodedData = ArrayToString(args.data); @@ -394,8 +492,12 @@ FileHandle.prototype.writeDataNonBlocking = function() { var result = native_.call('FileHandle_writeData', data, callback); + // Only IOError is possible to be returned synchronously, so it is passed to + // errorCallback in each case. if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); } }; @@ -420,10 +522,18 @@ FileHandle.prototype.flushNonBlocking = function() { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } if (this.mode === 'r') { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only')); + }, 0); } var data = {id: this.id, blocking: false}; @@ -437,8 +547,12 @@ FileHandle.prototype.flushNonBlocking = function() { var result = native_.call('FileHandle_flush', data, callback); + // Only IOError is possible to be returned synchronously, so it is passed to + // errorCallback in each case. if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); } }; @@ -464,10 +578,18 @@ FileHandle.prototype.syncNonBlocking = function() { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } if (this.mode === 'r') { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle state is read-only')); + }, 0); } var data = {id: this.id, blocking: false}; @@ -481,8 +603,12 @@ FileHandle.prototype.syncNonBlocking = function() { var result = native_.call('FileHandle_sync', data, callback); + // Only IOError is possible to be returned synchronously, so it is passed to + // errorCallback in each case. if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); } }; @@ -504,7 +630,11 @@ FileHandle.prototype.closeNonBlocking = function() { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); if (!(this.state === 'opened')) { - throw new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened'); + setTimeout(function() { + native_.callIfPossible( + args.errorCallback, + new WebAPIException(WebAPIException.IO_ERR, 'FileHandle is not opened')); + }, 0); } var data = {id: this.id, blocking: false}; @@ -518,7 +648,12 @@ FileHandle.prototype.closeNonBlocking = function() { var result = native_.call('FileHandle_close', data, callback); this.state = 'closed'; + + // Only IOError is possible to be returned synchronously, so it is passed to + // errorCallback in each case. if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + setTimeout(function() { + native_.callIfPossible(args.errorCallback, err); + }, 0); } }; diff --git a/src/filesystem/js/file_system_manager.js b/src/filesystem/js/file_system_manager.js index 59fce18..8aac6ba 100644 --- a/src/filesystem/js/file_system_manager.js +++ b/src/filesystem/js/file_system_manager.js @@ -384,7 +384,7 @@ FileSystemManager.prototype.listDirectory = function() { } if (args.filter.hasOwnProperty('startModified')) { - throwIfNotDate(args.filter.endModified, 'endModified'); + throwIfNotDate(args.filter.startModified, 'startModified'); args.filter.startModified = args.filter.startModified.getTime() / 1000; } if (args.filter.hasOwnProperty('endModified')) { @@ -392,11 +392,11 @@ FileSystemManager.prototype.listDirectory = function() { args.filter.endModified = args.filter.endModified.getTime() / 1000; } if (args.filter.hasOwnProperty('startCreated')) { - throwIfNotDate(args.filter.endModified, 'endModified'); + throwIfNotDate(args.filter.startCreated, 'startCreated'); args.filter.startCreated = args.filter.startCreated.getTime() / 1000; } if (args.filter.hasOwnProperty('endCreated')) { - throwIfNotDate(args.filter.endModified, 'endModified'); + throwIfNotDate(args.filter.endCreated, 'endCreated'); args.filter.endCreated = args.filter.endCreated.getTime() / 1000; } @@ -411,7 +411,8 @@ FileSystemManager.prototype.listDirectory = function() { if (native_.isFailure(result)) { native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); } else { - var names = native_.getResultObject(result); + var obj = native_.getResultObject(result); + var names = obj.names; if (args.filter.hasOwnProperty('name')) { var regex_name = stringToRegex(args.filter.name); for (var i = names.length - 1; i >= 0; i--) { @@ -420,7 +421,8 @@ FileSystemManager.prototype.listDirectory = function() { } } } - native_.callIfPossible(args.successCallback, names); + native_.callIfPossible( + args.successCallback, names, commonFS_.toVirtualPath(obj.path)); } }; @@ -507,7 +509,7 @@ FileSystemManager.prototype.getDirName = function() { var args = validator_.validateArgs(arguments, [{name: 'path', type: types_.STRING}]); var path = args.path; - path = mergeMultipleSlashes(path); + path = commonFS_.mergeMultipleSlashes(path); if (path.startsWith('file://')) { path = path.substring('file://'.length - 1, path.length - 1); } -- 2.7.4 From 1b61dd93d0433a818ccfccba9298d820b5c7449b Mon Sep 17 00:00:00 2001 From: Szymon Jastrzebski Date: Mon, 13 Aug 2018 14:22:57 +0200 Subject: [PATCH 11/16] [Filesystem] Fix for readString methods + The readString methods reported string till the first null character. This is wrong, because files may contain 0x00 bytes. + The returned string contains exactly at most 'count' characters. The returned string does not contain additional null characters. [ACR] http://suprem.sec.samsung.net/jira/browse/TWDAPI-121 [Verification] TCT 100% Code works well with below snippet: var fileHandleWrite = tizen.filesystem.openFile("documents/filet", "w"); fileHandleWrite.writeString("Lorem ipsum\x00\x00dolor sit amet..."); var fileHandleRead = tizen.filesystem.openFile("documents/filet", "r"); var fileContents = fileHandleRead.readString(); The 'fileContents is equal to: "Lorem ipsum"\x00\x00"dolor sit amet..." Change-Id: Id56c365e701c4ba88bdeeb7a4851669250f332b4 Signed-off-by: Szymon Jastrzebski --- src/filesystem/filesystem_instance.cc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 112f7e5..0837d5e 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -383,7 +383,8 @@ static std::size_t file_bytes_to_eof(FILE* file) { return total_fize_size - static_cast(file_position); } -static std::vector read_file(FILE* file, std::size_t length = NPOS); +static std::vector read_file(FILE* file, std::size_t length = NPOS, + std::size_t* read_bytes = nullptr); /** * Returns a buffer. If length is NPOS, then it reads whole file, up to the end. @@ -422,7 +423,8 @@ static std::vector read_file(std::string path, long offset = 0, * Returns a buffer. If length is NPOS, then it reads whole file, up to the end. * On failure throws std::runtime_error */ -static std::vector read_file(FILE* file, std::size_t length /*= NPOS*/) { +static std::vector read_file(FILE* file, std::size_t length /*= NPOS*/, + std::size_t* read_bytes /* = nullptr*/) { ScopeLogger(); // By default reads whole file. Get the file size. @@ -451,6 +453,14 @@ static std::vector read_file(FILE* file, std::size_t length /*= NP break; } } + // read_file function is used in API since version 1.0. + // read_bytes was added in Tizen 5.0, with default value equal to nullptr, the behaviour is not + // changed. + // It is used to return the actual number of read bytes, because requested length might be bigger + // than possible bytes to be read. + if (nullptr != read_bytes) { + *read_bytes = std::distance(out_buf.data(), data_p); + } return out_buf; } @@ -1981,7 +1991,9 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj auto logic = [handle, count, encoding, whole_file](decltype(out) out) { try { - std::vector buf = read_file(handle->file_handle, count); + size_t read_bytes = 0; + std::vector buf = read_file(handle->file_handle, count, &read_bytes); + buf.resize(read_bytes); // this protects from reporting too big arrays to JS if (encoding == kISOEncoding) { // for iso-8859-1 1 byte is equal to 1 character out["result"] = picojson::value(picojson::string_type, true); latin1::to_utf8(buf, out["result"].get()); @@ -2006,9 +2018,8 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj IOException("File doesn't contain UTF-8 encoded string with given length"), out); } } - buf.push_back('\0'); const char* str = (const char*)buf.data(); - ReportSuccess(picojson::value{str}, out); + ReportSuccess(picojson::value{str, buf.size()}, out); } } catch (std::runtime_error& e) { LoggerE("Cannot read, cause: %s", e.what()); -- 2.7.4 From 9a312f8db865b205dd4a8c5377486921604c198d Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Thu, 16 Aug 2018 10:42:15 +0200 Subject: [PATCH 12/16] [version] 2.25 Change-Id: If58254886f7fa6188e597e4d20dcb30f0ef60234 Signed-off-by: Piotr Kosko --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 70ab9fb..f9c4b20 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 2.24 +Version: 2.25 Release: 0 License: Apache-2.0 and BSD-3-Clause and MIT Group: Development/Libraries -- 2.7.4 From 275c3efc9c7b31007f4dd81baa9a258ca642eb75 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarczyk Date: Fri, 10 Aug 2018 12:37:47 +0200 Subject: [PATCH 13/16] [Filesystem] Add missing deprecation warnings since Tizen 5.0 [Verification] tct-filesystem-tizen-tests: 100% Change-Id: I8f0c2b888d1965a3ca633e1f56d77d88c4505ab1 Signed-off-by: Pawel Kaczmarczyk --- src/filesystem/filesystem_instance.cc | 49 ++++++++++++++++++++++++++++++++ src/filesystem/js/file.js | 35 ++++++++++++++++++++++- src/filesystem/js/file_stream.js | 23 +++++++++++++++ src/filesystem/js/file_system_manager.js | 3 ++ 4 files changed, 109 insertions(+), 1 deletion(-) diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 52f5948..7487ed2 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -247,6 +247,10 @@ FilesystemInstance::~FilesystemInstance() { void FilesystemInstance::FileCreateSync(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.createFile() is deprecated since Tizen 5.0. Use " + "FileSystemManager.openFile() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) const std::string& location = args.get("location").get(); @@ -267,6 +271,10 @@ void FilesystemInstance::FileCreateSync(const picojson::value& args, picojson::o void FilesystemInstance::FileRename(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.moveTo() is deprecated since Tizen 5.0. Use " + "FileSystemManager.moveFile() or FileSystemManager.moveDirectory() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "callbackId", out) @@ -703,6 +711,10 @@ static std::vector decode(const char* str, std::size_t len) { void FilesystemInstance::FileReadString(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: This method is deprecated since Tizen 5.0.Use FileHandle.readString() " + "or FileHandle.readStringNonBlocking() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "offset", out) @@ -733,6 +745,10 @@ void FilesystemInstance::FileReadString(const picojson::value& args, picojson::o void FilesystemInstance::FileReadBytes(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: This method is deprecated since Tizen 5.0. Use FileHandle.readData() " + "or FileHandle.readDataNonBlocking() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "offset", out) @@ -756,6 +772,10 @@ void FilesystemInstance::FileReadBytes(const picojson::value& args, picojson::ob void FilesystemInstance::FileWriteString(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: FileStream.write() is deprecated since Tizen 5.0. Use " + "FileHandle.writeString() or FileHandle.writeStringNonBlocking() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "data", out) @@ -791,6 +811,10 @@ void FilesystemInstance::FileWriteString(const picojson::value& args, picojson:: void FilesystemInstance::FileWriteBytes(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: FileStream.writeBytes() is deprecated since Tizen 5.0. To read and Use " + "FileHandle.writeData() or FileHandle.writeDataNonBlocking() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "data", out) @@ -818,6 +842,11 @@ void FilesystemInstance::FileWriteBytes(const picojson::value& args, picojson::o void FilesystemInstance::FileWriteBase64(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: FileStream.writeBase64() is deprecated since Tizen 5.0. Use " + "FileHandle.writeData() or FileHandle.writeDataNonBlocking() in combination with atob() and " + "btoa() functions instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "data", out) @@ -1011,6 +1040,10 @@ void FilesystemInstance::FileSystemManagerMakeDirectory(const picojson::value& a void FilesystemInstance::FileSystemManagerMakeDirectorySync(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.createDirectory() is deprecated since Tizen 5.0. Use " + "FileSystemManager.createDirectory() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) const std::string& location = args.get("location").get(); @@ -1029,6 +1062,10 @@ void FilesystemInstance::FileSystemManagerMakeDirectorySync(const picojson::valu void FilesystemInstance::ReadDir(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.listFiles() is deprecated since Tizen 5.0. Use " + "FileSystemManager.listDirectory() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "pathToDir", out) CHECK_EXIST(args, "callbackId", out) @@ -1068,6 +1105,10 @@ void FilesystemInstance::ReadDir(const picojson::value& args, picojson::object& void FilesystemInstance::UnlinkFile(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.deleteFile() is deprecated since Tizen 5.0. Use " + "FileSystemManager.deleteFile() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "pathToFile", out) double callback_id = args.get("callbackId").get(); @@ -1100,6 +1141,10 @@ void FilesystemInstance::UnlinkFile(const picojson::value& args, picojson::objec void FilesystemInstance::RemoveDirectory(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.deleteDirectory() is deprecated since Tizen 5.0. Use " + "FileSystemManager.deleteDirectory() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "pathToDelete", out) double callback_id = args.get("callbackId").get(); @@ -1132,6 +1177,10 @@ void FilesystemInstance::RemoveDirectory(const picojson::value& args, picojson:: void FilesystemInstance::CopyTo(const picojson::value& args, picojson::object& out) { ScopeLogger(); + LoggerW( + "DEPRECATION WARNING: File.copyTo() is deprecated since Tizen 5.0. Use " + "FileSystemManager.CopyFile() or FileSystemManager.CopyDirectory() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "callbackId", out) diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index d5d2d20..990e428 100644 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + function File(data) { function fileSizeGetter() { var _realPath = commonFS_.toRealPath(this.fullPath); @@ -60,6 +60,9 @@ function File(data) { } function toURI() { + privUtils_.warn("DEPRECATION WARNING: File.toURI() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.toURI() instead."); + xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ); return 'file://' + commonFS_.toRealPath(this.fullPath); } @@ -162,6 +165,9 @@ function checkFile(file, fileFilter) { } function listFiles() { + privUtils_.warn("DEPRECATION WARNING: File.listFiles() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.listDirectory() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}, @@ -243,6 +249,9 @@ function _checkEncoding(encoding) { } function openStream() { + privUtils_.warn("DEPRECATION WARNING: File.openStream() is deprecated since Tizen 5.0. " + + "Use FileHandle interface to read/write operations instead."); + var args = validator_.validateArgs(arguments, [ {name: 'mode', type: types_.ENUM, values: ['r', 'rw', 'w', 'a']}, {name: 'onsuccess', type: types_.FUNCTION}, @@ -294,6 +303,9 @@ File.prototype.openStream = function() { }; function readAsText() { + privUtils_.warn("DEPRECATION WARNING: File.readAsText() is deprecated since Tizen 5.0. " + + "Use FileHandle.readString() or FileHandle.readStringNonBlocking() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}, @@ -346,6 +358,9 @@ File.prototype.readAsText = function() { }; function copyTo() { + privUtils_.warn("DEPRECATION WARNING: File.copyTo() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.CopyFile() or FileSystemManager.CopyDirectory() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'originFilePath', type: types_.STRING}, {name: 'destinationFilePath', type: types_.STRING}, @@ -499,6 +514,9 @@ File.prototype.copyTo = function() { }; function moveTo() { + privUtils_.warn("DEPRECATION WARNING: File.moveTo() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.moveFile() or FileSystemManager.moveDirectory() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'originFilePath', type: types_.STRING}, {name: 'destinationFilePath', type: types_.STRING}, @@ -615,6 +633,9 @@ File.prototype.moveTo = function() { }; function createDirectory() { + privUtils_.warn("DEPRECATION WARNING: File.createDirectory() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.createDirectory() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'dirPath', type: types_.STRING} ]); @@ -679,6 +700,9 @@ File.prototype.createDirectory = function() { } function createFile() { + privUtils_.warn("DEPRECATION WARNING: File.createFile() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.createFile() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'relativeFilePath', type: types_.STRING} ]); @@ -735,6 +759,9 @@ File.prototype.createFile = function() { }; function resolveFile() { + privUtils_.warn("DEPRECATION WARNING: File.resolve() is deprecated since Tizen 5.0. " + + "Use FileHandle and FileSystemManager interfaces instead."); + var args = validator_.validateArgs(arguments, [ {name: 'filePath', type: types_.STRING} ]); @@ -783,6 +810,9 @@ File.prototype.resolve = function() { }; function deleteDirectory() { + privUtils_.warn("DEPRECATION WARNING: File.deleteDirectory() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.deleteDirectory() instead." ); + var args = validator_.validateArgs(arguments, [ {name: 'directoryPath', type: types_.STRING}, {name: 'recursive', type: types_.BOOLEAN}, @@ -883,6 +913,9 @@ File.prototype.deleteDirectory = function() { }; function deleteFile() { + privUtils_.warn("DEPRECATION WARNING: File.deleteFile() is deprecated since Tizen 5.0. " + + "Use FileSystemManager.deleteFile() instead."); + var args = validator_.validateArgs(arguments, [ {name: 'filePath', type: types_.STRING}, {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true}, diff --git a/src/filesystem/js/file_stream.js b/src/filesystem/js/file_stream.js index 9d391bb..89eed34 100644 --- a/src/filesystem/js/file_stream.js +++ b/src/filesystem/js/file_stream.js @@ -66,6 +66,9 @@ function _checkClosed(stream) { } function closeFileStream() { + privUtils_.warn("DEPRECATION WARNING: FileStream.close() is deprecated since Tizen 5.0. " + + "Use FileHandle.close() instead."); + this._closed = true; } @@ -86,6 +89,9 @@ function _checkWriteAccess(mode) { } function read() { + privUtils_.warn("DEPRECATION WARNING: FileStream.read() is deprecated since Tizen 5.0. " + + "Use FileHandle.readString() or FileHandle.readStringNonBlocking() instead."); + var args = validator_.validateArgs(arguments, [{name: 'charCount', type: types_.LONG}]); _checkClosed(this); @@ -177,10 +183,17 @@ function readBytes() { } FileStream.prototype.readBytes = function() { + privUtils_.warn("DEPRECATION WARNING: FileStream.readBytes() is deprecated since Tizen 5.0. " + + "Use FileHandle.readData() or FileHandle.readDataNonBlocking() instead."); + return readBytes.apply(this, arguments); }; FileStream.prototype.readBase64 = function() { + privUtils_.warn("DEPRECATION WARNING: FileStream.readBase64() is deprecated since Tizen 5.0. " + + "Use FileHandle.readData() or FileHandle.readDataNonBlocking() in combination " + + "with atob() and btoa() functions instead."); + return base64_encode(readBytes.apply(this, arguments)); }; @@ -196,6 +209,9 @@ function check_characters_outside_latin1(str) { } function write() { + privUtils_.warn("DEPRECATION WARNING: FileStream.write() is deprecated since Tizen 5.0. " + + "Use FileHandle.writeString() or FileHandle.writeStringNonBlocking() instead."); + var args = validator_.validateArgs(arguments, [{name: 'stringData', type: types_.STRING}]); @@ -235,6 +251,9 @@ FileStream.prototype.write = function() { }; function writeBytes() { + privUtils_.warn("DEPRECATION WARNING: FileStream.writeBytes() is deprecated since Tizen 5.0. " + + "Use FileHandle.writeData() or FileHandle.writeDataNonBlocking() instead."); + var args = validator_.validateArgs( arguments, [{ name: 'byteData', @@ -274,6 +293,10 @@ FileStream.prototype.writeBytes = function() { }; function writeBase64() { + privUtils_.warn("DEPRECATION WARNING: FileStream.writeBase64() is deprecated since Tizen 5.0. " + + "Use FileHandle.writeData() or FileHandle.writeDataNonBlocking() in combination " + + "with atob() and btoa() functions instead."); + var args = validator_.validateArgs(arguments, [{name: 'base64Data', type: types_.STRING}]); diff --git a/src/filesystem/js/file_system_manager.js b/src/filesystem/js/file_system_manager.js index 59fce18..cddcceb 100644 --- a/src/filesystem/js/file_system_manager.js +++ b/src/filesystem/js/file_system_manager.js @@ -527,6 +527,9 @@ FileSystemManager.prototype.getDirName = function() { }; function resolve() { + privUtils_.warn("DEPRECATION WARNING: FileSystemManager.resolve() is deprecated since Tizen 5.0. " + + "Use FileHandle and FileSystemManager interfaces instead."); + var args = validator_.validateArgs(arguments, [ {name: 'location', type: types_.STRING}, {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}, { -- 2.7.4 From 9723c352c361a48a500a2cfb4283890863a2296d Mon Sep 17 00:00:00 2001 From: Szymon Jastrzebski Date: Sun, 19 Aug 2018 08:18:52 +0200 Subject: [PATCH 14/16] [Common] Added checking types of arguments passed to the logging macros + The type check is made only in debug build. + Added WEBAPI_NOOP macro, used in the release builds. [Verification] The code builds for debug&release builds. Change-Id: Ie192f02b40a204dc97e713c0b2e280cd612efc77 Signed-off-by: Szymon Jastrzebski --- src/common/logger.h | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/common/logger.h b/src/common/logger.h index b59a318..228c871 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -7,12 +7,31 @@ #include +#ifdef TIZEN_DEBUG_ENABLE // Using static inline function with no operation inside to cause compiler types check. -// Using empty do {} while in WEBAPI_NOP macro will cause that when TIZEN_DEBUG_ENABLE flag -// is turned off, then no types checking will be performed. This could cause problems when -// developing code with this flag off and then enabling it. -static inline int _noop_print(const char *fmt __attribute__((unused)), ...) { return 0; } -#define WEBAPI_NOP(...) ({ do { _noop_print(__VA_ARGS__); } while (0); }) +// Using empty do {} while in WEBAPI_CHECK_PRINTF_FORMAT_ARGS macro will cause that when +// TIZEN_DEBUG_ENABLE flag is turned off, then no types checking will be performed. This could cause +// problems when developing code with this flag off and then enabling it. +static inline int _printf_format_checker(const char* fmt, ...) + __attribute__((format(printf, 1, 2))); + +int _printf_format_checker(const char* fmt, ...) { + return 0; +} + +#define WEBAPI_CHECK_PRINTF_FORMAT_ARGS(...) \ + ({ \ + do { \ + _printf_format_checker(__VA_ARGS__); \ + } while (0); \ + }) + +#else // TIZEN_DEBUG_ENABLE + +#define WEBAPI_NOOP() \ + do { \ + } while (0); +#endif // TIZEN_DEBUG_ENABLE // Tizen 3.0 uses different debug flag (DLOG_DEBUG_ENABLE) which is always // enabled, following code allows to disable logs with DLOG_DEBUG priority if @@ -24,6 +43,7 @@ static inline int _noop_print(const char *fmt __attribute__((unused)), ...) { re #define LOG_(id, prio, tag, fmt, arg...) \ ({ \ do { \ + WEBAPI_CHECK_PRINTF_FORMAT_ARGS(fmt, ##arg); \ __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \ } while (0); \ }) @@ -43,12 +63,13 @@ static inline int _noop_print(const char *fmt __attribute__((unused)), ...) { re #define SECURE_LOG_(id, prio, tag, fmt, arg...) \ ({ \ do { \ + WEBAPI_CHECK_PRINTF_FORMAT_ARGS(fmt, ##arg); \ __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, \ __LINE__, ##arg); \ } while (0); \ }) #else // TIZEN_DEBUG_ENABLE -#define SECURE_LOG_(id, prio, tag, fmt, arg...) WEBAPI_NOP(fmt, ##arg) +#define SECURE_LOG_(id, prio, tag, fmt, arg...) WEBAPI_NOOP() #endif // TIZEN_DEBUG_ENABLE #include @@ -254,13 +275,14 @@ class ScopeLogger { #ifdef TIZEN_DEBUG_ENABLE #define ScopeLogger(EX, args...) \ + WEBAPI_CHECK_PRINTF_FORMAT_ARGS("noop" EX, ##args); \ __dlog_print(LOG_ID_MAIN, DLOG_DEBUG, LOGGER_TAG, \ "logger.h: ScopeLogger > %s: %s(%d) > Enter " EX, __MODULE__, __func__, __LINE__, \ ##args); \ const common::ScopeLogger __sl__{__MODULE__, __func__}; #else -#define ScopeLogger(EX, args...) +#define ScopeLogger(EX, args...) WEBAPI_NOOP() #endif #endif // COMMON_LOGGER_H_ -- 2.7.4 From be0339e6522c2bbf276f81e2ee7d183081058a58 Mon Sep 17 00:00:00 2001 From: Szymon Jastrzebski Date: Mon, 20 Aug 2018 11:29:33 +0200 Subject: [PATCH 15/16] [Common] Fixing printf format modifiers + The following commit fixes error build for aarch. + C++ source code was formatted in whole project. + Added -Wformat-signedness flag to check the signedness of arguments passed to the logging macros. [Verification] Code compiles for 32&64 bit archs Change-Id: I106afb31132babb50c3a4b64dd510d627c5c10fe Signed-off-by: Szymon Jastrzebski --- src/alarm/alarm_manager.cc | 8 +- src/archive/archive_file.cc | 6 +- src/archive/archive_instance.cc | 2 +- src/archive/filesystem_node.cc | 2 +- src/archive/un_zip.cc | 2 +- src/archive/un_zip_extract_request.cc | 2 +- src/archive/zip_add_request.cc | 8 +- src/badge/badge_manager.cc | 4 +- src/calendar/calendar_item.cc | 4 +- src/callhistory/callhistory.cc | 2 +- src/common/common.gypi | 1 + src/contact/contact_util.cc | 6 +- src/exif/exif_information.cc | 6 +- src/exif/exif_instance.cc | 2 +- src/exif/exif_tag_saver.cc | 2 +- src/exif/get_exif_info.cc | 10 +- src/exif/jpeg_file.cc | 107 +++++++++++---------- src/filesystem/filesystem_instance.cc | 4 +- .../humanactivitymonitor_manager.cc | 4 +- src/messaging/MsgCommon/AttributeRangeFilter.h | 1 - src/messaging/conversations_change_callback.cc | 14 +-- src/messaging/email_manager.cc | 10 +- src/messaging/folders_change_callback.cc | 12 +-- src/messaging/message.cc | 29 +++--- src/messaging/messages_change_callback.cc | 16 +-- src/messaging/short_message_manager.cc | 36 +++---- src/nfc/nfc_adapter.cc | 8 +- src/nfc/nfc_util.cc | 4 +- src/package/package_instance.cc | 2 +- src/sound/sound_manager.cc | 2 +- src/systeminfo/systeminfo_properties_manager.cc | 2 +- src/widgetservice/widgetservice_instance.cc | 7 +- 32 files changed, 165 insertions(+), 160 deletions(-) diff --git a/src/alarm/alarm_manager.cc b/src/alarm/alarm_manager.cc index 7a27dfc..bcc74e0 100644 --- a/src/alarm/alarm_manager.cc +++ b/src/alarm/alarm_manager.cc @@ -143,7 +143,8 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) { } std::string delay_str = std::to_string(delay); - int ret_app = app_control_add_extra_data(app_control, kAlarmRelativeDelayKey, delay_str.c_str()); + int ret_app = + app_control_add_extra_data(app_control, kAlarmRelativeDelayKey, delay_str.c_str()); if (APP_CONTROL_ERROR_NONE != ret_app) { LogAndReportError( PlatformResult(ErrorCode::UNKNOWN_ERR, "Fail to add data from app_control."), &out, @@ -631,8 +632,9 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) { int ret_app = app_control_get_extra_data(app_control, kAlarmRelativeDelayKey, &delay_string); if (APP_CONTROL_ERROR_NONE != ret_app) { - return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Failed to get data.", - ("Failed to get data: %d (%s)", ret_app, get_error_message(ret_app))); + return LogAndCreateResult( + ErrorCode::NOT_FOUND_ERR, "Failed to get data.", + ("Failed to get data: %d (%s)", ret_app, get_error_message(ret_app))); } obj.insert(std::make_pair("type", picojson::value(kAlarmRelative))); diff --git a/src/archive/archive_file.cc b/src/archive/archive_file.cc index 0f91199..94ec9db 100644 --- a/src/archive/archive_file.cc +++ b/src/archive/archive_file.cc @@ -76,7 +76,7 @@ ArchiveFile::~ArchiveFile() { ScopeLogger(); if (m_entry_map) { - LoggerD("Unlinking old m_entry_map: %d ArchiveFileEntries", m_entry_map->size()); + LoggerD("Unlinking old m_entry_map: %zu ArchiveFileEntries", m_entry_map->size()); for (auto it = m_entry_map->begin(); it != m_entry_map->end(); ++it) { if (it->second) { it->second->setArchiveFileNonProtectPtr(NULL); @@ -537,7 +537,7 @@ void ArchiveFile::setEntryMap(ArchiveFileEntryPtrMapPtr entries) { ScopeLogger(); if (m_entry_map) { - LoggerD("Unlinking old m_entry_map: %d ArchiveFileEntries", m_entry_map->size()); + LoggerD("Unlinking old m_entry_map: %zu ArchiveFileEntries", m_entry_map->size()); for (auto it = m_entry_map->begin(); it != m_entry_map->end(); ++it) { if (it->second) { it->second->setArchiveFileNonProtectPtr(NULL); @@ -547,7 +547,7 @@ void ArchiveFile::setEntryMap(ArchiveFileEntryPtrMapPtr entries) { m_entry_map = entries; - LoggerD("Linking new m_entry_map ArchiveFileEntries (%d) with ArchiveFile object", + LoggerD("Linking new m_entry_map ArchiveFileEntries (%zu) with ArchiveFile object", m_entry_map->size()); for (auto it = m_entry_map->begin(); it != m_entry_map->end(); ++it) { if (it->second) { diff --git a/src/archive/archive_instance.cc b/src/archive/archive_instance.cc index cb28a2b..cf7f9c8 100644 --- a/src/archive/archive_instance.cc +++ b/src/archive/archive_instance.cc @@ -147,7 +147,7 @@ void ArchiveInstance::Open(const picojson::value& args, picojson::object& out) { } file_ptr = FilePtr(new File(node, File::PermissionList())); - LoggerD("open: %s mode: 0x%x overwrite: %d", location_full_path.c_str(), fm, overwrite); + LoggerD("open: %s mode: 0x%d overwrite: %d", location_full_path.c_str(), fm, overwrite); if (FileMode::WRITE == fm || FileMode::READ_WRITE == fm) { if (overwrite) { LoggerD("Deleting existing file: %s", location_full_path.c_str()); diff --git a/src/archive/filesystem_node.cc b/src/archive/filesystem_node.cc index 13d23f7..9ba9400 100644 --- a/src/archive/filesystem_node.cc +++ b/src/archive/filesystem_node.cc @@ -147,7 +147,7 @@ PlatformResult Node::resolve(const PathPtr& path, NodePtr* node) { } type = S_ISDIR(syminfo.st_mode) ? NT_DIRECTORY : NT_FILE; - LoggerD("%x", type); + LoggerD("%d", type); } *node = std::shared_ptr(new Node(path, type)); diff --git a/src/archive/un_zip.cc b/src/archive/un_zip.cc index 9689622..b381bdd 100644 --- a/src/archive/un_zip.cc +++ b/src/archive/un_zip.cc @@ -51,7 +51,7 @@ UnZip::UnZip(const std::string& filename) UnZip::~UnZip() { ScopeLogger(); for (auto& x : path_access_map) { - LoggerD("Setting permission for path: %s [%d] ", x.first.c_str(), x.second); + LoggerD("Setting permission for path: %s [%u] ", x.first.c_str(), x.second); if (chmod(x.first.c_str(), x.second) == -1) { LoggerE("Couldn't set permissions for: [%s] errno: %s", x.first.c_str(), GetErrorString(errno).c_str()); diff --git a/src/archive/un_zip_extract_request.cc b/src/archive/un_zip_extract_request.cc index 3cb0956..1fdd490 100644 --- a/src/archive/un_zip_extract_request.cc +++ b/src/archive/un_zip_extract_request.cc @@ -297,7 +297,7 @@ PlatformResult UnZipExtractRequest::handleDirectoryEntry() { } } - LoggerD("Set dir: [%s] access and modify to: %4d-%2d-%2d %2d:%2d:%2d", m_new_dir_path.c_str(), + LoggerD("Set dir: [%s] access and modify to: %4u-%2u-%2u %2u:%2u:%2u", m_new_dir_path.c_str(), m_file_info.tmu_date.tm_year, m_file_info.tmu_date.tm_mon, m_file_info.tmu_date.tm_mday, m_file_info.tmu_date.tm_hour, m_file_info.tmu_date.tm_min, m_file_info.tmu_date.tm_sec); diff --git a/src/archive/zip_add_request.cc b/src/archive/zip_add_request.cc index 526867f..46cd84d 100644 --- a/src/archive/zip_add_request.cc +++ b/src/archive/zip_add_request.cc @@ -361,7 +361,7 @@ PlatformResult ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node) fseek(m_input_file, 0, SEEK_END); const size_t in_file_size = ftell(m_input_file); fseek(m_input_file, 0, SEEK_SET); - LoggerD("Source file: [%s] size: %d - %s", src_file_path.c_str(), in_file_size, + LoggerD("Source file: [%s] size: %zu - %s", src_file_path.c_str(), in_file_size, bytesToReadableString(in_file_size).c_str()); cur_afentry->setSize(in_file_size); @@ -383,7 +383,7 @@ PlatformResult ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node) return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "New file addition failed"); } - LoggerD("Read: %d bytes from input file:[%s]", size_read, src_file_path.c_str()); + LoggerD("Read: %zu bytes from input file:[%s]", size_read, src_file_path.c_str()); total_bytes_read += size_read; m_bytes_compressed += size_read; @@ -402,7 +402,7 @@ PlatformResult ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node) LoggerD( "Callculatting overall progress: %llu/%llu bytes; " - "%lu/%lu files; current file: [%s] progress: %d/%d bytes; ", + "%lu/%lu files; current file: [%s] progress: %zu/%zu bytes; ", m_bytes_compressed, m_bytes_to_compress, m_files_compressed, m_files_to_compress, src_file_path.c_str(), total_bytes_read, in_file_size); @@ -423,7 +423,7 @@ PlatformResult ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node) if (in_file_size != total_bytes_read) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not add file to archive", - ("in_file_size(%d) != total_bytes_read(%d)", in_file_size, total_bytes_read)); + ("in_file_size(%zu) != total_bytes_read(%zu)", in_file_size, total_bytes_read)); } fclose(m_input_file); diff --git a/src/badge/badge_manager.cc b/src/badge/badge_manager.cc index fab178e..b41f9cc 100644 --- a/src/badge/badge_manager.cc +++ b/src/badge/badge_manager.cc @@ -88,7 +88,7 @@ PlatformResult BadgeManager::SetBadgeCount(const std::string &app_id, unsigned i } ret = badge_set_count(app_id_str, count); - LoggerD("badge_set_count() ret : %d, %s, count : %d ", ret, get_error_message(ret), count); + LoggerD("badge_set_count() ret : %d, %s, count : %u ", ret, get_error_message(ret), count); if (ret == BADGE_ERROR_PERMISSION_DENIED) { return LogAndCreateResult(ErrorCode::SECURITY_ERR, "Security error"); @@ -136,7 +136,7 @@ PlatformResult BadgeManager::GetBadgeCount(const std::string &app_id, unsigned i ret = badge_get_count(app_id.c_str(), count); - LoggerD("badge_get_count() ret : %d count : %d", ret, *count); + LoggerD("badge_get_count() ret : %d count : %u", ret, *count); switch (ret) { case BADGE_ERROR_NONE: diff --git a/src/calendar/calendar_item.cc b/src/calendar/calendar_item.cc index fe6e59b..b3bc59d 100644 --- a/src/calendar/calendar_item.cc +++ b/src/calendar/calendar_item.cc @@ -829,7 +829,7 @@ PlatformResult CalendarItem::AttendeesToJson(int type, calendar_record_h rec, calendar_record_h attendee; for (unsigned int i = 0; i < count; ++i) { - LoggerD("Processing the attendee %d", i); + LoggerD("Processing the attendee %u", i); if (GetChildRecordAt(rec, property, &attendee, i).IsError()) { LoggerW("Can't get attendee record"); @@ -1049,7 +1049,7 @@ PlatformResult CalendarItem::AlarmsToJson(int type, calendar_record_h rec, picoj int tick, tick_unit; calendar_record_h alarm; for (unsigned int i = 0; i < count; ++i) { - LoggerD("Processing the alarm %d", i); + LoggerD("Processing the alarm %u", i); if (GetChildRecordAt(rec, property, &alarm, i).IsError()) { LoggerW("Can't get alarm record"); diff --git a/src/callhistory/callhistory.cc b/src/callhistory/callhistory.cc index 1108c80..2f972a7 100644 --- a/src/callhistory/callhistory.cc +++ b/src/callhistory/callhistory.cc @@ -291,7 +291,7 @@ void CallHistory::LoadPhoneNumbers(const picojson::object& args, CallHistory* ca LoggerD("wait..."); fut.wait(); n = fut.get(); - LoggerD("Phone number [%d] : %s", modem_num, n.c_str()); + LoggerD("Phone number [%u] : %s", modem_num, n.c_str()); } while (false); phone_numbers.push_back(n); diff --git a/src/common/common.gypi b/src/common/common.gypi index cf4fed8..4609a66 100644 --- a/src/common/common.gypi +++ b/src/common/common.gypi @@ -82,6 +82,7 @@ '-fvisibility=hidden', '-Wall', '-Werror', + '-Wformat-signedness', ], 'cflags_c': [ '-std=c11', diff --git a/src/contact/contact_util.cc b/src/contact/contact_util.cc index fb32ede..f107843 100644 --- a/src/contact/contact_util.cc +++ b/src/contact/contact_util.cc @@ -1731,7 +1731,7 @@ PlatformResult ImportContactInstantMessengerFromContactsRecord(contacts_record_h int err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.messenger, index, &child_record); if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) { - LoggerW("Skipping message with index %i. error code: %i", index, err); + LoggerW("Skipping message with index %u. error code: %i", index, err); return PlatformResult(ErrorCode::NO_ERROR); } @@ -1744,7 +1744,7 @@ PlatformResult ImportContactInstantMessengerFromContactsRecord(contacts_record_h } if (!im_address) { - LoggerW("Skipping message with index %i. missing im address", index); + LoggerW("Skipping message with index %u. missing im address", index); return PlatformResult(ErrorCode::NO_ERROR); } @@ -2201,7 +2201,7 @@ PlatformResult ImportGroupIdsFromContactsRecord(contacts_record_h contacts_recor index, &record); if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) { // ignoring this record - LoggerW("Skipping record with index %i. error code: %i", index, err); + LoggerW("Skipping record with index %u. error code: %i", index, err); return PlatformResult(ErrorCode::NO_ERROR); } diff --git a/src/exif/exif_information.cc b/src/exif/exif_information.cc index 9a07286..6ed1bcc 100644 --- a/src/exif/exif_information.cc +++ b/src/exif/exif_information.cc @@ -333,7 +333,7 @@ void ExifInformation::setGpsProcessingMethod(const std::string& type, const std::string& processing_method) { if (type != EXIF_UNDEFINED_TYPE_ASCII && type != EXIF_UNDEFINED_TYPE_JIS && type != EXIF_UNDEFINED_TYPE_UNICODE && type != EXIF_UNDEFINED_TYPE_UNDEFINED) { - LoggerW("Trying to set invalid GPSProcessingMethod type: [%s] len:%d", type.c_str(), + LoggerW("Trying to set invalid GPSProcessingMethod type: [%s] len: %zu", type.c_str(), type.length()); return; } @@ -368,7 +368,7 @@ const std::string& ExifInformation::getUserCommentType() { void ExifInformation::setUserComment(const std::string& type, const std::string& user_comment) { if (type != EXIF_UNDEFINED_TYPE_ASCII && type != EXIF_UNDEFINED_TYPE_JIS && type != EXIF_UNDEFINED_TYPE_UNICODE && type != EXIF_UNDEFINED_TYPE_UNDEFINED) { - LoggerW("Trying to set invalid user comment type: [%s] len:%d", type.c_str(), type.length()); + LoggerW("Trying to set invalid user comment type: [%s] len: %zu", type.c_str(), type.length()); return; } @@ -689,7 +689,7 @@ PlatformResult ExifInformation::updateAttributesInExifData(ExifData* exif_data) } if (isSet(EXIF_INFORMATION_ATTRIBUTE_ISO_SPEED_RATINGS)) { std::vector iso_ratings = getIsoSpeedRatings(); - LoggerD("Saving iso speed ratings count:%d", iso_ratings.size()); + LoggerD("Saving iso speed ratings count: %zu", iso_ratings.size()); ret = ExifTagSaver::saveToExif(iso_ratings, EXIF_FORMAT_SHORT, EXIF_TAG_ISO_SPEED_RATINGS, exif_data); if (!ret) { diff --git a/src/exif/exif_instance.cc b/src/exif/exif_instance.cc index 0129d7c..c632916 100644 --- a/src/exif/exif_instance.cc +++ b/src/exif/exif_instance.cc @@ -23,11 +23,11 @@ #include #include +#include "common/filesystem/filesystem_provider.h" #include "common/logger.h" #include "common/platform_result.h" #include "common/task-queue.h" #include "common/tools.h" -#include "common/filesystem/filesystem_provider.h" #include "exif/exif_information.h" #include "exif/exif_util.h" diff --git a/src/exif/exif_tag_saver.cc b/src/exif/exif_tag_saver.cc index 0d91766..74b8092 100644 --- a/src/exif/exif_tag_saver.cc +++ b/src/exif/exif_tag_saver.cc @@ -31,7 +31,7 @@ void ExifTagSaver::removeExifEntryWithTag(const ExifTag tag, ExifData* exif_data ScopeLogger("tag: %d (%p)", tag, exif_data); ExifEntry* exif_entry = exif_data_get_entry(exif_data, tag); if (!exif_entry) { - LoggerE("Exif entry with tag: %d (0x%x) is not present", tag, tag); + LoggerE("Exif entry with tag: %d (0x%x) is not present", tag, (unsigned)tag); return; } diff --git a/src/exif/get_exif_info.cc b/src/exif/get_exif_info.cc index a5e4e81..4cd21c4 100644 --- a/src/exif/get_exif_info.cc +++ b/src/exif/get_exif_info.cc @@ -85,7 +85,7 @@ bool DecomposeExifUndefined(ExifEntry* entry, std::string& type, std::string& va } if (entry->size < EXIF_UNDEFINED_TYPE_LENGTH) { - LoggerW("entry size is invalid %d < EXIF_UNDEFINED_TYPE_LENGTH", entry->size); + LoggerW("entry size is invalid %u < EXIF_UNDEFINED_TYPE_LENGTH", entry->size); return false; } @@ -313,7 +313,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry, ExifData* exif_data, result_obj->insert(pair); LoggerD("Setting ExifInformation gps longitude REF to: WEST"); } else { - LoggerW("Unknown longitude ref: %c (0x%x)", ref, static_cast(ref)); + LoggerW("Unknown longitude ref: %c (0x%x)", ref, static_cast(ref)); } break; } @@ -357,7 +357,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry, ExifData* exif_data, result_obj->insert(pair); LoggerD("Setting ExifInformation gps latitude REF to: SOUTH"); } else { - LoggerW("Unknown latitude ref: %c (0x%x)", ref, static_cast(ref)); + LoggerW("Unknown latitude ref: %c (0x%x)", ref, static_cast(ref)); } break; } @@ -390,7 +390,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry, ExifData* exif_data, // UNDEFINED - Any std::string type, value; if (DecomposeExifUndefined(entry, type, value)) { - LoggerD("Extracted GPSProcessingMethod: [%s], len:%d, type:%s", value.c_str(), + LoggerD("Extracted GPSProcessingMethod: [%s], len: %zu, type: %s", value.c_str(), value.length(), type.c_str()); pair = std::make_pair("gpsProcessingMethod", JsonValue(value)); result_obj->insert(pair); @@ -425,7 +425,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry, ExifData* exif_data, // UNDEFINED - Any std::string type, value; if (DecomposeExifUndefined(entry, type, value)) { - LoggerD("Extracted UserComment: [%s], len:%d, type:%s", value.c_str(), value.length(), + LoggerD("Extracted UserComment: [%s], len: %zu, type: %s", value.c_str(), value.length(), type.c_str()); pair = std::make_pair("userComment", JsonValue(value)); diff --git a/src/exif/jpeg_file.cc b/src/exif/jpeg_file.cc index 6388e78..a5dced5 100644 --- a/src/exif/jpeg_file.cc +++ b/src/exif/jpeg_file.cc @@ -158,7 +158,7 @@ PlatformResult JpegFile::load(const std::string& path) { const std::size_t in_file_size = static_cast(ftell_val); fseek(m_in_file, 0, SEEK_SET); - LoggerD("JPEG file: [%s] size:%d", path.c_str(), in_file_size); + LoggerD("JPEG file: [%s] size: %zu", path.c_str(), in_file_size); if (0 == in_file_size) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid", ("Input file [%s] is empty!", path.c_str())); @@ -167,7 +167,7 @@ PlatformResult JpegFile::load(const std::string& path) { m_in_data = new (std::nothrow) unsigned char[in_file_size]; if (!m_in_data) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed", - ("Couldn't allocate buffer with size: %d", in_file_size)); + ("Couldn't allocate buffer with size: %zu", in_file_size)); } m_in_data_size = in_file_size; @@ -176,7 +176,7 @@ PlatformResult JpegFile::load(const std::string& path) { if (read_bytes != m_in_data_size) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not read JPEG file", - ("Couldn't read all: %d bytes. Read only: %u bytes!", m_in_data_size, read_bytes)); + ("Couldn't read all: %zu bytes. Read only: %zu bytes!", m_in_data_size, read_bytes)); } if (fclose(m_in_file) == EOF) { @@ -232,7 +232,7 @@ common::PlatformResult JpegFile::generateListOfSections() { m_padding_data_size = 0; for (size_t offset = 0, iterration = 0; offset < m_in_data_size; ++iterration) { - LoggerD("offset:%u | Starting iteration: %u", offset, iterration); + LoggerD("offset: %zu | Starting iteration: %zu", offset, iterration); const std::size_t search_len = 10; std::size_t search_offset = 0; for (search_offset = 0; search_offset < search_len; ++search_offset) { @@ -245,7 +245,7 @@ common::PlatformResult JpegFile::generateListOfSections() { if (search_len == search_offset) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid", - ("offset:%u | Couldn't find marker! RAW DATA:{%s}", offset, + ("offset: %zu | Couldn't find marker! RAW DATA:{%s}", offset, getPartOfFile(offset, 0, 10).c_str())); } @@ -253,16 +253,16 @@ common::PlatformResult JpegFile::generateListOfSections() { unsigned char* section_begin = m_in_data + section_offset; offset = section_offset; // Move to section begin - LoggerD("offset:%u | Moved to section begin", offset); + LoggerD("offset: %zu | Moved to section begin", offset); if (!isJpegMarker(section_begin[1])) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid", - ("offset:%u | Is not valid marker: 0x%x RAW DATA:{%s}", offset, + ("offset: %zu | Is not valid marker: 0x%x RAW DATA:{%s}", offset, section_begin[1], getPartOfFile(section_offset, 0, 4).c_str())); } const JpegMarker cur_marker = castToJpegMarker(section_begin[1]); - LoggerD("offset:%u | Found valid marker: 0x%x RAW DATA:{%s}", offset, cur_marker, + LoggerD("offset: %zu | Found valid marker: 0x%x RAW DATA:{%s}", offset, (unsigned)cur_marker, getPartOfFile(section_offset, 0, 4).c_str()); offset += 2; // Read 0xffxx marker tag - 2 bytes @@ -281,7 +281,7 @@ common::PlatformResult JpegFile::generateListOfSections() { section->type = cur_marker; m_sections.push_back(section); if (cur_marker == JPEG_MARKER_SOI || cur_marker == JPEG_MARKER_EOI) { - LoggerD("offset:%u | Found: %s marker, moving to next marker at:%u", section_offset, + LoggerD("offset: %zu | Found: %s marker, moving to next marker at: %zu", section_offset, ((cur_marker == JPEG_MARKER_SOI) ? "SOI" : "EOI"), offset); if (cur_marker == JPEG_MARKER_EOI && m_padding_data != NULL) { @@ -308,23 +308,23 @@ common::PlatformResult JpegFile::generateListOfSections() { // size 2 bytes const long section_data_len = total_section_len - 2; - LoggerD("offset:%u tag:0x%x | Read total_section_len:%ld (data len:%ld)", section_offset, - cur_marker, total_section_len, section_data_len); + LoggerD("offset: %zu tag:0x%x | Read total_section_len: %ld (data len: %ld)", section_offset, + (unsigned)cur_marker, total_section_len, section_data_len); offset += 2; // Read data size - 2 bytes if (total_section_len < 0) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid", - ("offset:%u tag:0x%x | Error: total_section_len is: %ld < 0", - offset, cur_marker, total_section_len)); + ("offset: %zu tag:0x%x | Error: total_section_len is: %ld < 0", + offset, (unsigned)cur_marker, total_section_len)); } if (section_offset + 2 + total_section_len > m_in_data_size) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "JPEG file is invalid", - ("offset:%u tag:0x%x | Error: current section offset:%u" - " + 2 + total_section_len:%ld = %lu is greater then file size:%u", - offset, cur_marker, section_offset, total_section_len, + ("offset: %zu tag:0x%x | Error: current section offset: %zu" + " + 2 + total_section_len: %ld = %lu is greater then file size: %zu", + offset, (unsigned)cur_marker, section_offset, total_section_len, section_offset + total_section_len, m_in_data_size)); } @@ -333,12 +333,12 @@ common::PlatformResult JpegFile::generateListOfSections() { section->exif_data = exif_data_new_from_data(section_begin, exif_data_size); LoggerD( - "offset:%u tag:0x%x | Loading exif from offset:%u" - " len:%u exif_data_new_from_data returned: %p", - offset, cur_marker, section_offset, exif_data_size, section->exif_data); + "offset: %zu tag:0x%x | Loading exif from offset: %zu" + " len: %u exif_data_new_from_data returned: %p", + offset, (unsigned)cur_marker, section_offset, exif_data_size, section->exif_data); if (!section->exif_data) { - LoggerW("offset:%d tag:0x%x | Couldn't load Exif!", offset, cur_marker); + LoggerW("offset: %zu tag:0x%x | Couldn't load Exif!", offset, (unsigned)cur_marker); } } @@ -358,9 +358,9 @@ common::PlatformResult JpegFile::generateListOfSections() { // -2 (exclude ending EOI marker (2 bytes) std::size_t image_size = m_in_data_size - image_data_offset - 2; LoggerW( - "offset:%d tag:0x%x" - " | Image data offset:%u Estimated image size:%u", - offset, cur_marker, image_data_offset, image_size); + "offset: %zu tag:0x%x" + " | Image data offset: %zu Estimated image size: %zu", + offset, (unsigned)cur_marker, image_data_offset, image_size); m_image_data = m_in_data + image_data_offset; @@ -375,31 +375,32 @@ common::PlatformResult JpegFile::generateListOfSections() { "JPEG file contains image data stream: image_size+= 2"); image_size += 2; // Skip expected EOI tag which is not present } else { - LoggerD("EOI tag found at offset: %d from SOS data", eoi_tag_index); + LoggerD("EOI tag found at offset: %zu from SOS data", eoi_tag_index); if (eoi_tag_index != image_size) { LoggerW( - "Estimated image size:%d doesn't match EOI tag index:%d" - " delta:%d", + "Estimated image size: %zu doesn't match EOI tag index: %zu" + " delta: %zu", image_size, eoi_tag_index, image_size - eoi_tag_index); - LoggerW("Setting image_size to EOI tag: %u", eoi_tag_index); + LoggerW("Setting image_size to EOI tag: %zu", eoi_tag_index); image_size = eoi_tag_index; m_padding_data = m_image_data + image_size + 2; // (skip EOI tag) m_padding_data_size = (m_in_data + m_in_data_size) - m_padding_data; - LoggerW("Saving padding data from offset:%d with size:%d", m_padding_data - m_in_data, - m_padding_data_size); + LoggerW("Saving padding data from offset: %td with size: %zu", + m_padding_data - m_in_data, m_padding_data_size); } } m_image_size = image_size; offset = image_data_offset + image_size; - LoggerD("offset:%u tag:0x%x | SOS Offset moved to next marker", offset, cur_marker); + LoggerD("offset: %zu tag:0x%x | SOS Offset moved to next marker", offset, + (unsigned)cur_marker); } else { offset += section_data_len; - LoggerD("offset:%u tag:0x%x | Offset moved to next marker", offset, cur_marker); + LoggerD("offset: %zu tag:0x%x | Offset moved to next marker", offset, (unsigned)cur_marker); } } } @@ -410,7 +411,7 @@ common::PlatformResult JpegFile::generateListOfSections() { bool JpegFile::searchForTagInBuffer(const unsigned char* buffer_start, const unsigned char* buffer_end, const JpegMarker marker, std::size_t& out_index) { - ScopeLogger("start:%p end:%p marker:0x%x", buffer_start, buffer_end, marker); + ScopeLogger("start: %p end: %p marker:0x%x", buffer_start, buffer_end, (unsigned)marker); if (!buffer_start) { LoggerE("buffer_start is NULL"); @@ -427,7 +428,7 @@ bool JpegFile::searchForTagInBuffer(const unsigned char* buffer_start, return false; } - LoggerD("Bytes to scan: %d", static_cast(buffer_end - buffer_start)); + LoggerD("Bytes to scan: %zu", static_cast(buffer_end - buffer_start)); const unsigned char marker_uchar = static_cast(marker); for (const unsigned char* ptr = buffer_start; ptr < buffer_end; ++ptr) { @@ -511,7 +512,7 @@ ExifData* JpegFile::getExifData() { } PlatformResult JpegFile::saveToFile(const std::string& out_path) { - ScopeLogger("out_path:%s", out_path.c_str()); + ScopeLogger("out_path: %s", out_path.c_str()); PlatformResult status = saveToFilePriv(out_path); if (status) return status; @@ -540,7 +541,7 @@ PlatformResult JpegFile::saveToFile(const std::string& out_path) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Couldn't restore whole file", ("Couldn't restore whole JPEG! " - "Only %d of %d bytes have been wrote!", + "Only %zu of %zu bytes have been wrote!", bytes_wrote, m_in_data_size)); } if (EOF == fclose(outf)) { @@ -554,7 +555,7 @@ PlatformResult JpegFile::saveToFile(const std::string& out_path) { } PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { - ScopeLogger("out_path:%s", out_path.c_str()); + ScopeLogger("out_path: %s", out_path.c_str()); m_out_file = fopen(out_path.c_str(), "wb"); if (!m_out_file) { @@ -571,7 +572,7 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { JpegFileSectionPtr cur = *it; const JpegMarker cur_marker = cur->type; - LoggerD("offset:%d | Section: %d marker 0x%x", offset, section_index, cur_marker); + LoggerD("offset: %zu | Section: %d marker 0x%x", offset, section_index, (unsigned)cur_marker); std::size_t bytes_to_write = 0; std::size_t bytes_wrote = 0; @@ -595,15 +596,15 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not save Exif in JPEG file"); } - LoggerD("offset:%d | Generated Exif RAW Data length:%d", offset, exif_output_size); + LoggerD("offset: %zu | Generated Exif RAW Data length: %u", offset, exif_output_size); exif_output_data.reset(tmp); if (exif_output_size > MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Exif data is to big to be saved in JPEG file", - ("exif_output_size:%d is greater then maximum JPEG section" - "data block size: %d", + ("exif_output_size: %u is greater then maximum JPEG section" + "data block size: %u", exif_output_size, MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE)); } section_size += exif_output_size; @@ -618,9 +619,9 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { } LoggerD( - "offset:%d | Writing section:" - " marker:0x%x size:%d", - offset, cur_marker, cur->size); + "offset: %zu | Writing section:" + " marker:0x%x size: %d", + offset, (unsigned)cur_marker, cur->size); bytes_wrote = fwrite(tmp_buf, 1, bytes_to_write, m_out_file); offset += bytes_wrote; @@ -628,11 +629,11 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { if (bytes_wrote != bytes_to_write) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not write JPEG file", - ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write, bytes_wrote)); + ("Couldn't wrote %zu bytes! Only %zu bytes wrote", bytes_to_write, bytes_wrote)); } if (write_section_data && cur->size > 0) { - LoggerD("offset:%d | Writing data with length:%d", offset, cur->size); + LoggerD("offset: %zu | Writing data with length: %d", offset, cur->size); bytes_to_write = cur->size; bytes_wrote = fwrite(cur->data_ptr, 1, bytes_to_write, m_out_file); @@ -641,12 +642,12 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { if (bytes_wrote != bytes_to_write) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not write JPEG file", - ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write, bytes_wrote)); + ("Couldn't wrote %zu bytes! Only %zu bytes wrote", bytes_to_write, bytes_wrote)); } } if (write_exif_data && exif_output_data && exif_output_size > 0) { - LoggerD("offset:%d | Writing new exif data with length:%d", offset, exif_output_size); + LoggerD("offset: %zu | Writing new exif data with length: %u", offset, exif_output_size); bytes_to_write = exif_output_size; bytes_wrote = fwrite(exif_output_data.get(), 1, bytes_to_write, m_out_file); @@ -655,12 +656,12 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { if (bytes_wrote != bytes_to_write) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not write JPEG file", - ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write, bytes_wrote)); + ("Couldn't wrote %zu bytes! Only %zu bytes wrote", bytes_to_write, bytes_wrote)); } } if (JPEG_MARKER_SOS == cur_marker) { - LoggerD("offset:%d | Writing image data stream with lenght:%d", offset, m_image_size); + LoggerD("offset: %zu | Writing image data stream with lenght: %zu", offset, m_image_size); bytes_to_write = m_image_size; bytes_wrote = fwrite(m_image_data, 1, bytes_to_write, m_out_file); @@ -669,19 +670,19 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) { if (bytes_wrote != bytes_to_write) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not write JPEG file", - ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write, bytes_wrote)); + ("Couldn't wrote %zu bytes! Only %zu bytes wrote", bytes_to_write, bytes_wrote)); } } } if (m_padding_data && m_padding_data_size > 0) { - LoggerD("Padding data exists and contains:%d bytes saving to JPEG file", m_padding_data_size); + LoggerD("Padding data exists and contains: %zu bytes saving to JPEG file", m_padding_data_size); const std::size_t bytes_wrote = fwrite(m_image_data, 1, m_padding_data_size, m_out_file); if (bytes_wrote != m_padding_data_size) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Could not write JPEG file", - ("Couldn't wrote %d bytes! Only %d bytes wrote", m_padding_data_size, bytes_wrote)); + ("Couldn't wrote %zu bytes! Only %zu bytes wrote", m_padding_data_size, bytes_wrote)); } } @@ -715,7 +716,7 @@ JpegFileSectionPtr JpegFile::getExifSection() { first_exif_section = cur; } else { LoggerW( - "Warning: found %d APP1/Exif sections -" + "Warning: found %zu APP1/Exif sections -" " only first is currently supported!", num_exif_sections); } diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 0837d5e..8fef9fe 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -148,7 +148,7 @@ FilesystemInstance::Worker::Worker() } FilesystemInstance::Worker::~Worker() { - if(!exit && thread.joinable()) { + if (!exit && thread.joinable()) { stop(); } } @@ -2006,7 +2006,7 @@ void FilesystemInstance::FileHandleReadString(const picojson::value& args, picoj IOException("File doesn't contain UTF-8 encoded string with given length"), out); return; } - LoggerD("char_count: %ld", char_count); + LoggerD("char_count: %lu", char_count); LoggerD("ftell: %ld", ftell(handle->file_handle)); if (!(std::feof( handle->file_handle))) { // read number of characters if not whole file read diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 676d6cb..0762f54 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -1573,8 +1573,8 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return ConvertRecordedTime(data, obj); }; - monitors_.insert(std::make_pair(kActivityTypePedometer, - std::make_shared())); + monitors_.insert( + std::make_pair(kActivityTypePedometer, std::make_shared())); monitors_.insert(std::make_pair(kActivityTypeWristUp, std::make_shared(kActivityTypeWristUp))); monitors_.insert(std::make_pair(kActivityTypeSleepDetector, diff --git a/src/messaging/MsgCommon/AttributeRangeFilter.h b/src/messaging/MsgCommon/AttributeRangeFilter.h index 6d93cbf..267faa2 100644 --- a/src/messaging/MsgCommon/AttributeRangeFilter.h +++ b/src/messaging/MsgCommon/AttributeRangeFilter.h @@ -54,7 +54,6 @@ class AttributeRangeFilter : public AbstractFilter { */ AttributeRangeFilterPtr castToAttributeRangeFilter(AbstractFilterPtr from); - } // Tizen } // DeviceAPI diff --git a/src/messaging/conversations_change_callback.cc b/src/messaging/conversations_change_callback.cc index fe5f7e0..a53c8d3 100644 --- a/src/messaging/conversations_change_callback.cc +++ b/src/messaging/conversations_change_callback.cc @@ -74,7 +74,7 @@ ConversationPtrVector ConversationsChangeCallback::filterConversations( LoggerD("[%d] matched filter: %s", i, matched ? "YES" : "NO"); } - LoggerD("returning matching %d of %d conversations", filtered_conversations.size(), + LoggerD("returning matching %zu of %zu conversations", filtered_conversations.size(), source_conversations.size()); return filtered_conversations; @@ -85,7 +85,7 @@ ConversationPtrVector ConversationsChangeCallback::filterConversations( } void ConversationsChangeCallback::added(const ConversationPtrVector& conversations) { - ScopeLogger("conversations.size() = %d", conversations.size()); + ScopeLogger("conversations.size() = %zu", conversations.size()); if (!m_is_act) { return; } @@ -104,14 +104,14 @@ void ConversationsChangeCallback::added(const ConversationPtrVector& conversatio }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSADDED, filtered.size()); + LoggerD("Calling:%s with:%zu added conversations", CONVERSATIONSADDED, filtered.size()); m_callback_data.SetAction(CONVERSATIONSADDED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::MEDIUM); } void ConversationsChangeCallback::updated(const ConversationPtrVector& conversations) { - ScopeLogger("conversations.size() = %d", conversations.size()); + ScopeLogger("conversations.size() = %zu", conversations.size()); if (!m_is_act) { return; } @@ -130,14 +130,14 @@ void ConversationsChangeCallback::updated(const ConversationPtrVector& conversat }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSUPDATED, filtered.size()); + LoggerD("Calling:%s with:%zu added conversations", CONVERSATIONSUPDATED, filtered.size()); m_callback_data.SetAction(CONVERSATIONSUPDATED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LOW); } void ConversationsChangeCallback::removed(const ConversationPtrVector& conversations) { - ScopeLogger("conversations.size() = %d", conversations.size()); + ScopeLogger("conversations.size() = %zu", conversations.size()); if (!m_is_act) { return; } @@ -156,7 +156,7 @@ void ConversationsChangeCallback::removed(const ConversationPtrVector& conversat }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSREMOVED, filtered.size()); + LoggerD("Calling:%s with:%zu added conversations", CONVERSATIONSREMOVED, filtered.size()); m_callback_data.SetAction(CONVERSATIONSREMOVED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LAST); diff --git a/src/messaging/email_manager.cc b/src/messaging/email_manager.cc index 65b117c..db1327c 100644 --- a/src/messaging/email_manager.cc +++ b/src/messaging/email_manager.cc @@ -575,7 +575,7 @@ PlatformResult EmailManager::loadMessageAttachment(MessageAttachmentCallbackData return platform_result; } - LoggerD("Mail: [%d] contains: [%d] attachments", msgAttachment->getMessageId(), + LoggerD("Mail: [%d] contains: [%zu] attachments", msgAttachment->getMessageId(), attachments.size()); auto it = attachments.begin(); @@ -821,7 +821,7 @@ void EmailManager::removeStatusCallback(const std::vector& ids, if (it != m_deleteRequests.end()) { LoggerD("Found request"); if (NOTI_MAIL_DELETE_FINISH == status) { - LoggerD("Successfully removed %d mails", ids.size()); + LoggerD("Successfully removed %zu mails", ids.size()); it->messagesDeleted += ids.size(); } MessagesCallbackUserData* callback = it->callback; @@ -1047,7 +1047,7 @@ void EmailManager::findMessages(FindMsgCallbackUserData* callback) { } // Complete task - LoggerD("callback: %p error: %d messages.size() = %d", callback, callback->IsError(), + LoggerD("callback: %p error: %d messages.size() = %zu", callback, callback->IsError(), callback->getMessages().size()); if (callback->IsError()) { @@ -1113,7 +1113,7 @@ void EmailManager::findConversations(ConversationCallbackData* callback) { } // Complete task - LoggerD("callback: %p error:%d conversations.size()=%d", callback, callback->IsError(), + LoggerD("callback: %p error:%d conversations.size()=%zu", callback, callback->IsError(), callback->getConversations().size()); if (callback->IsError()) { @@ -1232,7 +1232,7 @@ void EmailManager::findFolders(FoldersCallbackData* callback) { } // Complete task - LoggerD("callback: %p error:%d folders.size()=%d", callback, callback->IsError(), + LoggerD("callback: %p error:%d folders.size()=%zu", callback, callback->IsError(), callback->getFolders().size()); if (callback->IsError()) { diff --git a/src/messaging/folders_change_callback.cc b/src/messaging/folders_change_callback.cc index 6ceda0b..8bb67f2 100644 --- a/src/messaging/folders_change_callback.cc +++ b/src/messaging/folders_change_callback.cc @@ -69,7 +69,7 @@ FolderPtrVector FoldersChangeCallback::filterFolders(tizen::AbstractFilterPtr fi } void FoldersChangeCallback::added(const FolderPtrVector& folders) { - ScopeLogger("folders.size() = %d", folders.size()); + ScopeLogger("folders.size() = %zu", folders.size()); if (!m_is_act) { return; } @@ -88,14 +88,14 @@ void FoldersChangeCallback::added(const FolderPtrVector& folders) { }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d added folders", FOLDERSADDED, filtered.size()); + LoggerD("Calling:%s with:%zu added folders", FOLDERSADDED, filtered.size()); m_callback_data.SetAction(FOLDERSADDED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::MEDIUM); } void FoldersChangeCallback::updated(const FolderPtrVector& folders) { - ScopeLogger("folders.size() = %d", folders.size()); + ScopeLogger("folders.size() = %zu", folders.size()); if (!m_is_act) { return; } @@ -114,14 +114,14 @@ void FoldersChangeCallback::updated(const FolderPtrVector& folders) { }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d updated folders", FOLDERSUPDATED, filtered.size()); + LoggerD("Calling:%s with:%zu updated folders", FOLDERSUPDATED, filtered.size()); m_callback_data.SetAction(FOLDERSUPDATED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LOW); } void FoldersChangeCallback::removed(const FolderPtrVector& folders) { - ScopeLogger("folders.size() = %d", folders.size()); + ScopeLogger("folders.size() = %zu", folders.size()); if (!m_is_act) { return; } @@ -140,7 +140,7 @@ void FoldersChangeCallback::removed(const FolderPtrVector& folders) { }; for_each(filtered.begin(), filtered.end(), each); - LoggerD("Calling:%s with:%d removed folders", FOLDERSREMOVED, filtered.size()); + LoggerD("Calling:%s with:%zu removed folders", FOLDERSREMOVED, filtered.size()); m_callback_data.SetAction(FOLDERSREMOVED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LAST); diff --git a/src/messaging/message.cc b/src/messaging/message.cc index 231e095..2168199 100644 --- a/src/messaging/message.cc +++ b/src/messaging/message.cc @@ -591,8 +591,8 @@ PlatformResult Message::addEmailAttachments(std::shared_ptr message) { AttachmentPtrVector attachments = message->getMessageAttachments(); AttachmentPtrVector inlineAttachments = message->getBody()->getInlineAttachments(); - LoggerD("Attachments size: %d", attachments.size()); - LoggerD("Inline attachments size: %d", inlineAttachments.size()); + LoggerD("Attachments size: %zu", attachments.size()); + LoggerD("Inline attachments size: %zu", inlineAttachments.size()); LoggerD("Adding attachments for mail id = [%d]\n", message->getId()); for (auto it = attachments.begin(); it != attachments.end(); ++it) { PlatformResult ret = addSingleEmailAttachment(message, *it, AttachmentType::EXTERNAL); @@ -669,7 +669,7 @@ PlatformResult Message::addSMSRecipientsToStruct(const std::vector& for (unsigned int i = 0; i < size; ++i) { char* address = const_cast(recipients.at(i).c_str()); - LoggerD("[%d] address:[%s]", i, address); + LoggerD("[%u] address:[%s]", i, address); msg_struct_t tmpAddr = NULL; if (MSG_SUCCESS == msg_list_add_item(msg, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr)) { msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN); @@ -677,7 +677,7 @@ PlatformResult Message::addSMSRecipientsToStruct(const std::vector& msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, strlen(address)); } else { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "failed to add address", - ("failed to add address[%d] %s", i, address)); + ("failed to add address[%u] %s", i, address)); } } return PlatformResult(ErrorCode::NO_ERROR); @@ -696,7 +696,7 @@ PlatformResult Message::addMMSRecipientsToStruct(const std::vector& } char* address = const_cast(recipients.at(i).c_str()); - LoggerD("[%d] address:[%s] address_type:%d type:%d", i, address, address_type, type); + LoggerD("[%u] address:[%s] address_type:%d type:%d", i, address, address_type, type); int error = msg_list_add_item(msg, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr); if (MSG_SUCCESS == error) { @@ -705,7 +705,7 @@ PlatformResult Message::addMMSRecipientsToStruct(const std::vector& msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, strlen(address)); } else { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "failed to add address", - ("[%d] failed to add address: [%s], error: %d", i, address, error)); + ("[%u] failed to add address: [%s], error: %d", i, address, error)); } } return PlatformResult(ErrorCode::NO_ERROR); @@ -714,7 +714,7 @@ PlatformResult Message::addMMSRecipientsToStruct(const std::vector& PlatformResult Message::addMMSBodyAndAttachmentsToStruct(const AttachmentPtrVector& attach, msg_struct_t& mms_struct, Message* message) { - ScopeLogger("attachments.size() = %zd", attach.size()); + ScopeLogger("attachments.size() = %zu", attach.size()); int size = attach.size(); for (int i = 0; i < size; i++) { @@ -805,7 +805,7 @@ PlatformResult Message::convertPlatformShortMessageToStruct(Message* message, ms return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "msg_get_message() Fail", ("msg_get_message() Fail [%d] (%s)", err, get_error_message(err))); } - LoggerD("Using existing msg for id: %d", id); + LoggerD("Using existing msg for id: %u", id); } else { // id is not set - the message does not exist in database MessageType msgType = message->getType(); if (msgType == MessageType::SMS) { @@ -950,7 +950,7 @@ PlatformResult Message::convertPlatformShortMessageToStruct(Message* message, ms } // Set MMS attachments AttachmentPtrVector attach_list = message->getMessageAttachments(); - LoggerD("Message(%p): id:%d subject:[%s] plainBody:[%s] contains %d attachments", message, + LoggerD("Message(%p): id:%d subject:[%s] plainBody:[%s] contains %zu attachments", message, message->getId(), message->getSubject().c_str(), message->getBody()->getPlainBody().c_str(), attach_list.size()); @@ -1209,7 +1209,8 @@ PlatformResult Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg LoggerD( "[p:%d, m:%d] added attachment: %p " "(mime:0x%x mime:%s messageId:%d)", - p, m, att, msg_media_type, msg_media_type_str.c_str(), ma->getMessageId()); + p, m, att, (unsigned)msg_media_type, msg_media_type_str.c_str(), + ma->getMessageId()); } msg_release_struct(&media); @@ -1233,7 +1234,7 @@ PlatformResult Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg LoggerW("Warning: body has not been set!"); } - LoggerD("after MSG_MMS_PAGE_LIST attachments count is:%d", message->m_attachments.size()); + LoggerD("after MSG_MMS_PAGE_LIST attachments count is:%zu", message->m_attachments.size()); // if there are some other attachments add it to attachments vector msg_list_handle_t attach_list = NULL; @@ -1269,8 +1270,8 @@ PlatformResult Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg ma->setMimeType(type); MessageAttachment* att = ma.get(); - LoggerD("[att:%d] added attachement: %p (mime:0x%x mime:%s path:%s id:%d)", i, att, tempInt, - type.c_str(), infoStr, ma->getId()); + LoggerD("[att:%d] added attachement: %p (mime:0x%x mime:%s path:%s id:%d)", i, att, + (unsigned)tempInt, type.c_str(), infoStr, ma->getId()); message->m_attachments.push_back(ma); message->m_has_attachment = true; @@ -1284,7 +1285,7 @@ PlatformResult Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg ("msg_get_list_handle error: %d (%s)", error, get_error_message(error))); } - LoggerD("after MSG_MMS_ATTACH_LIST attachments count is:%d", message->m_attachments.size()); + LoggerD("after MSG_MMS_ATTACH_LIST attachments count is:%zu", message->m_attachments.size()); msg_release_struct(&mms_struct); return PlatformResult(ErrorCode::NO_ERROR); } diff --git a/src/messaging/messages_change_callback.cc b/src/messaging/messages_change_callback.cc index e0567dc..e0a48be 100644 --- a/src/messaging/messages_change_callback.cc +++ b/src/messaging/messages_change_callback.cc @@ -63,7 +63,7 @@ MessagesChangeCallback::~MessagesChangeCallback() { MessagePtrVector MessagesChangeCallback::filterMessages(tizen::AbstractFilterPtr filter, const MessagePtrVector& source_messages, const int service_id) { - ScopeLogger("sourceMessages.size() = %d filter %s", source_messages.size(), + ScopeLogger("sourceMessages.size() = %zu filter %s", source_messages.size(), (filter ? "PRESENT" : "NULL")); if (filter) { @@ -94,7 +94,7 @@ MessagePtrVector MessagesChangeCallback::filterMessages(tizen::AbstractFilterPtr LoggerD("}"); } - LoggerD("returning matching %d of %d messages", filtered_messages.size(), + LoggerD("returning matching %zu of %zu messages", filtered_messages.size(), source_messages.size()); return filtered_messages; } else { @@ -104,7 +104,7 @@ MessagePtrVector MessagesChangeCallback::filterMessages(tizen::AbstractFilterPtr } void MessagesChangeCallback::added(const MessagePtrVector& msgs) { - ScopeLogger("event: msgs.size() = %d", msgs.size()); + ScopeLogger("event: msgs.size() = %zu", msgs.size()); if (!m_is_act) { return; } @@ -123,14 +123,14 @@ void MessagesChangeCallback::added(const MessagePtrVector& msgs) { for_each(filtered_msgs.begin(), filtered_msgs.end(), each); - LoggerD("Calling:%s with:%d added messages", MESSAGESADDED, filtered_msgs.size()); + LoggerD("Calling:%s with:%zu added messages", MESSAGESADDED, filtered_msgs.size()); m_callback_data.SetAction(MESSAGESADDED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::MEDIUM); } void MessagesChangeCallback::updated(const MessagePtrVector& msgs) { - ScopeLogger("event: msgs.size() = %d", msgs.size()); + ScopeLogger("event: msgs.size() = %zu", msgs.size()); if (!m_is_act) { return; } @@ -149,14 +149,14 @@ void MessagesChangeCallback::updated(const MessagePtrVector& msgs) { for_each(filtered_msgs.begin(), filtered_msgs.end(), each); - LoggerD("Calling:%s with:%d updated messages", MESSAGESUPDATED, filtered_msgs.size()); + LoggerD("Calling:%s with:%zu updated messages", MESSAGESUPDATED, filtered_msgs.size()); m_callback_data.SetAction(MESSAGESUPDATED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LOW); } void MessagesChangeCallback::removed(const MessagePtrVector& msgs) { - ScopeLogger("event: msgs.size() = %d", msgs.size()); + ScopeLogger("event: msgs.size() = %zu", msgs.size()); if (!m_is_act) { return; } @@ -176,7 +176,7 @@ void MessagesChangeCallback::removed(const MessagePtrVector& msgs) { for_each(filtered_msgs.begin(), filtered_msgs.end(), each); - LoggerD("Calling:%s with:%d removed messages", MESSAGESREMOVED, filtered_msgs.size()); + LoggerD("Calling:%s with:%zu removed messages", MESSAGESREMOVED, filtered_msgs.size()); m_callback_data.SetAction(MESSAGESREMOVED, picojson::value(array)); m_callback_data.AddAndPost(PostPriority::LAST); diff --git a/src/messaging/short_message_manager.cc b/src/messaging/short_message_manager.cc index d1fc95c..069a686 100644 --- a/src/messaging/short_message_manager.cc +++ b/src/messaging/short_message_manager.cc @@ -53,7 +53,7 @@ static gboolean sendMessageCompleteCB(void* user_data) { } else { std::shared_ptr message = callback->getMessage(); - LoggerD("Calling success callback with: %d recipients", message->getTO().size()); + LoggerD("Calling success callback with: %zu recipients", message->getTO().size()); std::vector recipients; auto addToRecipients = [&recipients](std::string& e) -> void { @@ -393,7 +393,7 @@ PlatformResult ShortMsgManager::callProperEventMessages(EventMessages* event, msg_storage_change_type_t storageChangeType, ShortMsgManager* shortMsgManager) { ScopeLogger( - "event.items.size()=%d event.removed_conversations.size()=%d" + "event.items.size()=%zu event.removed_conversations.size()=%zu" " sChangeType:%d", event->items.size(), event->removed_conversations.size(), storageChangeType); @@ -435,17 +435,17 @@ PlatformResult ShortMsgManager::callProperEventMessages(EventMessages* event, cur_conv->getConversationId(), cur_conv->getLastMessageId()); } - LoggerD("num conversations:all=%d added=%d update=%d", eventConv->items.size(), + LoggerD("num conversations:all=%zu added=%zu update=%zu", eventConv->items.size(), added_conv.size(), updated_conv.size()); if (false == added_conv.empty()) { - LoggerD("%d new conversations, calling onConversationAdded", added_conv.size()); + LoggerD("%zu new conversations, calling onConversationAdded", added_conv.size()); eventConv->items = added_conv; ChangeListenerContainer::getInstance().callConversationAdded(eventConv); } if (false == updated_conv.empty()) { - LoggerD("%d updated conversation, calling onConversationUpdated", updated_conv.size()); + LoggerD("%zu updated conversation, calling onConversationUpdated", updated_conv.size()); eventConv->items = updated_conv; ChangeListenerContainer::getInstance().callConversationUpdated(eventConv); } @@ -535,7 +535,7 @@ void ShortMsgManager::storage_change_cb(msg_handle_t handle, for (int i = 0; i < pMsgIdList->nCount; ++i) { const msg_message_id_t& msg_id = pMsgIdList->msgIdList[i]; - LoggerD("pMsgIdList[%d] = %d", i, msg_id); + LoggerD("pMsgIdList[%d] = %u", i, msg_id); std::map::iterator it = cur_rem_msgs.find(msg_id); if (it != cur_rem_msgs.end()) { @@ -761,7 +761,7 @@ void ShortMsgManager::updateMessages(MessagesCallbackUserData* callback) { return; } - LoggerD("messages to update: %d", callback->getMessages().size()); + LoggerD("messages to update: %zu", callback->getMessages().size()); { std::lock_guard lock(m_mutex); @@ -849,7 +849,7 @@ PlatformResult ShortMsgManager::getMessage(int msg_id, msg_struct_t* out_msg) { PlatformResult ShortMsgManager::getConversationsForMessages( MessagePtrVector messages, msg_storage_change_type_t storageChangeType, ConversationPtrVector* result, ShortMsgManager* shortMsgManager) { - ScopeLogger("messages.size()=%d storageChangeType=%d", messages.size(), storageChangeType); + ScopeLogger("messages.size()=%zu storageChangeType=%d", messages.size(), storageChangeType); std::unordered_set unique_conv_ids; ConversationPtrVector convs; @@ -942,7 +942,7 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback) { if (callback->IsError()) { LoggerD("Calling error callback"); } else { - LoggerD("Calling success callback with %d messages:", callback->getMessages().size()); + LoggerD("Calling success callback with %zu messages:", callback->getMessages().size()); std::vector response; auto messages = callback->getMessages(); @@ -1072,7 +1072,7 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback) { ConversationPtr conv = (*it); msg_thread_id_t conv_id = conv->getConversationId(); - LoggerD("[%d] MessageConversation(%p) conv_id:%d", conv_index, conv.get(), conv_id); + LoggerD("[%d] MessageConversation(%p) conv_id:%u", conv_index, conv.get(), conv_id); msg_struct_list_s conv_view_list; error = msg_get_conversation_view_list(handle, (msg_thread_id_t)conv_id, &conv_view_list); @@ -1088,14 +1088,14 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback) { LoggerD( "[%d] message[%d] msg_id:%d," - "saved MessageConversation(%p) with conv_id:%d", + "saved MessageConversation(%p) with conv_id:%u", conv_index, msg_index, cur_msg_id, conv.get(), conv_id); } else { LoggerE("[%d] Couldn't get msg_id, error: %s!", error, get_error_message(error)); } } } else { - LoggerE("[%d] Couldn' get conversation view list for conv_id:%d error: %d", conv_index, + LoggerE("[%d] Couldn' get conversation view list for conv_id:%u error: %d", conv_index, conv_id, error); } @@ -1139,12 +1139,12 @@ ShortMsgManager::ShortMsgManager() : m_msg_handle(NULL) { ShortMsgManager::~ShortMsgManager() { ScopeLogger(); - LoggerD("m_sms_removed_messages.size() = %d", m_sms_removed_messages.size()); - LoggerD("m_mms_removed_messages.size() = %d", m_mms_removed_messages.size()); - LoggerD("m_sms_removed_msg_id_conv_id_map.size() = %d", m_sms_removed_msg_id_conv_id_map.size()); - LoggerD("m_sms_removed_conv_id_object_map.size() = %d", m_sms_removed_conv_id_object_map.size()); - LoggerD("m_mms_removed_msg_id_conv_id_map.size() = %d", m_mms_removed_msg_id_conv_id_map.size()); - LoggerD("m_mms_removed_conv_id_object_map.size() = %d", m_mms_removed_conv_id_object_map.size()); + LoggerD("m_sms_removed_messages.size() = %zu", m_sms_removed_messages.size()); + LoggerD("m_mms_removed_messages.size() = %zu", m_mms_removed_messages.size()); + LoggerD("m_sms_removed_msg_id_conv_id_map.size() = %zu", m_sms_removed_msg_id_conv_id_map.size()); + LoggerD("m_sms_removed_conv_id_object_map.size() = %zu", m_sms_removed_conv_id_object_map.size()); + LoggerD("m_mms_removed_msg_id_conv_id_map.size() = %zu", m_mms_removed_msg_id_conv_id_map.size()); + LoggerD("m_mms_removed_conv_id_object_map.size() = %zu", m_mms_removed_conv_id_object_map.size()); } std::string ShortMsgManager::getMessageStatus(int id) { ScopeLogger(); diff --git a/src/nfc/nfc_adapter.cc b/src/nfc/nfc_adapter.cc index f1725f3..65c87c4 100644 --- a/src/nfc/nfc_adapter.cc +++ b/src/nfc/nfc_adapter.cc @@ -436,7 +436,7 @@ PlatformResult NFCAdapter::SetCardEmulationMode(const std::string& mode) { if (result.IsError()) { return result; } - LoggerD("Card emulation mode value: %x", (int)new_mode); + LoggerD("Card emulation mode value: %x", (unsigned)new_mode); std::string current_mode = ""; result = GetCardEmulationMode(¤t_mode); @@ -498,7 +498,7 @@ PlatformResult NFCAdapter::SetActiveSecureElement(std::string element) { LoggerD("Error: %s", result.message().c_str()); return result; } - LoggerD("Secure element type value: %x", (int)new_type); + LoggerD("Secure element type value: %x", (unsigned)new_type); std::string current_type = ""; result = GetActiveSecureElement(¤t_type); @@ -947,7 +947,7 @@ static void tagEventCallback(nfc_discovered_type_e type, nfc_tag_h tag, void* /* obj.insert(make_pair("action", picojson::value("ondetach"))); NFCAdapter::GetInstance()->RespondAsync(event.serialize().c_str()); } else { // ERROR - should never happen - LoggerE("Invalid NFC discovered type: %d (%x)", type, type); + LoggerE("Invalid NFC discovered type: %d (%x)", type, (unsigned)type); } } @@ -1554,7 +1554,7 @@ PlatformResult NFCAdapter::SetPreferredApp() { if (aids.empty()) { return LogAndCreateResult(ErrorCode::ABORT_ERR, "No AID registered"); } - LoggerD("Found %d AIDs", aids.size()); + LoggerD("Found %zu AIDs", aids.size()); int ret = nfc_se_set_preferred_handler(); if (ret != NFC_ERROR_NONE) { diff --git a/src/nfc/nfc_util.cc b/src/nfc/nfc_util.cc index de51aaa..e91e1a1 100644 --- a/src/nfc/nfc_util.cc +++ b/src/nfc/nfc_util.cc @@ -221,7 +221,7 @@ PlatformResult NFCUtil::ToStringCardEmulationMode(const nfc_se_card_emulation_mo break; default: return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "No Match Card Emulation mode", - ("No Match Card Emulation mode: %x", card_mode)); + ("No Match Card Emulation mode: %x", (unsigned)card_mode)); } return PlatformResult(ErrorCode::NO_ERROR); } @@ -254,7 +254,7 @@ PlatformResult NFCUtil::ToStringSecureElementType(const nfc_se_type_e se_type, s break; default: return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "No Match Secure Element Type", - ("No Match Secure Element Type: %x", se_type)); + ("No Match Secure Element Type: %x", (unsigned)se_type)); } return PlatformResult(ErrorCode::NO_ERROR); } diff --git a/src/package/package_instance.cc b/src/package/package_instance.cc index 6af3a74..b944775 100644 --- a/src/package/package_instance.cc +++ b/src/package/package_instance.cc @@ -19,12 +19,12 @@ #include #include +#include "common/filesystem/filesystem_provider.h" #include "common/logger.h" #include "common/picojson.h" #include "common/task-queue.h" #include "common/tools.h" #include "package/package_info_provider.h" -#include "common/filesystem/filesystem_provider.h" namespace extension { namespace package { diff --git a/src/sound/sound_manager.cc b/src/sound/sound_manager.cc index fa23c61..c902d9a 100644 --- a/src/sound/sound_manager.cc +++ b/src/sound/sound_manager.cc @@ -197,7 +197,7 @@ double SoundManager::ConvertToSystemVolume(int max_volume, int volume) { } void SoundManager::VolumeChangeCallback(sound_type_e type, unsigned int value) { - ScopeLogger("VolumeChangeCallback: type: %d, value: %d", type, value); + ScopeLogger("VolumeChangeCallback: type: %d, value: %u", type, value); // Prepare response picojson::value response = picojson::value(picojson::object()); diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index da705eb..4b46b1b 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -1208,7 +1208,7 @@ PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) // handling storages from provider common::FilesystemProvider& provider(common::FilesystemProvider::Create()); auto storages = provider.GetStorages(); - LoggerD("Storages found %d", storages.size()); + LoggerD("Storages found %zu", storages.size()); for (auto storage : storages) { if (storage->state() == common::StorageState::kMounted) { unsigned long long available; diff --git a/src/widgetservice/widgetservice_instance.cc b/src/widgetservice/widgetservice_instance.cc index fd8f0ba..bbd61c0 100644 --- a/src/widgetservice/widgetservice_instance.cc +++ b/src/widgetservice/widgetservice_instance.cc @@ -586,7 +586,8 @@ TizenResult WidgetServiceInstance::SendContent(picojson::object const& args) { LogAndReturnTizenError(common::AbortError(ret), ("bundle_add() failed")); } - int ret_widget = widget_service_trigger_update(widget_id.c_str(), instance_id.c_str(), data, force); + int ret_widget = + widget_service_trigger_update(widget_id.c_str(), instance_id.c_str(), data, force); if (WIDGET_ERROR_NONE != ret_widget) { LogAndReturnTizenError(WidgetServiceUtils::ConvertErrorCode(ret_widget), ("widget_service_trigger_update() failed")); @@ -620,8 +621,8 @@ TizenResult WidgetServiceInstance::GetContent(picojson::object const& args, bundle_free(bundle_data); }; - int ret_widget = widget_service_get_content_of_widget_instance(widget_id.c_str(), instance_id.c_str(), - &bundle_data); + int ret_widget = widget_service_get_content_of_widget_instance( + widget_id.c_str(), instance_id.c_str(), &bundle_data); if (WIDGET_ERROR_NONE != ret_widget) { LoggerE("widget_service_get_content_of_widget_instance() failed"); this->Post(token, WidgetServiceUtils::ConvertErrorCode(ret_widget)); -- 2.7.4 From 0cd2a0974b9edc3e8882368bde237df730bacf7d Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Tue, 28 Aug 2018 13:34:08 +0200 Subject: [PATCH 16/16] [Spec] fix for generating emulator extension plugins Fix preventing error while generate emulator extension. Packages was not downloaded for modules which are enable on emulator and disable on devices. [Verification] Plugins generate properly Change-Id: I1eae9fd0d42d2d645792fb9b3ffe779f7cae1a1f Signed-off-by: Lukasz Bardeli --- packaging/webapi-plugins.spec | 106 +++++++++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 1e217f6..78f7e10 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -162,6 +162,28 @@ Source0: %{name}-%{version}.tar.gz %define tizen_mobile_feature_voicecontrol_support 1 %define tizen_mobile_feature_ppm_support 1 +## Mobile emulator + +%define tizen_mobile_emulator_feature_bluetooth_support 0 + +# FM radio feature +%define tizen_mobile_emulator_feature_fm_radio_support 1 + +%define tizen_mobile_emulator_feature_ham_support 1 +%define tizen_mobile_emulator_feature_media_key_support 0 +%define tizen_mobile_emulator_feature_nfc_emulation_support 0 +%define tizen_mobile_emulator_feature_nfc_support 1 + +# secure element feature +%define tizen_mobile_emulator_feature_se_support 0 + +# telephony feature +%define tizen_mobile_emulator_feature_telephony_support 1 +%define tizen_mobile_emulator_feature_callhistory_support 1 +%define tizen_mobile_emulator_feature_nbs_support 1 + +%define tizen_mobile_emulator_feature_wi_fi_support 0 + #################################################################### # Wearable Profile : B2 / TW2 # #################################################################### @@ -239,6 +261,22 @@ Source0: %{name}-%{version}.tar.gz %define tizen_wearable_feature_voicecontrol_support 1 %define tizen_wearable_feature_ppm_support 1 +## Wearable emulator + +%define tizen_wearable_emulator_feature_bluetooth_support 0 + +# MediayKey API is optional in Tizen Wearable Profile. +# tizen.org/feature/network.bluetooth.audio.media is required for MediayKey API +%define tizen_wearable_emulator_feature_media_key_support 0 + +#- telephony related APIs +# CallHistory API is optional in Tizen Wearable Profile. +# NetworkBearerSelection API is optional in Tizen Wearable Profile. +%define tizen_wearable_emulator_feature_se_support 0 +%define tizen_wearable_emulator_feature_telephony_support 1 +%define tizen_wearable_emulator_feature_callhistory_support 1 +%define tizen_wearable_emulator_feature_nbs_support 1 +%define tizen_wearable_emulator_feature_sensor_support 1 #################################################################### # TV Profile # @@ -453,7 +491,7 @@ BuildRequires: pkgconfig(capi-data-control) BuildRequires: pkgconfig(capi-web-url-download) %endif -%if "%{?tizen_feature_ham_support}" == "1" || "%{?unified_build}" == "1" +%if "%{?tizen_feature_ham_support}" == "1" || "%{?unified_build}" == "1" || "%{?tizen_mobile_emulator_feature_ham_support}" == "1" BuildRequires: pkgconfig(motion) BuildRequires: pkgconfig(capi-system-sensor) BuildRequires: pkgconfig(capi-location-manager) @@ -504,7 +542,7 @@ BuildRequires: pkgconfig(calendar-service2) BuildRequires: pkgconfig(contacts-service2) %endif -%if "%{?tizen_feature_callhistory_support}" == "1" || "%{?unified_build}" == "1" +%if "%{?tizen_feature_callhistory_support}" == "1" || "%{?unified_build}" == "1" || "%{?tizen_mobile_emulator_feature_callhistory_support}" == "1" || "%{?tizen_wearable_emulator_feature_callhistory_support}" == "1" BuildRequires: pkgconfig(contacts-service2) %endif @@ -512,12 +550,12 @@ BuildRequires: pkgconfig(contacts-service2) BuildRequires: pkgconfig(libexif) %endif -%if "%{?tizen_feature_nfc_support}" == "1" || "%{?unified_build}" == "1" +%if "%{?tizen_feature_nfc_support}" == "1" || "%{?unified_build}" == "1" || "%{?tizen_mobile_emulator_feature_nfc_support}" == "1" BuildRequires: pkgconfig(capi-network-nfc) BuildRequires: pkgconfig(capi-appfw-app-control) %endif -%if "%{?tizen_feature_fm_radio_support}" == "1" || "%{?unified_build}" == "1" +%if "%{?tizen_feature_fm_radio_support}" == "1" || "%{?unified_build}" == "1" || "%{?tizen_mobile_emulator_feature_fm_radio_support}" == "1" BuildRequires: pkgconfig(capi-media-radio) %endif @@ -546,7 +584,7 @@ BuildRequires: pkgconfig(capi-appfw-preference) BuildRequires: pkgconfig(capi-media-sound-manager) %endif -%if "%{?tizen_feature_sensor_support}" == "1" || "%{?unified_build}" == "1" +%if "%{?tizen_feature_sensor_support}" == "1" || "%{?unified_build}" == "1" || "%{?tizen_wearable_emulator_feature_sensor_support}" == "1" BuildRequires: pkgconfig(capi-system-sensor) %endif @@ -719,33 +757,30 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_pp ninja -C out/Default %{?_smp_mflags} pushd out mv Default bin_mobile -%if "%{?profile}" == "mobile" -ln -sf bin_mobile Default -%endif popd # mobile-extension-emulator %ifarch %{ix86} x86_64 -%define tizen_mobile_feature_bluetooth_support 0 +%define tizen_mobile_feature_bluetooth_support %{?tizen_mobile_emulator_feature_bluetooth_support} # FM radio feature -%define tizen_mobile_feature_fm_radio_support 1 +%define tizen_mobile_feature_fm_radio_support %{?tizen_mobile_emulator_feature_fm_radio_support} -%define tizen_mobile_feature_ham_support 1 -%define tizen_mobile_feature_media_key_support 0 -%define tizen_mobile_feature_nfc_emulation_support 0 -%define tizen_mobile_feature_nfc_support 1 +%define tizen_mobile_feature_ham_support %{?tizen_mobile_emulator_feature_ham_support} +%define tizen_mobile_feature_media_key_support %{?tizen_mobile_emulator_feature_media_key_support} +%define tizen_mobile_feature_nfc_emulation_support %{?tizen_mobile_emulator_feature_nfc_emulation_support} +%define tizen_mobile_feature_nfc_support %{?tizen_mobile_emulator_feature_nfc_support} # secure element feature -%define tizen_mobile_feature_se_support 0 +%define tizen_mobile_feature_se_support %{?tizen_mobile_emulator_feature_se_support} # telephony feature -%define tizen_mobile_feature_telephony_support 1 -%define tizen_mobile_feature_callhistory_support 1 -%define tizen_mobile_feature_nbs_support 1 +%define tizen_mobile_feature_telephony_support %{?tizen_mobile_emulator_feature_telephony_support} +%define tizen_mobile_feature_callhistory_support %{?tizen_mobile_emulator_feature_callhistory_support} +%define tizen_mobile_feature_nbs_support %{?tizen_mobile_emulator_feature_nbs_support} -%define tizen_mobile_feature_wi_fi_support 0 +%define tizen_mobile_feature_wi_fi_support %{?tizen_mobile_emulator_feature_wi_fi_support} GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=mobile -Dprivilege_engine=%{tizen_mobile_privilege_engine}" GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}" @@ -809,11 +844,15 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_pp ninja -C out/Default %{?_smp_mflags} pushd out mv Default bin_mobile_emulator +popd +%endif # mobile-extension-emulator + +pushd out %if "%{?profile}" == "mobile" -ln -sf bin_mobile_emulator Default +ln -sf bin_mobile Default %endif popd -%endif # mobile-extension-emulator + %endif # MOBILE %if "%{?unified_build}" == "1" || "%{?profile}" == "wearable" @@ -880,28 +919,25 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_ ninja -C out/Default %{?_smp_mflags} pushd out mv Default bin_wearable -%if "%{?profile}" == "wearable" -ln -sf bin_wearable Default -%endif popd # wearable-extension-emulator %ifarch %{ix86} x86_64 -%define tizen_wearable_feature_bluetooth_support 0 +%define tizen_wearable_feature_bluetooth_support %{?tizen_wearable_emulator_feature_bluetooth_support} # MediayKey API is optional in Tizen Wearable Profile. # tizen.org/feature/network.bluetooth.audio.media is required for MediayKey API -%define tizen_wearable_feature_media_key_support 0 +%define tizen_wearable_feature_media_key_support %{?tizen_wearable_emulator_feature_media_key_support} #- telephony related APIs # CallHistory API is optional in Tizen Wearable Profile. # NetworkBearerSelection API is optional in Tizen Wearable Profile. -%define tizen_wearable_feature_se_support 0 -%define tizen_wearable_feature_telephony_support 1 -%define tizen_wearable_feature_callhistory_support 1 -%define tizen_wearable_feature_nbs_support 1 -%define tizen_wearable_feature_sensor_support 1 +%define tizen_wearable_feature_se_support %{?tizen_wearable_emulator_feature_se_support} +%define tizen_wearable_feature_telephony_support %{?tizen_wearable_emulator_feature_telephony_support} +%define tizen_wearable_feature_callhistory_support %{?tizen_wearable_emulator_feature_callhistory_support} +%define tizen_wearable_feature_nbs_support %{?tizen_wearable_emulator_feature_nbs_support} +%define tizen_wearable_feature_sensor_support %{?tizen_wearable_emulator_feature_sensor_support} GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=wearable -Dprivilege_engine=%{tizen_wearable_privilege_engine}" GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}" @@ -965,11 +1001,15 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_ ninja -C out/Default %{?_smp_mflags} pushd out mv Default bin_wearable_emulator +popd +%endif # wearable-extension-emulator + +pushd out %if "%{?profile}" == "wearable" -ln -sf bin_wearable_emulator Default +ln -sf bin_wearable Default %endif popd -%endif # wearable-extension-emulator + %endif # WEARABLE %if "%{?unified_build}" == "1" || "%{?profile}" == "tv" -- 2.7.4