-
Notifications
You must be signed in to change notification settings - Fork 565
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
oboe: add ErrorOrValue dual return #63
Conversation
For returning an error code and a frame count, or other value, at the same time.
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.
I would also like to see a test for ErrorOrValue
class.
include/oboe/ErrorOrValue.h
Outdated
@@ -0,0 +1,58 @@ | |||
/* | |||
* Copyright (C) 2016 The Android Open Source Project |
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.
2018
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.
Done
include/oboe/ErrorOrValue.h
Outdated
|
||
/** | ||
* Quick way to check for an error. | ||
* @return true if an error occurred // TODO does this seem backwards? |
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.
To me, "backwards" seems more natural:
if (!write(...)) { // handle error }
Thus, operator! should return 'true' if there was an error.
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.
Done
include/oboe/ErrorOrValue.h
Outdated
, mError(error) {} | ||
|
||
explicit ErrorOrValue(T value) | ||
: mValue(value < 0 ? 0 : value) |
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.
That's not generic. What if 'T' is bool, or a string? In fact, it's the responsibility of the function that returns ErrorOrValue to determine the error condition, and use the appropriate type to pass to the constructor. If the constructor that takes 'T' is used, ErrorOrValue should assume that it was a success.
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.
Done
} | ||
|
||
T value() const { | ||
return mValue; |
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.
Should check if there is no error, and emit a log message.
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.
Why?
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.
Might be useful if a programmer claims that "oboe doesn't work," and then from the logs it turns out they are not checking the result, and there was an error. Treble for example has even stronger checks where retrieving the value crashes if the error status hasn't been checked before value retrieval. But that feels a bit too harsh, a simple log should be enough.
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.
@mnaganov - I do not understand this request. Do you want to log every access to the value?!
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.
Only if there was an error (mError != OK). Accessing the value if there was an error indicates a problem with client code.
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.
I see. Good idea. #76
src/aaudio/AudioStreamAAudio.cpp
Outdated
return mLibLoader->stream_write(mAAudioStream, buffer, numFrames, timeoutNanoseconds); | ||
int32_t result = mLibLoader->stream_write(mAAudioStream, buffer, | ||
numFrames, timeoutNanoseconds); | ||
return ErrorOrValue<int32_t>(result); |
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.
As I've noted, it's the responsibility of AudioStreamAAudio::write
to implement the logic that considers whether the value of result
indicates an error or not. ErrorOrValue
must not know these details.
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.
Done
Inverted boolean operators. More generic constructors.
} | ||
|
||
T value() const { | ||
return mValue; |
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.
Might be useful if a programmer claims that "oboe doesn't work," and then from the logs it turns out they are not checking the result, and there was an error. Treble for example has even stronger checks where retrieving the value crashes if the error status hasn't been checked before value retrieval. But that feels a bit too harsh, a simple log should be enough.
@@ -98,23 +98,23 @@ int64_t AudioStreamBuffered::predictNextCallbackTime() { | |||
// TODO: Consider returning an error_or_value struct instead. |
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.
Nit: Remove this comment now method returns ErrorOrValue
For returning an error code and a frame count, or other value, at the same time.