2016-09-05 12:00:04 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#ifndef CAMERASERVER_SINKIMPL_H_
|
|
|
|
|
#define CAMERASERVER_SINKIMPL_H_
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "llvm/StringRef.h"
|
|
|
|
|
|
2016-09-08 23:52:23 -07:00
|
|
|
#include "SourceImpl.h"
|
|
|
|
|
|
2016-09-05 12:00:04 -07:00
|
|
|
namespace cs {
|
|
|
|
|
|
|
|
|
|
class Frame;
|
|
|
|
|
|
|
|
|
|
class SinkImpl {
|
|
|
|
|
public:
|
|
|
|
|
SinkImpl(llvm::StringRef name);
|
2016-09-08 23:52:23 -07:00
|
|
|
virtual ~SinkImpl();
|
2016-09-05 12:00:04 -07:00
|
|
|
SinkImpl(const SinkImpl& queue) = delete;
|
|
|
|
|
SinkImpl& operator=(const SinkImpl& queue) = delete;
|
|
|
|
|
|
|
|
|
|
llvm::StringRef GetName() const { return m_name; }
|
2016-09-10 21:30:39 -07:00
|
|
|
virtual llvm::StringRef GetDescription(
|
|
|
|
|
llvm::SmallVectorImpl<char>& buf) const = 0;
|
2016-09-05 12:00:04 -07:00
|
|
|
|
2016-09-08 23:52:23 -07:00
|
|
|
void Enable() {
|
2016-09-05 12:00:04 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2016-09-08 23:52:23 -07:00
|
|
|
if (!m_enabled) {
|
|
|
|
|
m_enabled = true;
|
|
|
|
|
if (m_source) m_source->EnableSink();
|
|
|
|
|
}
|
2016-09-05 12:00:04 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-08 23:52:23 -07:00
|
|
|
void Disable() {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
if (m_enabled) {
|
|
|
|
|
m_enabled = false;
|
|
|
|
|
if (m_source) m_source->DisableSink();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetSource(std::shared_ptr<SourceImpl> source);
|
|
|
|
|
|
2016-09-05 12:00:04 -07:00
|
|
|
std::shared_ptr<SourceImpl> GetSource() const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
return m_source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string m_name;
|
|
|
|
|
mutable std::mutex m_mutex;
|
|
|
|
|
std::shared_ptr<SourceImpl> m_source;
|
2016-09-08 23:52:23 -07:00
|
|
|
bool m_enabled{false};
|
2016-09-05 12:00:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cs
|
|
|
|
|
|
|
|
|
|
#endif // CAMERASERVER_SINKIMPL_H_
|