blob: e0f01ed25d3821c00152dd55a9e562c66c9f1219 [file] [log] [blame]
Paul Ramireze2bb1872024-08-12 20:21:13 +00001/**
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <TestLooper.h>
18
19#include <android-base/logging.h>
20
21namespace android {
22
23TestLooper::TestLooper() : mLooper(sp<Looper>::make(/*allowNonCallbacks=*/false)) {}
24
25int TestLooper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callback,
26 void* data) {
27 mCallbacks[fd] = callback;
28 constexpr int SUCCESS{1};
29 return SUCCESS;
30}
31
32int TestLooper::removeFd(int fd) {
33 if (auto it = mCallbacks.find(fd); it != mCallbacks.cend()) {
34 mCallbacks.erase(fd);
35 constexpr int SUCCESS{1};
36 return SUCCESS;
37 }
38 constexpr int FAILURE{0};
39 return FAILURE;
40}
41
42void TestLooper::invokeCallback(int fd, int events) {
43 auto it = mCallbacks.find(fd);
44 LOG_IF(FATAL, it == mCallbacks.cend()) << "Fd does not exist in mCallbacks.";
45 mCallbacks[fd]->handleEvent(fd, events, /*data=*/nullptr);
46}
47
48sp<Looper> TestLooper::getLooper() const {
49 return mLooper;
50}
51} // namespace android