/** * Copyright (c) 2021, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CPP_LIBSYSFSMONITOR_SRC_SYSFSMONITOR_H_ #define CPP_LIBSYSFSMONITOR_SRC_SYSFSMONITOR_H_ #include #include #include #include #include #include namespace android { namespace automotive { using CallbackFunc = ::std::function&)>; /** * SysfsMonitor monitors sysfs file changes and invokes the registered callback when there is a * change at the sysfs files to monitor. */ class SysfsMonitor final : public RefBase { public: // Initializes SysfsMonitor instance. android::base::Result init(CallbackFunc callback); // Releases resources used for monitoring. android::base::Result release(); // Registers a sysfs file to monitor. android::base::Result registerFd(int32_t fd); // Unregisters a sysfs file to monitor. android::base::Result unregisterFd(int32_t fd); // Starts observing sysfs file changes. android::base::Result observe(); private: android::base::unique_fd mEpollFd; std::unordered_set mMonitoringFds; CallbackFunc mCallback; }; } // namespace automotive } // namespace android #endif // CPP_LIBSYSFSMONITOR_SRC_SYSFSMONITOR_H_