Skip to content

Commit 6221fe1

Browse files
authored
[Tizen] Check app options by iterate over given set (project-chip#23634)
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.
1 parent 406bdfe commit 6221fe1

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

examples/platform/tizen/OptionsProxy.cpp

+28-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <cstring>
2222

23+
#include <app_control.h>
24+
2325
#include <platform/CHIPDeviceBuildConfig.h>
2426

2527
namespace {
@@ -65,35 +67,50 @@ static constexpr Option sOptions[] = {
6567
#endif
6668
};
6769

68-
}; // namespace
69-
70-
void OptionsProxy::Parse(const char * argv0, app_control_h app_control)
70+
bool ParseAppExtraData(app_control_h app_control, const char * key, void * userData)
7171
{
72-
// Insert argv[0] commonly used as a process name
73-
if (argv0 != nullptr)
74-
{
75-
mArgs.push_back(argv0);
76-
}
72+
auto * args = static_cast<std::vector<std::string> *>(userData);
7773

7874
for (const auto & option : sOptions)
7975
{
76+
if (strcmp(key, option.name) != 0)
77+
{
78+
continue;
79+
}
80+
8081
char * value = nullptr;
8182
if (app_control_get_extra_data(app_control, option.name, &value) == APP_CONTROL_ERROR_NONE && value != nullptr)
8283
{
8384
if (!option.isBoolean)
8485
{
85-
mArgs.push_back(std::string("--") + option.name);
86-
mArgs.push_back(value);
86+
args->push_back(std::string("--") + option.name);
87+
args->push_back(value);
8788
}
8889
else if (strcmp(value, "true") == 0)
8990
{
90-
mArgs.push_back(std::string("--") + option.name);
91+
args->push_back(std::string("--") + option.name);
9192
}
9293
// Release memory allocated by app_control_get_extra_data()
9394
free(value);
9495
}
9596
}
9697

98+
// Continue iterating over all extra data
99+
return true;
100+
}
101+
102+
}; // namespace
103+
104+
void OptionsProxy::Parse(const char * argv0, app_control_h app_control)
105+
{
106+
// Insert argv[0] commonly used as a process name
107+
if (argv0 != nullptr)
108+
{
109+
mArgs.push_back(argv0);
110+
}
111+
112+
app_control_foreach_extra_data(app_control, ParseAppExtraData, &mArgs);
113+
97114
// Convert vector of strings into NULL-terminated vector of char pointers
98115
mArgv.reserve(mArgs.size() + 1);
99116
for (auto & arg : mArgs)

0 commit comments

Comments
 (0)