1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HDI_FD_H 17 #define HDI_FD_H 18 #include <fcntl.h> 19 #include <memory> 20 #include "display_common.h" 21 22 namespace OHOS { 23 namespace HDI { 24 namespace DISPLAY { 25 class HdiFd { 26 public: HdiFd()27 HdiFd() 28 { 29 DISPLAY_LOGD(); 30 } HdiFd(int fd)31 explicit HdiFd(int fd) : mFd(fd) 32 { 33 DISPLAY_LOGD("mFd %{public}d", mFd); 34 } GetFd()35 int GetFd() const 36 { 37 return mFd; 38 }; 39 40 HdiFd &operator = (int fd) 41 { 42 if (mFd >= 0) { 43 close(mFd); 44 } 45 mFd = fd; 46 return *this; 47 } 48 ~HdiFd()49 virtual ~HdiFd() 50 { 51 if (mFd >= 0) { 52 close(mFd); 53 } 54 } 55 56 private: 57 int mFd = -1; 58 }; 59 60 using FdPtr = std::shared_ptr<HdiFd>; 61 } // OHOS 62 } // HDIO 63 } // DISPLAY 64 65 #endif // HDI_FD_H