Skip to content

Commit

Permalink
[thread-host] make AddThreadStateChangedCallback as a ThreadHost API (#…
Browse files Browse the repository at this point in the history
…2587)

This commit adds `AddThreadStateChangedCallback` as a `ThreadHost`
API.

Because this method is also needed under NCP mode. The commit doesn't
change the implementation in RcpHost and adds an empty implementation
in NcpHost.
  • Loading branch information
Irving-cl authored Nov 6, 2024
1 parent ad4c611 commit 7a79c99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ void NcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMa
mTaskRunner.Post([aReceiver](void) { aReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); });
}

void NcpHost::AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback)
{
// TODO: Implement AddThreadStateChangedCallback under NCP mode.
OT_UNUSED_VARIABLE(aCallback);
}

void NcpHost::Process(const MainloopContext &aMainloop)
{
mSpinelDriver.Process(&aMainloop);
Expand Down
1 change: 1 addition & 0 deletions src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkPr
void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) override;
void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) override;
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) override;
CoprocessorType GetCoprocessorType(void) override { return OT_COPROCESSOR_NCP; }
const char *GetCoprocessorVersion(void) override;
const char *GetInterfaceName(void) const override { return mConfig.mInterfaceName; }
Expand Down
10 changes: 1 addition & 9 deletions src/ncp/rcp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class OtNetworkProperties : virtual public NetworkProperties
class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkProperties
{
public:
using ThreadStateChangedCallback = std::function<void(otChangedFlags aFlags)>;

/**
* This constructor initializes this object.
*
Expand Down Expand Up @@ -152,13 +150,6 @@ class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkPro
*/
void RegisterResetHandler(std::function<void(void)> aHandler);

/**
* This method adds a event listener for Thread state changes.
*
* @param[in] aCallback The callback to receive Thread state changed events.
*/
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback);

/**
* This method resets the OpenThread instance.
*/
Expand Down Expand Up @@ -213,6 +204,7 @@ class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkPro
void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) override;
void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) override;
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) override;

CoprocessorType GetCoprocessorType(void) override
{
Expand Down
10 changes: 9 additions & 1 deletion src/ncp/thread_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class ThreadHost : virtual public NetworkProperties
using AsyncResultReceiver = std::function<void(otError, const std::string &)>;
using ChannelMasksReceiver =
std::function<void(uint32_t /*aSupportedChannelMask*/, uint32_t /*aPreferredChannelMask*/)>;
using DeviceRoleHandler = std::function<void(otError, otDeviceRole)>;
using DeviceRoleHandler = std::function<void(otError, otDeviceRole)>;
using ThreadStateChangedCallback = std::function<void(otChangedFlags aFlags)>;

struct ChannelMaxPower
{
Expand Down Expand Up @@ -201,6 +202,13 @@ class ThreadHost : virtual public NetworkProperties
virtual void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) = 0;

/**
* This method adds a event listener for Thread state changes.
*
* @param[in] aCallback The callback to receive Thread state changed events.
*/
virtual void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) = 0;

/**
* Returns the co-processor type.
*/
Expand Down

0 comments on commit 7a79c99

Please sign in to comment.