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:
[legend]

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. 写入端口。
 
static LibXR::Mutexwrite_mutex_
 Write port mutex. 写入端口互斥锁。
 
static LibXR::WritePort::Streamwrite_stream_ = nullptr
 

Detailed Description

STDIO interface for read/write ports.

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

Definition at line 767 of file libxr_rw.hpp.

Member Function Documentation

◆ Printf()

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

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 603 of file libxr_rw.cpp.

604{
605#if LIBXR_PRINTF_BUFFER_SIZE > 0
606 if (!STDIO::write_ || !STDIO::write_->Writable())
607 {
608 return -1;
609 }
610
611 if (!write_mutex_)
612 {
614 }
615
617
618 va_list args;
619 va_start(args, fmt);
620 int len = vsnprintf(STDIO::printf_buff_, LIBXR_PRINTF_BUFFER_SIZE, fmt, args);
621 va_end(args);
622
623 // Check result and limit length
624 if (len < 0)
625 {
626 return -1;
627 }
628 if (static_cast<size_t>(len) >= LIBXR_PRINTF_BUFFER_SIZE)
629 {
630 len = LIBXR_PRINTF_BUFFER_SIZE - 1;
631 }
632
633 ConstRawData data = {reinterpret_cast<const uint8_t*>(STDIO::printf_buff_),
634 static_cast<size_t>(len)};
635
636 static WriteOperation op; // NOLINT
637 auto ans = ErrorCode::OK;
638 if (write_stream_ == nullptr)
639 {
640 ans = STDIO::write_->operator()(data, op);
641 }
642 else
643 {
644 (*write_stream_) << data;
645 ans = write_stream_->Commit();
646 }
647
648 if (ans == ErrorCode::OK)
649 {
650 return len;
651 }
652 else
653 {
654 return -1;
655 }
656
657#else
658 UNUSED(fmt);
659 return 0;
660#endif
661}
常量原始数据封装类。 A class for encapsulating constant raw data.
互斥锁的 RAII 机制封装 (RAII-style mechanism for automatic mutex management).
Definition mutex.hpp:65
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
Definition mutex.hpp:18
static LibXR::Mutex * write_mutex_
Write port mutex. 写入端口互斥锁。
Definition libxr_rw.hpp:773
static WritePort * write_
Write port instance. 写入端口。
Definition libxr_rw.hpp:772
ErrorCode Commit()
手动提交已写入的数据到队列,并释放当前锁。
Definition libxr_rw.cpp:572
@ OK
操作成功 | Operation successful

Field Documentation

◆ read_

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

Read port instance. 读取端口。

Definition at line 771 of file libxr_rw.hpp.

◆ write_

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

Write port instance. 写入端口。

Definition at line 772 of file libxr_rw.hpp.

◆ write_mutex_

LibXR::Mutex* LibXR::STDIO::write_mutex_
inlinestatic
Initial value:
=
nullptr

Write port mutex. 写入端口互斥锁。

Definition at line 773 of file libxr_rw.hpp.

◆ write_stream_

LibXR::WritePort::Stream* LibXR::STDIO::write_stream_ = nullptr
inlinestatic

Definition at line 775 of file libxr_rw.hpp.


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