/************************************************************************ * EOS - the CERN Disk Storage System * * Copyright (C) 2023 CERN/Switzerland * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* ************************************************************************/ #ifndef EOS_IMDLOCKHELPER_HH #define EOS_IMDLOCKHELPER_HH #include #include "namespace/interface/IContainerMD.hh" #include "namespace/Namespace.hh" EOSNSNAMESPACE_BEGIN class IMDLockHelper { public: /** * Convenient function to lock an File or ContainerMD owned by a shared_ptr * @tparam Locker the type of lock to apply * @tparam MDPtr the type of the File or ContainerMD shared_ptr * @param objectMDPtr the shared_ptr * @return the unique_pointer owning the locked ContainerMD/FileMD */ template static std::unique_ptr lock(MDPtr objectMDPtr) { return std::make_unique(objectMDPtr); } /** * Convenient function to lock a File or a Container MD * @tparam ContainerMDLocker The type of lock for the ContainerMD * @tparam FileMDLocker The type of lock for the FileMD * @param fileOrContMD the object containing either a FileMD or a ContainerMD * @return the structure FileOrContainerMDLocked containing either a File or ContainerMD locked accordingly */ template static FileOrContainerMDLocked lock(eos::FileOrContainerMD fileOrContMD) { FileOrContainerMDLocked ret; if(fileOrContMD.container) { ret.containerLocked = std::make_unique(fileOrContMD.container); } else if(fileOrContMD.file) { ret.fileLocked = std::make_unique(fileOrContMD.file); } return ret; }; }; EOSNSNAMESPACE_END #endif // EOS_IMDLOCKHELPER_HH