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_EVENT_LOOP_H_
18 #define WIFICOND_EVENT_LOOP_H_
25 // Abstract class for dispatching tasks.
33 virtual ~EventLoop() {}
35 // Enqueues a callback.
36 // This function can be called on any thread.
37 virtual void PostTask(const std::function<void()>& callback) = 0;
39 // Enqueues a callback to be processed after a specified period of time.
40 // |delay_ms| is delay time in milliseconds. It should not be negative.
41 // This function can be called on any thread.
42 virtual void PostDelayedTask(const std::function<void()>& callback,
43 int64_t delay_ms) = 0;
45 // Monitoring file descriptor for data.
46 // Callback will be executed when specific file descriptor is ready.
47 // File descriptor is provided as a parameter to this callback:
48 // This function can be called on any thread.
49 // This returns true upon success and returns false when it failed.
50 virtual bool WatchFileDescriptor(
53 const std::function<void(int)>& callback_) = 0;
55 // Stop monitoring file descriptor |fd|.
56 // This function can be called on any thread.
57 // This returns true upon success and returns false when it failed to
58 // remove the file descriptor, or this file descriptor was not registered
60 virtual bool StopWatchFileDescriptor(int fd);
63 } // namespace wificond
64 } // namespace android
66 #endif // WIFICOND_EVENT_LOOP_H_