[dbus] Add leader takeover and local leader weight API#2372
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2372 +/- ##
===========================================
- Coverage 55.77% 45.37% -10.41%
===========================================
Files 87 94 +7
Lines 6890 9931 +3041
Branches 0 749 +749
===========================================
+ Hits 3843 4506 +663
- Misses 3047 5206 +2159
- Partials 0 219 +219 ☔ View full report in Codecov by Sentry. |
|
This depends on if/when this OT PR merges openthread/openthread#9186 |
| auto threadHelper = mHost.GetThreadHelper(); | ||
| otError error = OT_ERROR_NONE; | ||
|
|
||
| SuccessOrExit(error = otThreadBecomeLeader(threadHelper->GetInstance())); |
There was a problem hiding this comment.
From the API doc, this should only be called when the device is attached. Could you add a check before issuing this call?
…e method to the LocalLeaderWeight property, in order to set the local leader weight
3022ab4 to
95dfb9b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for taking over as the partition leader and setting the local leader weight via DBus. Specifically, it introduces the TakeoverLeader method and updates the LocalLeaderWeight property to be writable. The feedback suggests simplifying the TakeoverLeaderHandler implementation by removing a redundant role check, as otThreadBecomeLeader already performs this validation internally.
| void DBusThreadObjectRcp::TakeoverLeaderHandler(DBusRequest &aRequest) | ||
| { | ||
| auto threadHelper = mHost.GetThreadHelper(); | ||
| otError error = OT_ERROR_NONE; | ||
| otDeviceRole role = otThreadGetDeviceRole(threadHelper->GetInstance()); | ||
|
|
||
| VerifyOrExit(role != OT_DEVICE_ROLE_DISABLED && role != OT_DEVICE_ROLE_DETACHED, error = OT_ERROR_INVALID_STATE); | ||
| SuccessOrExit(error = otThreadBecomeLeader(threadHelper->GetInstance())); | ||
|
|
||
| exit: | ||
| aRequest.ReplyOtResult(error); | ||
| } |
There was a problem hiding this comment.
The explicit role check in TakeoverLeaderHandler is redundant because otThreadBecomeLeader already performs this check internally and returns OT_ERROR_INVALID_STATE if the device is disabled or detached. We can simplify this handler by directly forwarding the result of otThreadBecomeLeader to ReplyOtResult, similar to other handlers like DetachHandler.
void DBusThreadObjectRcp::TakeoverLeaderHandler(DBusRequest &aRequest)
{
auto threadHelper = mHost.GetThreadHelper();
aRequest.ReplyOtResult(otThreadBecomeLeader(threadHelper->GetInstance()));
}
Adds DBus APIs to takeover leader role and to set the local leader weight