Skip to content

[device_info_plus] Minor code cleanup #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
#include <flutter/standard_method_codec.h>
#include <system_info.h>

#include <map>
#include <memory>
#include <string>

#include "log.h"

namespace {

class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
Expand Down Expand Up @@ -43,13 +46,11 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
const auto &method_name = method_call.method_name();

if (method_name == "getTizenDeviceInfo") {
char *value = nullptr;
flutter::EncodableMap map;

for (auto &request : requests_) {
const auto &map_key = request.first;
const auto &tizen_key = request.second;
for (const auto &[key, tizen_key] : tizen_keys_) {
auto response = flutter::EncodableValue();
char *value = nullptr;
int ret = system_info_get_platform_string(tizen_key.c_str(), &value);
if (ret == SYSTEM_INFO_ERROR_NONE) {
response = std::string(value);
Expand All @@ -58,7 +59,7 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
LOG_ERROR("Failed to get %s from the system: %s", tizen_key.c_str(),
get_error_message(ret));
}
map[flutter::EncodableValue(map_key)] = response;
map[flutter::EncodableValue(key)] = response;
}

result->Success(flutter::EncodableValue(map));
Expand All @@ -67,7 +68,7 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
}
}

const std::vector<std::pair<std::string, std::string>> requests_ = {
const std::map<std::string, std::string> tizen_keys_ = {
{"modelName", "http://tizen.org/system/model_name"},
{"cpuArch", "http://tizen.org/feature/platform.core.cpu.arch"},
{"nativeApiVersion",
Expand All @@ -90,6 +91,8 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
};
};

} // namespace

void DeviceInfoPlusTizenPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
DeviceInfoPlusTizenPlugin::RegisterWithRegistrar(
Expand Down