#include <memory>
-#include <device.h>
#include <net_connection.h>
+#include <runtime_info.h>
#include "common/logger.h"
#include "common/platform_exception.h"
PlatformResult SysteminfoUtils::GetTotalMemory(long long *result) {
ScopeLogger();
- unsigned int value = 0;
-
- int ret = device_memory_get_total(&value);
- if (ret != DEVICE_ERROR_NONE) {
- std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+ runtime_memory_info_s info = {0};
+ int ret = runtime_info_get_system_memory_info(&info);
+ if (ret != RUNTIME_INFO_ERROR_NONE) {
+ std::string log_msg = "Failed to get system memory info: " + std::to_string(ret);
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, log_msg,
- ("device_memory_get_total error: %d (%s)", ret, get_error_message(ret)));
+ ("runtime_info_get_system_memory_info error: %d (%s)", ret, get_error_message(ret)));
}
- *result = static_cast<long long>(value) * MEMORY_TO_BYTE;
+ *result = static_cast<long long>(info.total) * MEMORY_TO_BYTE;
return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult SysteminfoUtils::GetAvailableMemory(long long *result) {
ScopeLogger();
- unsigned int value = 0;
-
- int ret = device_memory_get_available(&value);
- if (ret != DEVICE_ERROR_NONE) {
- std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+ runtime_memory_info_s info = {0};
+ int ret = runtime_info_get_system_memory_info(&info);
+ if (ret != RUNTIME_INFO_ERROR_NONE) {
+ std::string log_msg = "Failed to get system memory info: " + std::to_string(ret);
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, log_msg,
- ("device_memory_get_available error: %d (%s)", ret, get_error_message(ret)));
+ ("runtime_info_get_system_memory_info error: %d (%s)", ret, get_error_message(ret)));
}
- *result = static_cast<long long>(value) * MEMORY_TO_BYTE;
+ // as the WebIDL says the available memory means "amount of memory that is not in use (in bytes)",
+ // the result value is evaluated exactly this way, basing on total and used memory.
+ *result = static_cast<long long>(info.total - info.used) * MEMORY_TO_BYTE;
+
return PlatformResult(ErrorCode::NO_ERROR);
}