libzypp 17.31.23
devicedriver.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#ifndef ZYPP_MEDIA_NG_WORKER_DEVICEDRIVER_H_INCLUDED
11#define ZYPP_MEDIA_NG_WORKER_DEVICEDRIVER_H_INCLUDED
12
13#include <zypp-media/ng/ProvideFwd>
14#include <zypp-media/ng/worker/ProvideWorker>
15#include <zypp-media/ng/HeaderValueMap>
16#include <zypp-media/Mount>
17#include <zypp-core/zyppng/base/Signals>
18#include <zypp-core/zyppng/base/Base>
19#include <zypp-core/zyppng/base/zyppglobal.h>
20#include <zypp-core/zyppng/pipelines/Expected>
21#include <any>
22#include <unordered_map>
23
24namespace zyppng::worker
25{
26
28
29 struct Device
30 {
31 std::string _name;
32 unsigned int _maj_nr = 0;
33 unsigned int _min_nr = 0;
35 bool _ephemeral = false;
36 std::unordered_map<std::string, std::any> _properties = {};
37 };
38
40 {
41 std::shared_ptr<Device> _dev;
43 };
44
46 {
47 AttachError ( const uint code, const std::string &reason, const bool transient, const HeaderValueMap &extra = {} );
48 AttachError ( const uint code, const bool transient, const zypp::Exception &e );
49
50 uint _code;
51 std::string _reason;
54 };
55
56 using AttachResult = expected<void, AttachError>;
57
64 class DeviceDriver : public zyppng::Base
65 {
66 public:
67
68 DeviceDriver ( WorkerCaps::WorkerType wType );
69
73 void setProvider ( ProvideWorkerWeakRef workerRef );
74
78 virtual AttachResult mountDevice ( const uint32_t id, const zypp::Url &mediaUrl, const std::string &attachId, const std::string &label, const HeaderValueMap &extras ) = 0;
79
80
81
82 virtual zyppng::expected<WorkerCaps> initialize(const zyppng::worker::Configuration &conf);
83
84
93 bool detachMedia ( const std::string &attachId );
94
98 void releaseIdleDevices ();
99
105 virtual void detectDevices();
106
111 std::vector<std::shared_ptr<Device>> &knownDevices();
112
117 const std::vector<std::shared_ptr<Device>> &knownDevices() const;
118
122 std::unordered_map<std::string, AttachedMedia> &attachedMedia();
123
128 virtual bool isVolatile () const;
129
133 void setAttachRoot ( const zypp::Pathname &root );
134
138 zypp::Pathname attachRoot () const;
139
143 virtual void immediateShutdown();
144
148 ProvideWorkerRef parentWorker () const;
149
154
155 protected:
159 virtual void unmountDevice ( Device &dev );
160
164 zyppng::expected<void> isDesiredMedium ( const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr = 1 );
165
166
167 zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const;
168 void removeAttachPoint ( const zypp::Pathname &attach_pt ) const;
169 bool checkAttached ( const zypp::Pathname &mountPoint, const std::function<bool( const zypp::media::MountEntry &)> predicate );
170
174 static const std::function<bool( const zypp::media::MountEntry &)> devicePredicate ( unsigned int majNr, unsigned int minNr );
175
179 static const std::function<bool( const zypp::media::MountEntry &)> fstypePredicate ( const std::string &src, const std::vector<std::string> &fstypes );
180
184 static const std::function<bool( const zypp::media::MountEntry &)> bindMountPredicate ( const std::string &src );
185
186 private:
187 WorkerCaps::WorkerType _wType;
189 time_t _attach_mtime = 0; //< Timestamp of the mtab we did read
191 std::vector<std::shared_ptr<Device>> _sysDevs;
192 std::unordered_map<std::string, AttachedMedia> _attachedMedia;
193 ProvideWorkerWeakRef _parentWorker;
194 };
195
196
197
198
199}
200
201#endif
MediaVerifierRef verifier
Predicate predicate
Definition: PoolQuery.cc:313
Base class for Exception.
Definition: Exception.h:146
Url manipulation class.
Definition: Url.h:92
zypp::Pathname attachRoot() const
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
Definition: devicedriver.cc:34
static const std::function< bool(const zypp::media::MountEntry &)> fstypePredicate(const std::string &src, const std::vector< std::string > &fstypes)
bool checkAttached(const zypp::Pathname &mountPoint, const std::function< bool(const zypp::media::MountEntry &)> predicate)
zyppng::worker::Configuration _config
Definition: devicedriver.h:188
ProvideWorkerWeakRef _parentWorker
Definition: devicedriver.h:193
bool detachMedia(const std::string &attachId)
Definition: devicedriver.cc:60
virtual bool isVolatile() const
void setProvider(ProvideWorkerWeakRef workerRef)
Definition: devicedriver.cc:29
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
WorkerCaps::WorkerType _wType
Definition: devicedriver.h:187
static const std::function< bool(const zypp::media::MountEntry &)> bindMountPredicate(const std::string &src)
std::unordered_map< std::string, AttachedMedia > & attachedMedia()
std::vector< std::shared_ptr< Device > > & knownDevices()
Definition: devicedriver.cc:90
virtual AttachResult mountDevice(const uint32_t id, const zypp::Url &mediaUrl, const std::string &attachId, const std::string &label, const HeaderValueMap &extras)=0
const zyppng::worker::Configuration & config() const
virtual void immediateShutdown()
void removeAttachPoint(const zypp::Pathname &attach_pt) const
std::vector< std::shared_ptr< Device > > _sysDevs
Definition: devicedriver.h:191
std::unordered_map< std::string, AttachedMedia > _attachedMedia
Definition: devicedriver.h:192
ProvideWorkerRef parentWorker() const
static const std::function< bool(const zypp::media::MountEntry &)> devicePredicate(unsigned int majNr, unsigned int minNr)
void setAttachRoot(const zypp::Pathname &root)
virtual void unmountDevice(Device &dev)
ZYPP_FWD_DECL_TYPE_WITH_REFS(DeviceDriver)
zypp::proto::Configuration Configuration
Definition: provideworker.h:33
expected< void, AttachError > AttachResult
Definition: devicedriver.h:56
A "struct mntent" like mount entry structure, but using std::strings.
Definition: mount.h:35
std::shared_ptr< Device > _dev
Definition: devicedriver.h:41
std::unordered_map< std::string, std::any > _properties
Definition: devicedriver.h:36
std::string _name
Path of the device node or URL for e.g. nfs devices.
Definition: devicedriver.h:31
unsigned int _min_nr
Minor number of the device.
Definition: devicedriver.h:33
unsigned int _maj_nr
Major number of the device.
Definition: devicedriver.h:32
bool _ephemeral
If set to true the device is removed from the internal list after the last attachpoint was released.
Definition: devicedriver.h:35
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
Definition: devicedriver.h:34