/* * Copyright (C) 2024 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. */ #pragma once #include #include #include #include #include #include namespace android::hardware::graphics::composer { class FileNode { public: FileNode(const std::string& nodePath); ~FileNode(); std::string dump(); uint32_t getLastWrittenValue(const std::string& nodeName); std::optional readString(const std::string& nodeName); bool WriteUint32(const std::string& nodeName, uint32_t value); private: int getFileHandler(const std::string& nodeName); std::string mNodePath; std::unordered_map mFds; std::unordered_map mLastWrittenValue; }; class FileNodeManager : public Singleton { public: FileNodeManager() = default; ~FileNodeManager() = default; std::shared_ptr getFileNode(const std::string& nodePath) { if (mFileNodes.find(nodePath) == mFileNodes.end()) { mFileNodes[nodePath] = std::make_shared(nodePath); } return mFileNodes[nodePath]; } private: std::unordered_map> mFileNodes; }; } // namespace android::hardware::graphics::composer