mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
SinkImpl: Refactor GetDescription, add GetError, SetEnabled.
This commit is contained in:
@@ -20,6 +20,18 @@ SinkImpl::~SinkImpl() {
|
||||
}
|
||||
}
|
||||
|
||||
void SinkImpl::SetDescription(llvm::StringRef description) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
llvm::StringRef SinkImpl::GetDescription(
|
||||
llvm::SmallVectorImpl<char>& buf) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
buf.append(m_description.begin(), m_description.end());
|
||||
return llvm::StringRef{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_source) {
|
||||
@@ -30,3 +42,20 @@ void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
m_source->AddSink();
|
||||
if (m_enabledCount > 0) m_source->EnableSink();
|
||||
}
|
||||
|
||||
std::string SinkImpl::GetError() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
auto frame = m_source->GetCurFrame();
|
||||
if (frame) return std::string{}; // no error
|
||||
return llvm::StringRef{frame};
|
||||
}
|
||||
|
||||
llvm::StringRef SinkImpl::GetError(llvm::SmallVectorImpl<char>& buf) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
auto frame = m_source->GetCurFrame();
|
||||
if (frame) return llvm::StringRef{}; // no error
|
||||
buf.append(frame.data(), frame.data() + frame.size());
|
||||
return llvm::StringRef{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user