From 10429c85af1b8a100c7b8af3eb1dd9ab2f5b28b4 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Mon, 30 Mar 2020 21:03:35 +0800 Subject: [PATCH] =?UTF-8?q?Create=20Looper=20=E7=9A=84=E5=89=AF=E4=B8=9A.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interview/技巧心得相关/Looper 的副业.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 blogs/Android/Framework/Interview/技巧心得相关/Looper 的副业.md diff --git a/blogs/Android/Framework/Interview/技巧心得相关/Looper 的副业.md b/blogs/Android/Framework/Interview/技巧心得相关/Looper 的副业.md new file mode 100644 index 0000000..fc5fbdd --- /dev/null +++ b/blogs/Android/Framework/Interview/技巧心得相关/Looper 的副业.md @@ -0,0 +1,26 @@ +--- +Looper 的副业 +--- + +```c++ +int addFd(int fd, int ident, int events, sp& callback, ...){ + epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem); +} +void NativeMessageQueue::setFileDescriptorEvents(int fd, int events){ + mLooper->addFd(fd, Looper::POLL_CALLBACK, looperEvents, this, reinterpret_cast(events)); +} +void addOnFileDescriptorEventListener(FileDescriptor fd, int events, OnFileDescriptorEventListener listener){...} +``` + +Framework 里面有哪些地方用到了副业? + +```c++ +status_t NativeDisplayEventReceiver::initialize(){ + mMessageQueue->getLooper()->addFd(mReceiver.getFd(), 0, EVENT_INPUT, this, NULL); +} +``` + +#### 总结 + +1. Looper 里可以监听其他描述符 +2. 创建管道,跨进程传数据,用 Looper 监听描述符事件 \ No newline at end of file