diff --git a/src/agent/application.cpp b/src/agent/application.cpp index 6d7499676bc..c9a5598f2ff 100644 --- a/src/agent/application.cpp +++ b/src/agent/application.cpp @@ -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); @@ -104,7 +104,7 @@ void Application::Init(void) mDBusAgent.Init(); #endif #if OTBR_ENABLE_VENDOR_SERVER - mVendorServer.Init(); + mVendorServer->Init(); #endif } diff --git a/src/agent/application.hpp b/src/agent/application.hpp index 9bfeee33e66..4d392c33063 100644 --- a/src/agent/application.hpp +++ b/src/agent/application.hpp @@ -147,7 +147,7 @@ class Application : private NonCopyable DBus::DBusAgent mDBusAgent; #endif #if OTBR_ENABLE_VENDOR_SERVER - vendor::VendorServer mVendorServer; + std::shared_ptr mVendorServer; #endif static std::atomic_bool sShouldTerminate; diff --git a/src/agent/vendor.hpp b/src/agent/vendor.hpp index 833072225ed..39912c9c0c5 100644 --- a/src/agent/vendor.hpp +++ b/src/agent/vendor.hpp @@ -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 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_