8 #ifndef CSCORE_HANDLE_H_ 9 #define CSCORE_HANDLE_H_ 15 #include <llvm/StringRef.h> 17 #include "UnlimitedHandleResource.h" 32 enum Type { kUndefined = 0, kProperty = 0x40, kSource, kSink, kListener };
33 enum { kIndexMax = 0xffff };
35 Handle(CS_Handle handle) : m_handle(handle) {}
36 operator CS_Handle()
const {
return m_handle; }
38 Handle(
int index, Type type) {
43 m_handle = ((
static_cast<int>(type) & 0x7f) << 24) | (index & 0xffff);
45 Handle(
int index,
int property, Type type) {
46 if (index < 0 || property < 0) {
50 m_handle = ((
static_cast<int>(type) & 0x7f) << 24) |
51 ((index & 0xff) << 16) | (property & 0xffff);
54 int GetIndex()
const {
return static_cast<int>(m_handle) & 0xffff; }
55 Type GetType()
const {
56 return static_cast<Type
>((
static_cast<int>(m_handle) >> 24) & 0xff);
58 bool IsType(Type type)
const {
return type == GetType(); }
59 int GetTypedIndex(Type type)
const {
return IsType(type) ? GetIndex() : -1; }
60 int GetParentIndex()
const {
61 return IsType(Handle::kProperty) ? (
static_cast<int>(m_handle) >> 16) & 0xff
70 SourceData(CS_SourceKind kind_, std::shared_ptr<SourceImpl> source_)
71 : kind{kind_}, refCount{0}, source{source_} {}
74 std::atomic_int refCount;
75 std::shared_ptr<SourceImpl> source;
82 ATOMIC_STATIC(
Sources, instance);
86 std::pair<CS_Source, std::shared_ptr<SourceData>> Find(
89 [&](
const SourceData& data) {
return data.source.get() == &source; });
99 explicit SinkData(CS_SinkKind kind_, std::shared_ptr<SinkImpl> sink_)
100 : kind{kind_}, refCount{0}, sourceHandle{0}, sink{sink_} {}
103 std::atomic_int refCount;
104 std::atomic<CS_Source> sourceHandle;
105 std::shared_ptr<SinkImpl> sink;
110 static Sinks& GetInstance() {
111 ATOMIC_STATIC(
Sinks, instance);
115 std::pair<CS_Sink, std::shared_ptr<SinkData>> Find(
const SinkImpl& sink) {
117 [&](
const SinkData& data) {
return data.sink.get() == &sink; });
123 ATOMIC_STATIC_DECL(
Sinks)
128 #endif // CSCORE_HANDLE_H_ Definition: SinkImpl.h:19
Definition: SinkImpl.h:23
Definition: SourceImpl.h:30
Definition: UnlimitedHandleResource.h:42