*/
#include "systeminfo-utils.h"
-#include "systeminfo/systeminfo_instance.h"
-
-#include <memory>
#include <net_connection.h>
#include <runtime_info.h>
+#include <fstream>
+#include <memory>
+
#include "common/logger.h"
#include "common/platform_exception.h"
#include "common/scope_exit.h"
+#include "common/tools.h"
+#include "systeminfo/systeminfo_instance.h"
namespace extension {
namespace systeminfo {
const short MEMORY_TO_BYTE = 1024;
} // namespace
-using common::PlatformResult;
using common::ErrorCode;
+using common::PlatformResult;
+using common::tools::GetErrorString;
PlatformResult SysteminfoUtils::GetVconfInt(const char *key, int *value) {
ScopeLogger();
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult SysteminfoUtils::GetDeviceUptime(unsigned long long *result) {
+ ScopeLogger();
+
+ double uptime_seconds;
+ if (std::ifstream("/proc/uptime", std::ios::in) >> uptime_seconds) {
+ *result = static_cast<unsigned long long>(llround(uptime_seconds));
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ int ret = errno;
+ std::string log_msg =
+ "Failed to get uptime from /proc/uptime: " + GetErrorString(ret);
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, log_msg,
+ ("Failed to get uptime from /proc/uptime: %d (%s)",
+ ret, GetErrorString(ret).c_str()));
+}
+
PlatformResult SysteminfoUtils::RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
void *event_ptr) {
ScopeLogger();
static common::PlatformResult GetTotalMemory(long long *result);
static common::PlatformResult GetServiceCountry(std::string *result);
static common::PlatformResult GetAvailableMemory(long long *result);
+ static common::PlatformResult GetDeviceUptime(unsigned long long *result);
static common::PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
void *event_ptr);
static common::PlatformResult UnregisterVconfCallback(const char *in_key, vconf_callback_fn cb);
return native_.getResultObject(result).availableMemory;
};
+SystemInfo.prototype.getDeviceUptime = function () {
+ var result = native_.callSync('SystemInfoGetDeviceUptime', {});
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return native_.getResultObject(result).uptime;
+};
+
SystemInfo.prototype.getCount = function() {
var args = validator_.validateArgs(arguments, [
{
REGISTER_METHOD(SystemInfoRemovePropertyValueChangeListener);
REGISTER_METHOD(SystemInfoGetTotalMemory);
REGISTER_METHOD(SystemInfoGetAvailableMemory);
+ REGISTER_METHOD(SystemInfoGetDeviceUptime);
REGISTER_METHOD(SystemInfoGetCount);
REGISTER_METHOD(SystemInfoSetBrightness);
REGISTER_METHOD(SystemInfoGetBrightness);
manager_.GetAvailableMemory(args, &out);
}
+void SysteminfoInstance::SystemInfoGetDeviceUptime(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger();
+ manager_.GetDeviceUptime(args, &out);
+}
+
void SysteminfoInstance::SystemInfoGetCount(const picojson::value& args, picojson::object& out) {
ScopeLogger();
manager_.GetCount(args, &out);
void SystemInfoSetBrightness(const picojson::value& args, picojson::object& out);
void SystemInfoGetTotalMemory(const picojson::value& args, picojson::object& out);
void SystemInfoGetAvailableMemory(const picojson::value& args, picojson::object& out);
+ void SystemInfoGetDeviceUptime(const picojson::value &args, picojson::object &out);
void SystemInfoGetCount(const picojson::value& args, picojson::object& out);
SysteminfoManager manager_;
LoggerD("Success");
}
+void SysteminfoManager::GetDeviceUptime(const picojson::value& args,
+ picojson::object* out) {
+ ScopeLogger();
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ unsigned long long return_value = 0;
+ PlatformResult ret = SysteminfoUtils::GetDeviceUptime(&return_value);
+ if (ret.IsError()) {
+ LogAndReportError(ret, out);
+ return;
+ }
+ result_obj.insert(std::make_pair(
+ "uptime", picojson::value(static_cast<double>(return_value))));
+
+ ReportSuccess(result, *out);
+ LoggerD("Success");
+}
+
void SysteminfoManager::GetCount(const picojson::value& args, picojson::object* out) {
ScopeLogger();
CHECK_EXIST(args, "property", out)
void SetBrightness(const picojson::value& args, picojson::object* out);
void GetTotalMemory(const picojson::value& args, picojson::object* out);
void GetAvailableMemory(const picojson::value& args, picojson::object* out);
+ void GetDeviceUptime(const picojson::value& args, picojson::object* out);
void GetCount(const picojson::value& args, picojson::object* out);
common::PlatformResult GetPropertyCount(const std::string& property, unsigned long* count);