-
Notifications
You must be signed in to change notification settings - Fork 1
/
ALooperRoster.cpp
74 lines (60 loc) · 2.12 KB
/
ALooperRoster.cpp
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
#include "ALooperRoster.h"
#include "AHandler.h"
#include "AMessage.h"
#include "Logger.h"
namespace android {
static bool verboseStats = false;
ALooperRoster::ALooperRoster()
: mNextHandlerID(1) {
}
ALooper::handler_id ALooperRoster::registerHandler(
const std::shared_ptr<ALooper>& looper, const std::shared_ptr<AHandler>& handler) {
MutexAutoLock autoLock(mLock);
if (handler->id() != 0) {
//CHECK(!"A handler must only be registered once.");
LOGE("A handler must only be registered once.");
return INVALID_OPERATION;
}
HandlerInfo info;
info.mLooper = looper;
info.mHandler = handler;
ALooper::handler_id handlerID = mNextHandlerID++;
mHandlers.emplace(handlerID, info);
handler->setID(handlerID, looper);
return handlerID;
}
void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) {
MutexAutoLock autoLock(mLock);
auto it = mHandlers.find(handlerID);
if (it == mHandlers.end()) {
return;
}
const HandlerInfo& info = it->second;
std::shared_ptr<AHandler> handler = info.mHandler.lock();
if (handler != nullptr) {
handler->clear();
}
mHandlers.erase(it);
}
void ALooperRoster::unregisterStaleHandlers() {
std::vector<std::shared_ptr<ALooper> > activeLoopers;
{
MutexAutoLock autoLock(mLock);
auto it = mHandlers.begin();
while (it != mHandlers.end()) {
const HandlerInfo& info = it->second;
std::shared_ptr<ALooper> looper = info.mLooper.lock();
if (looper == nullptr) {
it = mHandlers.erase(it);
}
else
{
activeLoopers.emplace_back(looper);
it++;
}
}
}
}
void ALooperRoster::dump(int fd, const std::vector<std::string>& args) {
}
} // namespace android