libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::STDIO Class Reference

STDIO interface for read/write ports. More...

#include <libxr_rw.hpp>

Collaboration diagram for LibXR::STDIO:

Static Public Member Functions

static int Printf (const char *fmt,...)
 Prints a formatted string to the write port (like printf).
 

Static Public Attributes

static ReadPortread_ = nullptr
 Read port instance. 读取端口。
 
static WritePortwrite_ = nullptr
 Write port instance. 写入端口。
 

Detailed Description

STDIO interface for read/write ports.

提供静态全局的输入输出接口绑定与缓冲区管理。

Definition at line 689 of file libxr_rw.hpp.

Member Function Documentation

◆ Printf()

static int LibXR::STDIO::Printf ( const char fmt,
  ... 
)
inlinestatic

Prints a formatted string to the write port (like printf).

将格式化字符串发送至写入端口,类似 printf。

Parameters
fmtThe format string. 格式化字符串。
...Variable arguments to be formatted. 需要格式化的参数。
Returns
Number of characters written, or negative on error. 成功返回写入的字符数,失败返回负数。

Definition at line 710 of file libxr_rw.hpp.

711 {
712#if LIBXR_PRINTF_BUFFER_SIZE > 0
713 if (!STDIO::write_ || !STDIO::write_->Writable())
714 {
715 return -1;
716 }
717
718 static LibXR::Mutex mutex; // NOLINT
719
721
723 va_start(args, fmt);
724 int len = vsnprintf(STDIO::printf_buff_, LIBXR_PRINTF_BUFFER_SIZE, fmt, args);
725 va_end(args);
726
727 // Check result and limit length
728 if (len < 0)
729 {
730 return -1;
731 }
732 if (static_cast<size_t>(len) >= LIBXR_PRINTF_BUFFER_SIZE)
733 {
735 }
736
737 ConstRawData data = {reinterpret_cast<const uint8_t *>(STDIO::printf_buff_),
738 static_cast<size_t>(len)};
739
740 static WriteOperation op; // NOLINT
741 return static_cast<int>(STDIO::write_->operator()(data, op));
742#else
743 UNUSED(fmt);
744 return 0;
745#endif
746 }
互斥锁的 RAII 机制封装 (RAII-style mechanism for automatic mutex management).
Definition mutex.hpp:95
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
Definition mutex.hpp:18
static WritePort * write_
Write port instance. 写入端口。
Definition libxr_rw.hpp:694
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
Operation< ErrorCode > WriteOperation
Write operation type.
Definition libxr_rw.hpp:271

Field Documentation

◆ read_

ReadPort* LibXR::STDIO::read_ = nullptr
inlinestatic

Read port instance. 读取端口。

Definition at line 693 of file libxr_rw.hpp.

◆ write_

WritePort* LibXR::STDIO::write_ = nullptr
inlinestatic

Write port instance. 写入端口。

Definition at line 694 of file libxr_rw.hpp.


The documentation for this class was generated from the following file: