[cli] move output format to server (#3502)

This commit is contained in:
Yakun Xu
2019-01-24 09:02:23 -08:00
committed by Jonathan Hui
parent 65db853abc
commit eeff2e225c
6 changed files with 41 additions and 81 deletions
-12
View File
@@ -88,17 +88,5 @@ int Console::Output(const char *aBuf, uint16_t aBufLength)
return mCallback(aBuf, aBufLength, mContext);
}
int Console::OutputFormat(const char *fmt, ...)
{
char buf[kMaxLineLength];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
} // namespace Cli
} // namespace ot
-16
View File
@@ -70,17 +70,6 @@ public:
*/
virtual int Output(const char *aBuf, uint16_t aBufLength);
/**
* This method delivers formatted output to the client.
*
* @param[in] aFmt A pointer to the format string.
* @param[in] ... A variable list of arguments to format.
*
* @returns The number of bytes placed in the output queue.
*
*/
virtual int OutputFormat(const char *fmt, ...);
/**
* This method sets a callback that is called when console has some output.
*
@@ -100,11 +89,6 @@ public:
void ReceiveTask(char *aBuf, uint16_t aBufLength);
private:
enum
{
kMaxLineLength = 128,
};
otCliConsoleOutputCallback mCallback;
void * mContext;
};
+22 -1
View File
@@ -36,7 +36,28 @@
namespace ot {
namespace Cli {
Server *Server::sServer;
Server *Server::sServer = NULL;
int Server::OutputFormat(const char *aFormat, ...)
{
int rval;
va_list ap;
va_start(ap, aFormat);
rval = OutputFormatV(aFormat, ap);
va_end(ap);
return rval;
}
int Server::OutputFormatV(const char *aFormat, va_list aArguments)
{
char buf[kMaxLineLength];
vsnprintf(buf, sizeof(buf), aFormat, aArguments);
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
} // namespace Cli
} // namespace ot
+17 -6
View File
@@ -51,7 +51,6 @@ public:
Server(Instance *aInstance)
: mInterpreter(aInstance)
{
;
}
/**
@@ -83,11 +82,18 @@ public:
* @retval -1 Driver is broken.
*
*/
virtual int OutputFormat(const char *aFormat, ...)
{
OT_UNUSED_VARIABLE(aFormat);
return -1;
}
int OutputFormat(const char *aFormat, ...);
/**
* This method delivers formatted output to the client.
*
* @param[in] aFormat A pointer to the format string.
* @param[in] aArguments A variable list of arguments for format.
*
* @returns The number of bytes placed in the output queue.
*
*/
int OutputFormatV(const char *aFormat, va_list aArguments);
/**
* This method returns a reference to the interpreter object.
@@ -100,6 +106,11 @@ public:
static Server *sServer;
protected:
enum
{
kMaxLineLength = OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH,
};
Interpreter mInterpreter;
};
-21
View File
@@ -288,27 +288,6 @@ int Uart::Output(const char *aBuf, uint16_t aBufLength)
return aBufLength;
}
int Uart::OutputFormat(const char *fmt, ...)
{
char buf[kMaxLineLength];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
int Uart::OutputFormatV(const char *aFmt, va_list aAp)
{
char buf[kMaxLineLength];
vsnprintf(buf, sizeof(buf), aFmt, aAp);
return Output(buf, static_cast<uint16_t>(strlen(buf)));
}
void Uart::Send(void)
{
VerifyOrExit(mSendLength == 0);
+2 -25
View File
@@ -70,37 +70,14 @@ public:
*/
virtual int Output(const char *aBuf, uint16_t aBufLength);
/**
* This method delivers formatted output to the client.
*
* @param[in] aFmt A pointer to the format string.
* @param[in] ... A variable list of arguments to format.
*
* @returns The number of bytes placed in the output queue.
*
*/
virtual int OutputFormat(const char *fmt, ...);
/**
* This method delivers formatted output to the client.
*
* @param[in] aFmt A pointer to the format string.
* @param[in] aAp A variable list of arguments for format.
*
* @returns The number of bytes placed in the output queue.
*
*/
int OutputFormatV(const char *aFmt, va_list aAp);
void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength);
void SendDoneTask(void);
private:
enum
{
kRxBufferSize = OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
kTxBufferSize = OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE,
kMaxLineLength = OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH,
kRxBufferSize = OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
kTxBufferSize = OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE,
};
otError ProcessCommand(void);