-
Notifications
You must be signed in to change notification settings - Fork 51
[audioplayers] Refactor the C++ code #357
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
[audioplayers] Refactor the C++ code #357
Conversation
@swift-kim @bbrto21 For functions that doesn't return any values but may throws exceptions, the code can be changed like this: void Func(){
ret = tizen_native_api();
if(ret != ERROR_NONE) throw Exception();
}
// To:
bool Func(){
ret = tizen_native_api();
if(ret != ERROR_NONE) {
// Detailed error can be checked by `last_error_`.
last_error_ = ret;
return false;
}
return true;
} But what about functions that return a value? For example GetPlayerState? How does the caller know if the return value is valid or not? Should I wrap Out parameters may also be used but is it common in C++? I know it's commonly used in C but I haven't seen much in C++. Any suggestions? |
@HakkyuKim Although it's Google's internal convention to not use exceptions in their code, it would be good to keep that convention in our code because we also depend on their code. However, it's up to your decision. If you decide not to use exceptions, there are several options. One is the way I used in my previous PRs, that is, using a result type that can represent an error state. The type can be either an enum class (has a bool func(std::string *out_value) {
char* result;
int ret = tizen_native_api(&result);
if (not success) {
last_error_ = ret;
return false;
}
*out_value = std::string(result);
return true;
} However, if you think repeating Another solution is to make the function take an error callback as an argument. You can use this approach if it makes most sense to you. typedef std::function<void(int)> ErrorCallback;
void func(ErrorCallback on_error) {
...
if (error) {
on_error(ret);
}
}
func([&](int ret) -> void {
result_->Error(std::to_string(ret), get_error_message(ret));
}); |
As far as I know, flutter-tizen is not using an explicit compile option( |
@swift-kim @bbrto21 @wanchao-xu
|
c6bef8c
to
121e056
Compare
@swift-kim |
2ec57ca
to
2e15bbf
Compare
Hmmm don't know what's causing integration test to fail for audioplayers, same failure happens in master branch so it's not related to this PR change. This PR doesn't have the changes in #360 so it's not related to that either. I'll check. |
The GitHub connection in the company is extremely slow today.
You may need to set a larger timeout value, or the artifacts should be downloaded in advance before the test is run (maybe using the |
0b8e0fb
to
fc31a7c
Compare
- Make internal linkages with unnamed namespace. - Use `const` instead of `#define` for constants. - Relocate constructor logic to RegisterWithRegistrar. - Use helper function `GetValueFromEncodableMap`. - Use `enum class` instead of `enum`. - Some naming changes. - Remove unnecessary logging. - Initialize private variables inline rather than in constructor. - Move `HandleResult` from AudioPlayer's memeber to internal.
Also: - Avoid c-style cast syntax. - Declare local variable just before use. - Remove unnecessary LOG_ERRORs. - Rename method OnErrorOccurred -> OnError. - Add newline at the end.
Also: - Remove unused header cassert. - Explicitly add used headers. - Add return statements appropriately. - Minor cleanups.
- Rename callback function: StartPlayingListener -> UpdatePositionListener.
- Call result->Success() in every if block to clarify execution path.
- Remove unused log.h include.
- Use ouput parameters for methods that return values. - Use exceptions only in HandleMethodCall.
This reverts commit 937be20.
@flutter-tizen/maintainers |
4e45da3
to
3046392
Compare
This reverts commit c69d799.
3046392
to
c8a3403
Compare
After discussing with @swift-kim, we've decided reverting back to using exceptions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice! Thank you for the hard work.
Please do some testing on TV device/emulator before releasing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for hard work.
There are some issues with audioplayers when running on TV (Not new ones from this PR, the problems existed in previous code), the main cause is calling |
ecfb3f6
to
f121745
Compare
Part of the code refactoring project.
Summary
const
instead of#define
for constants.GetValueFromEncodableMap
.enum class
instead ofenum
.HandleResult
from AudioPlayer's memeber to internal free function.