mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[cli] move public C APIs to dedicated cli_api.cpp (#13016)
This commit moves the public C APIs for the CLI from `cli.cpp` to a new dedicated file `cli_api.cpp`.
This commit is contained in:
committed by
GitHub
parent
7650ecca55
commit
54dd6f0e7a
@@ -30,6 +30,7 @@ import("../../etc/gn/openthread.gni")
|
||||
openthread_cli_sources = [
|
||||
"cli.cpp",
|
||||
"cli.hpp",
|
||||
"cli_api.cpp",
|
||||
"cli_ba.cpp",
|
||||
"cli_ba.hpp",
|
||||
"cli_bbr.cpp",
|
||||
|
||||
@@ -33,6 +33,7 @@ set(COMMON_INCLUDES
|
||||
|
||||
set(COMMON_SOURCES
|
||||
cli.cpp
|
||||
cli_api.cpp
|
||||
cli_ba.cpp
|
||||
cli_bbr.cpp
|
||||
cli_br.cpp
|
||||
|
||||
@@ -8826,54 +8826,5 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
|
||||
return error;
|
||||
}
|
||||
|
||||
extern "C" void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
|
||||
{
|
||||
Interpreter::Initialize(aInstance, aCallback, aContext);
|
||||
|
||||
#if OPENTHREAD_CONFIG_CLI_VENDOR_COMMANDS_ENABLE && OPENTHREAD_CONFIG_CLI_MAX_USER_CMD_ENTRIES > 1
|
||||
otCliVendorSetUserCommands();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void otCliInputLine(char *aBuf) { Interpreter::GetInterpreter().ProcessLine(aBuf); }
|
||||
|
||||
extern "C" otError otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength, void *aContext)
|
||||
{
|
||||
return Interpreter::GetInterpreter().SetUserCommands(aUserCommands, aLength, aContext);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength)
|
||||
{
|
||||
Interpreter::GetInterpreter().OutputBytes(aBytes, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputFormat(const char *aFmt, ...)
|
||||
{
|
||||
va_list aAp;
|
||||
va_start(aAp, aFmt);
|
||||
Interpreter::GetInterpreter().OutputFormatV(aFmt, aAp);
|
||||
va_end(aAp);
|
||||
}
|
||||
|
||||
extern "C" void otCliAppendResult(otError aError) { Interpreter::GetInterpreter().OutputResult(aError); }
|
||||
|
||||
extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
VerifyOrExit(Interpreter::IsInitialized());
|
||||
|
||||
// CLI output is being used for logging, so we set the flag
|
||||
// `EmittingCommandOutput` to false indicate this.
|
||||
Interpreter::GetInterpreter().SetEmittingCommandOutput(false);
|
||||
Interpreter::GetInterpreter().OutputFormatV(aFormat, aArgs);
|
||||
Interpreter::GetInterpreter().OutputNewLine();
|
||||
Interpreter::GetInterpreter().SetEmittingCommandOutput(true);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
@@ -89,7 +89,6 @@
|
||||
namespace ot {
|
||||
|
||||
/**
|
||||
* @namespace ot::Cli
|
||||
*
|
||||
* @brief
|
||||
* This namespace contains definitions for the CLI interpreter.
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2026, 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 implements the CLI public APIs.
|
||||
*/
|
||||
|
||||
#include <openthread/cli.h>
|
||||
|
||||
#include "cli.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
extern "C" void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
|
||||
{
|
||||
Interpreter::Initialize(aInstance, aCallback, aContext);
|
||||
|
||||
#if OPENTHREAD_CONFIG_CLI_VENDOR_COMMANDS_ENABLE && OPENTHREAD_CONFIG_CLI_MAX_USER_CMD_ENTRIES > 1
|
||||
otCliVendorSetUserCommands();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void otCliInputLine(char *aBuf) { Interpreter::GetInterpreter().ProcessLine(aBuf); }
|
||||
|
||||
extern "C" otError otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength, void *aContext)
|
||||
{
|
||||
return Interpreter::GetInterpreter().SetUserCommands(aUserCommands, aLength, aContext);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength)
|
||||
{
|
||||
Interpreter::GetInterpreter().OutputBytes(aBytes, aLength);
|
||||
}
|
||||
|
||||
extern "C" void otCliOutputFormat(const char *aFmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, aFmt);
|
||||
Interpreter::GetInterpreter().OutputFormatV(aFmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
extern "C" void otCliAppendResult(otError aError) { Interpreter::GetInterpreter().OutputResult(aError); }
|
||||
|
||||
extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
VerifyOrExit(Interpreter::IsInitialized());
|
||||
|
||||
// CLI output is being used for logging, so we set the flag
|
||||
// `EmittingCommandOutput` to false indicate this.
|
||||
Interpreter::GetInterpreter().SetEmittingCommandOutput(false);
|
||||
Interpreter::GetInterpreter().OutputFormatV(aFormat, aArgs);
|
||||
Interpreter::GetInterpreter().OutputNewLine();
|
||||
Interpreter::GetInterpreter().SetEmittingCommandOutput(true);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
@@ -46,6 +46,7 @@ target_include_directories(openthread-cli-radio PUBLIC ${OT_PUBLIC_INCLUDES} PRI
|
||||
target_sources(openthread-cli-radio
|
||||
PRIVATE
|
||||
cli.cpp
|
||||
cli_api.cpp
|
||||
cli_logging.cpp
|
||||
cli_utils.cpp
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user