Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
FileAccessor.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef POOLTESTS_FILEACCESSOR_H
20#define POOLTESTS_FILEACCESSOR_H
21
22#include <boost/thread/shared_mutex.hpp>
23
24namespace Euclid {
25namespace FilePool {
26
31public:
32 using SharedMutex = boost::shared_mutex;
33 using SharedLock = boost::shared_lock<SharedMutex>;
34 using UniqueLock = boost::unique_lock<SharedMutex>;
35 using UpgradeLock = boost::upgrade_lock<SharedMutex>;
36 using UpgradeToUniqueLock = boost::upgrade_to_unique_lock<SharedMutex>;
37
38 virtual ~FileAccessorBase() = default;
39
41 virtual bool isReadOnly() const = 0;
42};
43
53template <typename TFD>
55public:
57
59 TFD m_fd;
60
62 virtual ~FileAccessor() = default;
63
64protected:
65 FileAccessor(TFD&& fd, ReleaseDescriptorCallback release_callback);
66
68};
69
80template <typename TFD>
81class FileReadAccessor : public FileAccessor<TFD> {
82public:
85 using SharedLock = typename Base_::SharedLock;
86
96 FileReadAccessor(TFD&& fd, ReleaseDescriptorCallback release_callback, SharedLock lock);
97
100
103
106
108 bool isReadOnly() const final;
109
110private:
112};
113
120template <typename TFD>
121class FileWriteAccessor : public FileAccessor<TFD> {
122public:
127
137 FileWriteAccessor(TFD&& fd, ReleaseDescriptorCallback release_callback, UniqueLock lock);
138
141
143 bool isReadOnly() const final;
144
145private:
146 UniqueLock m_unique_lock;
147};
148
149} // namespace FilePool
150} // namespace Euclid
151
152#define FILEACCESSOR_IMPL
154#undef FILEACCESSOR_IMPL
155
156#endif // POOLTESTS_FILEACCESSOR_H
virtual bool isReadOnly() const =0
boost::upgrade_lock< SharedMutex > UpgradeLock
boost::unique_lock< SharedMutex > UniqueLock
boost::upgrade_to_unique_lock< SharedMutex > UpgradeToUniqueLock
boost::shared_lock< SharedMutex > SharedLock
FileAccessor(TFD &&fd, ReleaseDescriptorCallback release_callback)
ReleaseDescriptorCallback m_release_callback
virtual ~FileAccessor()=default
Destructor.
std::function< void(TFD &&)> ReleaseDescriptorCallback
TFD m_fd
The wrapped file descriptor.
FileReadAccessor(TFD &&fd, ReleaseDescriptorCallback release_callback, SharedLock lock)
FileReadAccessor(FileReadAccessor &&)=default
But it can be moved.
virtual ~FileReadAccessor()
Destructor.
FileReadAccessor(const FileReadAccessor &)=delete
It can not be copied.
typename Base_::SharedLock SharedLock
typename Base_::ReleaseDescriptorCallback ReleaseDescriptorCallback
typename Base_::ReleaseDescriptorCallback ReleaseDescriptorCallback
typename Base_::SharedLock SharedLock
virtual ~FileWriteAccessor()
Destructor.
FileWriteAccessor(TFD &&fd, ReleaseDescriptorCallback release_callback, UniqueLock lock)
typename Base_::UniqueLock UniqueLock