• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #ifndef ANDROID_BUFFER_HUB_EVENT_FD_H_
18 #define ANDROID_BUFFER_HUB_EVENT_FD_H_
19 
20 #include <android-base/unique_fd.h>
21 #include <utils/Errors.h>
22 
23 namespace android {
24 
25 class BufferHubEventFd {
26 public:
27     /**
28      * Constructs a valid event fd.
29      */
30     BufferHubEventFd();
31 
32     /**
33      * Constructs from a valid event fd. Caller is responsible for the validity of the fd. Takes
34      * ownership.
35      */
36     BufferHubEventFd(int fd);
37 
38     /**
39      * Returns whether this BufferHubEventFd holds a valid event_fd.
40      */
isValid()41     bool isValid() const { return get() >= 0; }
42 
43     /**
44      * Returns the fd number of the BufferHubEventFd object. Note that there is no ownership
45      * transfer.
46      */
get()47     int get() const { return mFd.get(); }
48 
49     /**
50      * Signals the eventfd.
51      */
52     status_t signal() const;
53 
54     /**
55      * Clears the signal from this eventfd if it is signaled.
56      */
57     status_t clear() const;
58 
59 private:
60     base::unique_fd mFd;
61 };
62 
63 } // namespace android
64 
65 #endif // ANDROID_BUFFER_HUB_EVENT_FD_H_
66