-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventBase.h
More file actions
121 lines (97 loc) · 2.82 KB
/
Copy pathEventBase.h
File metadata and controls
121 lines (97 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include"RxObserver/Subjects.h"
#include"RxObserver/SubjectsProxy.h"
#include"RxObserver/ObserverProxy.h"
#include"RxObserver/ObserverEvent.h"
#include"RxSignal/Observer/FilterObserver.h"
namespace BaseLib { namespace Concurrent
{
template <typename EventType, typename T>
class SubjectEventsType
: public BaseLib::Observer::FilterOutObserver1<BaseLib::Concurrent::Event::Ptr>
{
private:
typedef SubjectsProxy<EventType, T> Proxy;
public:
SubjectEventsType(T *eventSource, SubjectDescription description, SubjectPolicy policy)
: proxy_(eventSource, description, policy)
{
proxy_.template Connect<SubjectEventsType<EventType, T>>(this);
}
virtual ~SubjectEventsType()
{
proxy_.template Disconnect<SubjectEventsType<EventType, T>>(this);
}
T& event()
{
return proxy_.On();
}
const T& event() const
{
return proxy_.On();
}
Proxy& state()
{
return proxy_;
}
const Proxy& state() const
{
return proxy_;
}
// -----------------------------------------
// FilterOutObserver1 interface
// -----------------------------------------
virtual void OnFilteredOut(Concurrent::Event::Ptr )
{
IINFO() << "Event filtered out";
}
//virtual void OnSubscribe(std::shared_ptr<ObserverAction> ) {}
//virtual void OnUnsubscribe(std::shared_ptr<ObserverAction> ) {}
//virtual void OnUnsubscribe() { }
//virtual void OnBlock(std::shared_ptr<ObserverAction> ) { }
//virtual void OnUnblock(std::shared_ptr<ObserverAction> ) { }
//virtual void OnBackpressureDrop(Event::Ptr) { }
private:
Proxy proxy_;
};
template <typename EventType, typename T>
class ObserverEventType
: public BaseLib::Observer::FilterOutObserver1<ObserverEvent::Ptr>
{
private:
typedef ObserverProxy<EventType, T> Proxy;
public:
ObserverEventType(T *eventSource, SubjectDescription description)
: proxy_(eventSource, description)
{
proxy_.Connect(this);
}
virtual ~ObserverEventType()
{
proxy_.Disconnect(this);
}
Proxy& event()
{
return proxy_;
}
const Proxy& event() const
{
return proxy_;
}
// -----------------------------------------
// FilterOutObserver1 interface
// -----------------------------------------
virtual void OnFilteredOut(Concurrent::ObserverEvent::Ptr )
{
IINFO() << "Event filtered out";
}
//virtual void OnActive(Concurrent::Subject::Ptr ) {}
//virtual void OnInactive(Concurrent::Subject::Ptr ) {}
//virtual void OnUnsubscribe() { }
//virtual void OnBlock(Concurrent::Subject::Ptr ) { }
//virtual void OnUnblock(Concurrent::Subject::Ptr ) { }
//virtual void OnBackpressureDrop(Event::Ptr) { }
private:
Proxy proxy_;
};
}}