libzypp 17.37.17
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>
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 MessageCodes code, const std::string &reason, const bool transient, const HeaderValueMap &extra = {} );
48 AttachError ( const MessageCodes code, const bool transient, const zypp::Exception &e );
49
51 std::string _reason;
54 };
55
56 // either the mountpoint or an error
58
66 {
67 public:
68
70
74 void setProvider ( ProvideWorkerWeakRef workerRef );
75
79 virtual AttachResult mountDevice ( const uint32_t id, const zypp::Url &mediaUrl, const std::string &attachId, const std::string &label, const HeaderValueMap &extras ) = 0;
80
81
82
84
85
94 bool detachMedia ( const std::string &attachId );
95
99 void releaseIdleDevices ();
100
106 virtual void detectDevices();
107
112 std::vector<std::shared_ptr<Device>> &knownDevices();
113
118 const std::vector<std::shared_ptr<Device>> &knownDevices() const;
119
123 std::unordered_map<std::string, AttachedMedia> &attachedMedia();
124
129 virtual bool isVolatile () const;
130
134 void setAttachRoot ( const zypp::Pathname &root );
135
139 zypp::Pathname attachRoot () const;
140
144 virtual void immediateShutdown();
145
149 ProvideWorkerRef parentWorker () const;
150
155
156 protected:
160 virtual void unmountDevice ( Device &dev );
161
165 zyppng::expected<void> isDesiredMedium ( const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr = 1 );
166
167
168 zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const;
169 void removeAttachPoint ( const zypp::Pathname &attach_pt ) const;
170 bool checkAttached ( const zypp::Pathname &mountPoint, const std::function<bool( const zypp::media::MountEntry &)> predicate );
171
175 static const std::function<bool( const zypp::media::MountEntry &)> devicePredicate ( unsigned int majNr, unsigned int minNr );
176
180 static const std::function<bool( const zypp::media::MountEntry &)> fstypePredicate ( const std::string &src, const std::vector<std::string> &fstypes );
181
185 static const std::function<bool( const zypp::media::MountEntry &)> bindMountPredicate ( const std::string &src );
186
187 private:
190 time_t _attach_mtime = 0; //< Timestamp of the mtab we did read
192 std::vector<std::shared_ptr<Device>> _sysDevs;
193 std::unordered_map<std::string, AttachedMedia> _attachedMedia;
194 ProvideWorkerWeakRef _parentWorker;
195 };
196
197
198
199
200}
201
202#endif
Base class for Exception.
Definition Exception.h:153
Url manipulation class.
Definition Url.h:93
zypp::Pathname attachRoot() const
zypp::Pathname createAttachPoint(const zypp::Pathname &attach_root) const
virtual zyppng::expected< WorkerCaps > initialize(const zyppng::worker::Configuration &conf)
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)
ProvideWorkerWeakRef _parentWorker
bool detachMedia(const std::string &attachId)
DeviceDriver(WorkerCaps::WorkerType wType)
virtual bool isVolatile() const
void setProvider(ProvideWorkerWeakRef workerRef)
zyppng::expected< void > isDesiredMedium(const zypp::Url &deviceUrl, const zypp::Pathname &mountPoint, const zyppng::MediaDataVerifierRef &verifier, uint mediaNr=1)
WorkerCaps::WorkerType _wType
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()
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
void removeAttachPoint(const zypp::Pathname &attach_pt) const
std::vector< std::shared_ptr< Device > > _sysDevs
ProviderConfiguration _config
std::unordered_map< std::string, AttachedMedia > _attachedMedia
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)
expected< zypp::Pathname, AttachError > AttachResult
zyppng::ProviderConfiguration Configuration
A "struct mntent" like mount entry structure, but using std::strings.
Definition mount.h:36
AttachError(const MessageCodes code, const std::string &reason, const bool transient, const HeaderValueMap &extra={})
std::shared_ptr< Device > _dev
std::unordered_map< std::string, std::any > _properties
std::string _name
Path of the device node or URL for e.g. nfs devices.
unsigned int _min_nr
Minor number of the device.
unsigned int _maj_nr
Major number of the device.
bool _ephemeral
If set to true the device is removed from the internal list after the last attachpoint was released.
zypp::Pathname _mountPoint
Mountpoint of the device, if empty dev is not mounted.
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126