Skip to content

Commit

Permalink
[Tizen] Check app options by iterate over given set (#23634)
Browse files Browse the repository at this point in the history
Instead of iterating over available options and trying to get them from
app extra data, iterate over extra data and match them with available
options. This approach will fix errors generated by Tizen API call
app_control_get_extra_data() when used with not available key.
  • Loading branch information
arkq authored Nov 17, 2022
1 parent 406bdfe commit 6221fe1
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions examples/platform/tizen/OptionsProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <cstring>

#include <app_control.h>

#include <platform/CHIPDeviceBuildConfig.h>

namespace {
Expand Down Expand Up @@ -65,35 +67,50 @@ static constexpr Option sOptions[] = {
#endif
};

}; // namespace

void OptionsProxy::Parse(const char * argv0, app_control_h app_control)
bool ParseAppExtraData(app_control_h app_control, const char * key, void * userData)
{
// Insert argv[0] commonly used as a process name
if (argv0 != nullptr)
{
mArgs.push_back(argv0);
}
auto * args = static_cast<std::vector<std::string> *>(userData);

for (const auto & option : sOptions)
{
if (strcmp(key, option.name) != 0)
{
continue;
}

char * value = nullptr;
if (app_control_get_extra_data(app_control, option.name, &value) == APP_CONTROL_ERROR_NONE && value != nullptr)
{
if (!option.isBoolean)
{
mArgs.push_back(std::string("--") + option.name);
mArgs.push_back(value);
args->push_back(std::string("--") + option.name);
args->push_back(value);
}
else if (strcmp(value, "true") == 0)
{
mArgs.push_back(std::string("--") + option.name);
args->push_back(std::string("--") + option.name);
}
// Release memory allocated by app_control_get_extra_data()
free(value);
}
}

// Continue iterating over all extra data
return true;
}

}; // namespace

void OptionsProxy::Parse(const char * argv0, app_control_h app_control)
{
// Insert argv[0] commonly used as a process name
if (argv0 != nullptr)
{
mArgs.push_back(argv0);
}

app_control_foreach_extra_data(app_control, ParseAppExtraData, &mArgs);

// Convert vector of strings into NULL-terminated vector of char pointers
mArgv.reserve(mArgs.size() + 1);
for (auto & arg : mArgs)
Expand Down

0 comments on commit 6221fe1

Please sign in to comment.