#include <package_manager.h>
#include <unistd.h>
+#include "common/extension.h"
#include "common/logger.h"
#include "common/scope_exit.h"
namespace common {
-CurrentApplication& CurrentApplication::GetInstance() {
+namespace {
+
+std::string GetRuntimeVariable(const char* variable_name) {
+ return common::Extension::GetRuntimeVariableString(variable_name);
+}
+
+} // namespace
+
+CurrentApplication &CurrentApplication::GetInstance() {
ScopeLogger();
static CurrentApplication current_application;
return current_application;
std::string CurrentApplication::GetApplicationId() const {
ScopeLogger();
- return app_id_;
+ auto app_id = GetRuntimeVariable("application_id");
+ LoggerI("GetRuntimeVariable: cached application_id: %s, runtime application_id: %s", app_id_.c_str(), app_id.c_str());
+ return app_id.empty() ? app_id_ : app_id;
}
std::string CurrentApplication::GetPackageId() const {
ScopeLogger();
- return package_id_;
+ auto pkg_id = GetRuntimeVariable("package_id");
+ LoggerI("GetRuntimeVariable: cached package_id: %s, runtime package_id: %s", package_id_.c_str(), pkg_id.c_str());
+ return pkg_id.empty() ? package_id_ : pkg_id;
}
std::string CurrentApplication::GetRoot() const {
ScopeLogger();
- return root_;
+ auto app_root = GetRuntimeVariable("app_root");
+ LoggerI("GetRuntimeVariable: cached app_root: %s, runtime app_root: %s", root_.c_str(), app_root.c_str());
+ return app_root.empty() ? root_ : app_root;
}
CurrentApplication::CurrentApplication()
return NULL;
}
+// static
+std::string Extension::GetRuntimeVariableString(const char* var_name) {
+ ScopeLogger();
+ if (!g_runtime) return "";
+
+ const int result_len = 1024;
+ std::vector<char> res(result_len + 1, 0);
+ g_runtime->GetRuntimeVariableString(0, var_name, &res[0], result_len);
+ LoggerI("GetRuntimeVariable: result %s: \"%s\"", var_name, &res[0]);
+ return std::string(res.data());
+}
+
std::string Extension::GetRuntimeVariable(const char* var_name, unsigned len) {
ScopeLogger();
if (!g_runtime) return "";
virtual Instance* CreateInstance();
- std::string GetRuntimeVariable(const char* var_name, unsigned len);
+ std::string GetRuntimeVariable(const char* var_name, unsigned len = 512);
+ static std::string GetRuntimeVariableString(const char* var_name);
private:
friend int32_t(::XW_Initialize)(XW_Extension extension, XW_GetInterface get_interface);