Skip to content
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

Merged
merged 2 commits into from
Mar 27, 2018
Merged

oboe: add ErrorOrValue dual return #63

merged 2 commits into from
Mar 27, 2018

Conversation

philburk
Copy link
Collaborator

For returning an error code and a frame count, or other value, at the same time.

For returning an error code and a frame count, or other value, at the same time.
Copy link
Collaborator

@mnaganov mnaganov left a 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.

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2016 The Android Open Source Project
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Quick way to check for an error.
* @return true if an error occurred // TODO does this seem backwards?
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

, mError(error) {}

explicit ErrorOrValue(T value)
: mValue(value < 0 ? 0 : value)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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?!

Copy link
Collaborator

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.

Copy link
Collaborator Author

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

return mLibLoader->stream_write(mAAudioStream, buffer, numFrames, timeoutNanoseconds);
int32_t result = mLibLoader->stream_write(mAAudioStream, buffer,
numFrames, timeoutNanoseconds);
return ErrorOrValue<int32_t>(result);
Copy link
Collaborator

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.

Copy link
Collaborator Author

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;
Copy link
Collaborator

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.
Copy link
Collaborator

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

@dturner dturner merged commit 7c19352 into master Mar 27, 2018
@dturner dturner deleted the dualreturn branch March 27, 2018 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants