[agent] add application integration for VendorServer instead of NCP (#2017)
This allows VendorServer to visit application and all parts of
application through Get API. This addresses the issues like:
BorderAgent is not accessible from VendorServer.
diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake
index 9060bbb..a8d3905 100644
--- a/etc/cmake/options.cmake
+++ b/etc/cmake/options.cmake
@@ -146,3 +146,8 @@
else()
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_DHCP6_PD=0)
endif()
+
+option(OTBR_VENDOR_SERVER "Enable vendor server" OFF)
+if (OTBR_VENDOR_SERVER)
+ target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_VENDOR_SERVER=1)
+endif()
diff --git a/src/agent/application.cpp b/src/agent/application.cpp
index c9a5598..3369602 100644
--- a/src/agent/application.cpp
+++ b/src/agent/application.cpp
@@ -77,7 +77,7 @@
, mDBusAgent(mNcp, mBorderAgent.GetPublisher())
#endif
#if OTBR_ENABLE_VENDOR_SERVER
- , mVendorServer(vendor::VendorServer::newInstance(mNcp))
+ , mVendorServer(vendor::VendorServer::newInstance(*this))
#endif
{
OTBR_UNUSED_VARIABLE(aRestListenAddress);
diff --git a/src/agent/application.hpp b/src/agent/application.hpp
index 4d392c3..55b39ee 100644
--- a/src/agent/application.hpp
+++ b/src/agent/application.hpp
@@ -64,6 +64,14 @@
namespace otbr {
+#if OTBR_ENABLE_VENDOR_SERVER
+namespace vendor {
+
+class VendorServer;
+
+}
+#endif
+
/**
* @addtogroup border-router-agent
*
@@ -119,6 +127,73 @@
*/
otbrError Run(void);
+ /**
+ * Get the OpenThread controller object the application is using.
+ *
+ * @returns The OpenThread controller object.
+ */
+ Ncp::ControllerOpenThread &GetNcp(void) { return mNcp; }
+
+#if OTBR_ENABLE_BORDER_AGENT
+ /**
+ * Get the border agent the application is using.
+ *
+ * @returns The border agent.
+ */
+ BorderAgent &GetBorderAgent(void)
+ {
+ return mBorderAgent;
+ }
+#endif
+
+#if OTBR_ENABLE_BACKBONE_ROUTER
+ /**
+ * Get the backbone agent the application is using.
+ *
+ * @returns The backbone agent.
+ */
+ BackboneRouter::BackboneAgent &GetBackboneAgent(void)
+ {
+ return mBackboneAgent;
+ }
+#endif
+
+#if OTBR_ENABLE_OPENWRT
+ /**
+ * Get the UBus agent the application is using.
+ *
+ * @returns The UBus agent.
+ */
+ ubus::UBusAgent &GetUBusAgent(void)
+ {
+ return mUbusAgent;
+ }
+#endif
+
+#if OTBR_ENABLE_REST_SERVER
+ /**
+ * Get the rest web server the application is using.
+ *
+ * @returns The rest web server.
+ */
+ rest::RestWebServer &GetRestWebServer(void)
+ {
+ return mRestWebServer;
+ }
+#endif
+
+#if OTBR_ENABLE_DBUS_SERVER
+ /**
+ * Get the DBus agent the application is using.
+ *
+ * @returns The DBus agent.
+ */
+ DBus::DBusAgent &GetDBusAgent(void)
+ {
+ return mDBusAgent;
+ }
+#endif
+
private:
// Default poll timeout.
static const struct timeval kPollTimeout;
diff --git a/src/agent/vendor.hpp b/src/agent/vendor.hpp
index 3df4987..8e2ecb3 100644
--- a/src/agent/vendor.hpp
+++ b/src/agent/vendor.hpp
@@ -36,9 +36,12 @@
#include "openthread-br/config.h"
-#include "ncp/ncp_openthread.hpp"
+#include "agent/application.hpp"
namespace otbr {
+
+class Application;
+
namespace vendor {
/**
@@ -54,11 +57,11 @@
*
* Custom vendor servers should implement this method to return an object of the derived class.
*
- * @param[in] aNcp The OpenThread controller object.
+ * @param[in] aApplication The OTBR application.
*
* @returns New derived VendorServer instance.
*/
- static std::shared_ptr<VendorServer> newInstance(otbr::Ncp::ControllerOpenThread &aNcp);
+ static std::shared_ptr<VendorServer> newInstance(Application &aApplication);
/**
* Initializes the vendor server.