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)

Change-Id: Ic322efbee9b58d7a2743c72a511572ec7ebfb262
  • Loading branch information
wgtdkp committed Sep 4, 2023
1 parent 19cca1b commit 76837f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 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
20 changes: 8 additions & 12 deletions src/agent/vendor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,21 @@ class VendorServer
{
public:
/**
* 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_

0 comments on commit 76837f7

Please sign in to comment.