-
Notifications
You must be signed in to change notification settings - Fork 1
/
AHandler.h
73 lines (55 loc) · 1.86 KB
/
AHandler.h
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
#pragma once
#include "Base.h"
#include "ALooper.h"
#include "Logger.h"
namespace android {
struct AMessage;
struct AHandler : public std::enable_shared_from_this<AHandler> {
AHandler()
: mID(0),
mVerboseStats(false),
mMessageCounter(0) {
LOGV("constructed {}",fmt::ptr(this));
}
~AHandler() {
LOGV("destructed {}",fmt::ptr(this));
}
ALooper::handler_id id() const {
return mID;
}
std::shared_ptr<ALooper> looper() {
return mLooper.lock();
}
std::weak_ptr<ALooper> getLooper() const {
return mLooper;
}
std::weak_ptr<AHandler> getHandler() {
// allow getting a weak reference to a const handler
return shared_from_this();
}
status_t postEmptyMessage(uint32_t what, int64_t delayUs = 0);
void removeAllMessage();
void removeMessage(int what);
std::shared_ptr<AMessage> obtainMessage();
protected:
virtual void onMessageReceived(const std::shared_ptr<AMessage>& msg) = 0;
private:
friend struct AMessage; // deliverMessage()
friend struct ALooperRoster; // setID()
ALooper::handler_id mID;
std::weak_ptr<ALooper> mLooper;
inline void setID(ALooper::handler_id id, const std::weak_ptr<ALooper>& looper) {
mID = id;
mLooper = looper;
}
inline void clear() {
mID = 0;
mLooper.reset();
}
bool mVerboseStats;
uint64_t mMessageCounter;
KeyedI32Vector mMessages;
void deliverMessage(const std::shared_ptr<AMessage>& msg);
DISALLOW_EVIL_CONSTRUCTORS(AHandler);
};
} // namespace android