Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] generic vendor server #1995

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_executable(otbr-agent
application.cpp
main.cpp
uris.hpp
vendor.hpp
)

target_link_libraries(otbr-agent PRIVATE
Expand Down
8 changes: 4 additions & 4 deletions src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Application::Application(const std::string &aInterfaceName,
#if OTBR_ENABLE_DBUS_SERVER && OTBR_ENABLE_BORDER_AGENT
, mDBusAgent(mNcp, mBorderAgent.GetPublisher())
#endif
#if OTBR_ENABLE_ANDROID_OTDAEMON_SERVER
, mOtDaemonServer(ndk::SharedRefBase::make<Android::OtDaemonServer>())
#if OTBR_ENABLE_VENDOR_SERVER
, mVendorServer(vendor::VendorServer::newInstance(mNcp))
#endif
{
OTBR_UNUSED_VARIABLE(aRestListenAddress);
Expand All @@ -103,8 +103,8 @@ void Application::Init(void)
#if OTBR_ENABLE_DBUS_SERVER
mDBusAgent.Init();
#endif
#if OTBR_ENABLE_ANDROID_OTDAEMON_SERVER
mOtDaemonServer->InitOrDie(&mNcp);
#if OTBR_ENABLE_VENDOR_SERVER
mVendorServer->Init();
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#if OTBR_ENABLE_OPENWRT
#include "openwrt/ubus/otubus.hpp"
#endif
#if OTBR_ENABLE_ANDROID_OTDAEMON_SERVER
#include "android/otdaemon_server.hpp"
#if OTBR_ENABLE_VENDOR_SERVER
#include "agent/vendor.hpp"
#endif
#include "utils/infra_link_selector.hpp"

Expand Down Expand Up @@ -146,8 +146,8 @@ class Application : private NonCopyable
#if OTBR_ENABLE_DBUS_SERVER
DBus::DBusAgent mDBusAgent;
#endif
#if OTBR_ENABLE_ANDROID_OTDAEMON_SERVER
std::shared_ptr<Android::OtDaemonServer> mOtDaemonServer;
#if OTBR_ENABLE_VENDOR_SERVER
std::shared_ptr<vendor::VendorServer> mVendorServer;
#endif

static std::atomic_bool sShouldTerminate;
Expand Down
74 changes: 74 additions & 0 deletions src/agent/vendor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2021, The OpenThread Authors.
wgtdkp marked this conversation as resolved.
Show resolved Hide resolved
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* @file
* This file includes definitions of the vendor server. The implementation of the
* vendor server should be implemented by users.
*/
#ifndef OTBR_AGENT_VENDOR_HPP_
#define OTBR_AGENT_VENDOR_HPP_

#include "openthread-br/config.h"

#include "ncp/ncp_openthread.hpp"

namespace otbr {
namespace vendor {

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

/**
* Creates a new instance of VendorServer.
*
* Custom vendor servers should implement this method to return an object of the derived class.
wgtdkp marked this conversation as resolved.
Show resolved Hide resolved
*
* @param[in] aNcp The OpenThread controller object.
*
* @returns New derived VendorServer instance.
*/
static std::shared_ptr<VendorServer> newInstance(otbr::Ncp::ControllerOpenThread &aNcp);

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

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

/**
* This method get mInstance pointer.
*
* @retval The pointer of mInstance.
* Returns an OpenThread instance.
*
* @retval Non-null OpenThread instance if `ControllerOpenThread::Init()` has been called.
* Otherwise, it's guaranteed to be `null`
*/
otInstance *GetInstance(void)
{
assert(mInstance != nullptr);
return mInstance;
}
otInstance *GetInstance(void) { return mInstance; }

/**
* This method gets the thread functionality helper.
Expand Down