Skip to content

Conversation

@facchinm
Copy link
Contributor

@facchinm facchinm commented Sep 24, 2025

New calls will be in the form:

Bridge.call("test", 1, 2) -> returns true if the call succeeded, ignore the return

Bridge.call("test", 1, 2).result(c) -> stores the result in variable c, returns true if succeeded

Bridge.call("test", 1, 2).timeout(20) -> waits 20ms for the result, then returns fals if timeout is reached

Bridge.call("test", 1, 2).timeout(20).result(c) -> same but storing the result to variable c

Bridge.call("test", 1, 2).result(c, 20) -> same as previous call

  • Usages that do not held the expected behaviour:

Bridge.call("test", 1, 2).result(c).timeout(20) -> doesn't apply the timeout, waits forever

src/bridge.h Outdated
// Lock read mutex
if (_timeout < 0) _timeout = timeout_ms;
int start = millis();
while(true && (_timeout < 0 || (millis() - start) < _timeout)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant condition

Suggested change
while(true && (_timeout < 0 || (millis() - start) < _timeout)) {
while (_timeout < 0 || (millis() - start) < _timeout) {

src/bridge.h Outdated
Comment on lines 41 to 46
if (client->get_response(msg_id_wait, result)) {
k_mutex_unlock(read_mutex);
k_msleep(1);
break;
}
k_mutex_unlock(read_mutex);
k_msleep(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

fold k_mutex_unlock and k_msleep, to make the lock/unlock a bit more readable

Suggested change
if (client->get_response(msg_id_wait, result)) {
k_mutex_unlock(read_mutex);
k_msleep(1);
break;
}
k_mutex_unlock(read_mutex);
k_msleep(1);
auto gotResp = client->get_response(msg_id_wait, result);
k_mutex_unlock(read_mutex);
k_msleep(1);
if (gotResp) {
break;
}

New calls will be in the form:

Bridge.call("test", 1, 2) -> returns true if the call succeeded, ignore the return

Bridge.call("test", 1, 2).result(c) -> stores the result in variable c, returns true if succeeded

Bridge.call("test", 1, 2).timeout(20) -> waits 20ms for the result, then returns fals if timeout is reached

Bridge.call("test", 1, 2).timeout(20).result(c) -> same but storing the result to variable c

Bridge.call("test", 1, 2).result(c, 20) -> same as previous call

* Usages that do not held the expected behaviour:

Bridge.call("test", 1, 2).result(c).timeout(20) -> doesn't apply the timeout, waits forever
Copy link
Collaborator

@eigen-value eigen-value left a comment

Choose a reason for hiding this comment

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

I have a general concern about usability of the proposed solution.

src/bridge.h Outdated
k_yield();
}
}
return (client->lastError.code == NO_ERR) && (_timeout < 0 || (millis() - start) < _timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather rewrite this block so that the timeout condition is evaluated at the end of the loop.
This way we get the chance of forcing:

client->lastError.code = GENERIC_ERR;
client->lastError.message = "Timed out";

Then we could either return or break and leave the last line unmodified (saving yet another call to millis)

fix: RpcResult overloaded bool using a generic return type, not setting a timeout, can potentially execute result method multiple times
operator bool() {
char c;
return result(c);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This dummy result (c) call should pass a timeout or it will hang if the receiving end returns a type other than char

@eigen-value
Copy link
Collaborator

@gbr1 please test the last commit as I'm off today.
Just one thing I'm not sure of... Should the Bridge have a default timeout or not? (it doesn't for the moment)

@eigen-value
Copy link
Collaborator

@gbr1 should be ready to merge. plz test it though

Copy link
Collaborator

@gbr1 gbr1 left a comment

Choose a reason for hiding this comment

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

LGTM (finally - good luck to this PR)

@eigen-value eigen-value merged commit 1509a66 into main Sep 26, 2025
@eigen-value eigen-value deleted the new_call_api branch September 26, 2025 15:38
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.

5 participants