2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef WIFICOND_LOOPER_BACKED_EVENT_LOOP_H_
18 #define WIFICOND_LOOPER_BACKED_EVENT_LOOP_H_
20 #include <event_loop.h>
22 #include <android-base/macros.h>
23 #include <utils/Looper.h>
28 class LooperBackedEventLoop: public EventLoop {
30 LooperBackedEventLoop();
31 ~LooperBackedEventLoop() override;
34 void PostTask(const std::function<void()>& callback) override;
37 void PostDelayedTask(const std::function<void()>& callback,
38 int64_t delay_ms) override;
40 bool WatchFileDescriptor(
43 const std::function<void(int)>& callback) override;
46 bool StopWatchFileDescriptor(int fd) override;
48 // Performs all pending callbacks and waiting for new events until
49 // TriggerExit() is called.
50 // This method can be called from any thread context.
53 // Blocks for |timeout_millis| for the next event.
54 // This method can be called from any thread context.
55 void PollForOne(int timeout_millis);
57 // Posts a task to stop event loop polling.
58 // This method can be called from any thread context.
62 sp<android::Looper> looper_;
63 bool should_continue_;
65 DISALLOW_COPY_AND_ASSIGN(LooperBackedEventLoop);
68 } // namespace wificond
69 } // namespace android
71 #endif // WIFICOND_LOOPER_BACKED_EVENT_LOOP_H_