Skip to content

Commit

Permalink
[utils] make generic VendorServer (#1995)
Browse files Browse the repository at this point in the history
This commit changes VendorServer to an abstract class so that it
can be extended to have different implementations.

Fulfills request from #1967 (comment)
  • Loading branch information
wgtdkp committed Sep 5, 2023
1 parent 19cca1b commit 666cbcb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Application::Application(const std::string &aInterfaceName,
, mDBusAgent(mNcp, mBorderAgent.GetPublisher())
#endif
#if OTBR_ENABLE_VENDOR_SERVER
, mVendorServer(mNcp)
, mVendorServer(vendor::VendorServer::newInstance(mNcp))
#endif
{
OTBR_UNUSED_VARIABLE(aRestListenAddress);
Expand All @@ -104,7 +104,7 @@ void Application::Init(void)
mDBusAgent.Init();
#endif
#if OTBR_ENABLE_VENDOR_SERVER
mVendorServer.Init();
mVendorServer->Init();
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Application : private NonCopyable
DBus::DBusAgent mDBusAgent;
#endif
#if OTBR_ENABLE_VENDOR_SERVER
vendor::VendorServer mVendorServer;
std::shared_ptr<vendor::VendorServer> mVendorServer;
#endif

static std::atomic_bool sShouldTerminate;
Expand Down
25 changes: 13 additions & 12 deletions src/agent/vendor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,30 @@
namespace otbr {
namespace vendor {

/**
* An interface for customized behavior depending on OpenThread API and state.
*/
class VendorServer
{
public:
virtual ~VendorServer(void) = default;

/**
* The constructor of vendor server.
*
* @param[in] aNcp A reference to the NCP controller.
* Creates a new instance of VendorServer.
*
* Custom vendor servers should implement this method to return an object of the derived class.
*/
VendorServer(otbr::Ncp::ControllerOpenThread &aNcp)
: mNcp(aNcp)
{
}
static std::shared_ptr<VendorServer> newInstance(otbr::Ncp::ControllerOpenThread &aNcp);

/**
* This method initializes the vendor server.
* Initializes the vendor server.
*
* This will be called by `Application::Init()` after OpenThread instance and other built-in
* servers have been created and initialized.
*/
void Init(void);

private:
otbr::Ncp::ControllerOpenThread &mNcp;
virtual void Init(void) = 0;
};

} // namespace vendor
} // namespace otbr
#endif // OTBR_AGENT_VENDOR_HPP_
7 changes: 3 additions & 4 deletions src/ncp/ncp_openthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ class ControllerOpenThread : public MainloopProcessor
void Deinit(void);

/**
* This method get mInstance pointer.
*
* @retval The pointer of mInstance.
* Returns an OpenThread instance.
*
* @retval The OpenThread instance if `ControllerOpenThread::Init()` has been called,
* otherwise `null`
*/
otInstance *GetInstance(void)
{
assert(mInstance != nullptr);
return mInstance;
}

Expand Down

0 comments on commit 666cbcb

Please sign in to comment.