[posix] add spinel driver getter to allow external app to access (#10272)

This commit is contained in:
Li Cao
2024-05-21 13:25:12 -07:00
committed by GitHub
parent 153e2567cd
commit 71bd98744c
4 changed files with 68 additions and 12 deletions
+2 -1
View File
@@ -41,6 +41,7 @@
#include "common/code_utils.hpp"
#include "common/new.hpp"
#include "posix/platform/radio.hpp"
#include "posix/platform/spinel_driver_getter.hpp"
#include "posix/platform/spinel_manager.hpp"
#include "utils/parse_cmdline.hpp"
@@ -89,7 +90,7 @@ void Radio::Init(const char *aUrl)
skipCompatibilityCheck = mRadioUrl.HasParam("skip-rcp-compatibility-check");
mRadioSpinel.SetCallbacks(callbacks);
mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &SpinelManager::GetSpinelDriver());
mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &GetSpinelDriver());
ProcessRadioUrl(mRadioUrl);
}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2024, The OpenThread Authors.
* 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 is used to expose the API to the external posix app so that the
* app can access to the posix spinel driver.
*
*/
#ifndef POSIX_PLATFORM_SPINEL_DRIVER_GETTER_HPP_
#define POSIX_PLATFORM_SPINEL_DRIVER_GETTER_HPP_
#include "lib/spinel/spinel_driver.hpp"
namespace ot {
namespace Posix {
/**
* Returns the static instance of the SpinelDriver.
*
*/
extern Spinel::SpinelDriver &GetSpinelDriver(void);
} // namespace Posix
} // namespace ot
#endif // POSIX_PLATFORM_SPINEL_DRIVER_GETTER_HPP_
+7 -5
View File
@@ -36,6 +36,7 @@
#include "posix/platform/hdlc_interface.hpp"
#include "posix/platform/radio_url.hpp"
#include "posix/platform/spi_interface.hpp"
#include "posix/platform/spinel_driver_getter.hpp"
#include "posix/platform/vendor_interface.hpp"
static ot::Posix::SpinelManager sSpinelManager;
@@ -43,9 +44,10 @@ static ot::Posix::SpinelManager sSpinelManager;
namespace ot {
namespace Posix {
SpinelManager &SpinelManager::GetSpinelManager(void) { return sSpinelManager; }
// Implements `GetSpinelDriver` in spinel_driver_getter.hpp for external access to SpinelDriver
Spinel::SpinelDriver &GetSpinelDriver(void) { return sSpinelManager.GetSpinelDriver(); }
Spinel::SpinelDriver &SpinelManager::GetSpinelDriver(void) { return sSpinelManager.mSpinelDriver; }
SpinelManager &SpinelManager::GetSpinelManager(void) { return sSpinelManager; }
SpinelManager::SpinelManager(void)
: mUrl(nullptr)
@@ -201,14 +203,14 @@ void platformSpinelManagerDeinit(void) { return sSpinelManager.Deinit(); }
void virtualTimeSpinelProcess(otInstance *aInstance, const struct VirtualTimeEvent *aEvent)
{
OT_UNUSED_VARIABLE(aInstance);
ot::Posix::SpinelManager::GetSpinelDriver().Process(aEvent);
ot::Posix::GetSpinelDriver().Process(aEvent);
}
#else
void platformSpinelManagerProcess(otInstance *aInstance, const otSysMainloopContext *aContext)
{
OT_UNUSED_VARIABLE(aInstance);
ot::Posix::SpinelManager::GetSpinelDriver().Process(aContext);
ot::Posix::GetSpinelDriver().Process(aContext);
}
#endif // OPENTHREAD_POSIX_VIRTUAL_TIME
@@ -216,7 +218,7 @@ void platformSpinelManagerUpdateFdSet(otSysMainloopContext *aContext)
{
sSpinelManager.GetSpinelInterface().UpdateFdSet(aContext);
if (ot::Posix::SpinelManager::GetSpinelDriver().HasPendingFrame())
if (ot::Posix::GetSpinelDriver().HasPendingFrame())
{
aContext->mTimeout.tv_sec = 0;
aContext->mTimeout.tv_usec = 0;
+6 -6
View File
@@ -44,18 +44,18 @@ namespace Posix {
class SpinelManager
{
public:
/**
* Returns the static instance of the SpinelDriver.
*
*/
static Spinel::SpinelDriver &GetSpinelDriver(void);
/**
* Returns the static instance of the SpinelManager.
*
*/
static SpinelManager &GetSpinelManager(void);
/**
* Returns the static instance of the SpinelDriver.
*
*/
Spinel::SpinelDriver &GetSpinelDriver(void) { return mSpinelDriver; }
/**
* Constructor of the SpinelManager
*