Imported Upstream version 17.12.0
[platform/upstream/libzypp.git] / zypp / target / hal / HalContext.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/hal/HalContext.h
10  *
11  *  \brief Hardware abstaction layer library wrapper.
12  */
13 #ifndef ZYPP_TARGET_HAL_HALCONTEXT_H
14 #define ZYPP_TARGET_HAL_HALCONTEXT_H
15
16 #include "zypp/target/hal/HalException.h"
17 #include "zypp/base/PtrTypes.h"
18 #include <string>
19 #include <vector>
20 #include <stdint.h>
21
22 //////////////////////////////////////////////////////////////////////
23 namespace zypp
24 { ////////////////////////////////////////////////////////////////////
25   ////////////////////////////////////////////////////////////////////
26   namespace target
27   { //////////////////////////////////////////////////////////////////
28     //////////////////////////////////////////////////////////////////
29     namespace hal
30     { ////////////////////////////////////////////////////////////////
31
32
33       // -------------------------------------------------------------
34       /** @{
35        * Forward declarations.
36        */
37       class HalDrive;
38       class HalVolume;
39
40       class HalDrive_Impl;
41       class HalVolume_Impl;
42       class HalContext_Impl;
43       /** }@ */
44
45
46       ////////////////////////////////////////////////////////////////
47       //
48       // CLASS NAME : HalContext
49       //
50       /** Hardware abstaction layer context.
51        *
52        * Hal context wrapper. It manages the dbus connection and is
53        * the entry point to query drives, volumes and other information.
54        *
55        * @todo: wrap more functions.
56        */
57       class HalContext
58       {
59       public:
60         typedef
61         zypp::RW_pointer<HalContext_Impl>::unspecified_bool_type  bool_type;
62
63         HalContext(bool autoconnect=false);
64         HalContext(const HalContext &context);
65         ~HalContext();
66
67         HalContext&
68         operator=(const HalContext &context);
69
70         /**
71          * Verifies if the context is initialized.
72          */
73         operator bool_type() const;
74
75         /**
76          */
77         void
78         connect();
79
80         /**
81          * Retrieve UDI's of all devices.
82          * \return Vector with device UDI's.
83          */
84         std::vector<std::string>
85         getAllDevices() const;
86
87         /**
88          * Construct a HalDrive object for the specified UDI.
89          * \param  The \p udi of the drive.
90          * \return The HalDrive object.
91          */
92         HalDrive
93         getDriveFromUDI(const std::string &udi) const;
94
95         /**
96          * Construct a HalVolume object for the specified UDI.
97          * \param  The \p udi of the volume.
98          * \return The HalVolume object.
99          */
100         HalVolume
101         getVolumeFromUDI(const std::string &udi) const;
102
103         HalVolume
104         getVolumeFromDeviceFile(const std::string &device_file) const;
105
106         /**
107          * Retrieve UDI's of all devices with a capability.
108          * \param  The \p capability name
109          * \return Vector with device UDI's.
110          */
111         std::vector<std::string>
112         findDevicesByCapability(const std::string &capability) const;
113
114         bool
115         getDevicePropertyBool  (const std::string &udi,
116                                 const std::string &key) const;
117
118         int32_t
119         getDevicePropertyInt32 (const std::string &udi,
120                                 const std::string &key) const;
121
122         uint64_t
123         getDevicePropertyUInt64(const std::string &udi,
124                                 const std::string &key) const;
125
126         double
127         getDevicePropertyDouble(const std::string &udi,
128                                 const std::string &key) const;
129
130         std::string
131         getDevicePropertyString(const std::string &udi,
132                                 const std::string &key) const;
133
134         void
135         setDevicePropertyBool  (const std::string &udi,
136                                 const std::string &key,
137                                 bool               value);
138
139         void
140         setDevicePropertyInt32 (const std::string &udi,
141                                 const std::string &key,
142                                 int32_t            value);
143
144         void
145         setDevicePropertyUInt64(const std::string &udi,
146                                 const std::string &key,
147                                 uint64_t           value);
148
149         void
150         setDevicePropertyDouble(const std::string &udi,
151                                 const std::string &key,
152                                 double             value);
153
154         void
155         setDevicePropertyString(const std::string &udi,
156                                 const std::string &key,
157                                 const std::string &value);
158
159         void
160         removeDeviceProperty(const std::string &udi,
161                              const std::string &key);
162
163       private:
164
165         zypp::RW_pointer<HalContext_Impl> h_impl;
166       };
167
168
169       ////////////////////////////////////////////////////////////////
170       //
171       // CLASS NAME : HalDrive
172       //
173       /** Hardware abstaction layer storage drive object.
174        *
175        * @todo: wrap more functions.
176        */
177       class HalDrive
178       {
179       public:
180         typedef
181         zypp::RW_pointer<HalDrive_Impl>::unspecified_bool_type    bool_type;
182
183         HalDrive();
184         HalDrive(const HalDrive &drive);
185         ~HalDrive();
186
187         HalDrive&
188         operator=(const HalDrive &drive);
189
190         operator bool_type() const;
191
192         std::string
193         getUDI() const;
194
195         std::string
196         getTypeName() const;
197
198         /**
199          * \return The drive's device file name.
200          */
201         std::string
202         getDeviceFile() const;
203
204         /**
205          * \return The drive's device file major number.
206          */
207         unsigned int
208         getDeviceMajor() const;
209
210         /**
211          * \return The drive's device minor number.
212          */
213         unsigned int
214         getDeviceMinor() const;
215
216         /**
217          * \return True, if drive uses removable media.
218          */
219         bool
220         usesRemovableMedia() const;
221
222         /*
223         ** Returns the media type names supported by the drive.
224         **
225         ** Since hal does not implement a textual form here, we
226         ** are using the drive type and property names from
227         ** "storage.cdrom.*" namespace:
228         **   cdrom, cdr, cdrw, dvd, dvdr, dvdrw, dvdram,
229         **   dvdplusr, dvdplusrw, dvdplusrdl
230         **
231         ** FIXME: Should we provide own LibHalDriveCdromCaps?
232         */
233         std::vector<std::string>
234         getCdromCapabilityNames() const;
235
236         /**
237          * Retrieve UDI's of all volumes of this drive.
238          * \return Vector with volume UDI's.
239          */
240         std::vector<std::string>
241         findAllVolumes() const;
242
243       private:
244         friend class HalContext;
245
246         HalDrive(HalDrive_Impl *impl);
247
248         zypp::RW_pointer<HalDrive_Impl>   d_impl;
249       };
250
251
252       ////////////////////////////////////////////////////////////////
253       //
254       // CLASS NAME : HalVolume
255       //
256       /** Hardware abstaction layer storage volume object.
257        *
258        * @todo: wrap more functions.
259        */
260       class HalVolume
261       {
262       public:
263         typedef
264         zypp::RW_pointer<HalVolume_Impl>::unspecified_bool_type   bool_type;
265
266         HalVolume();
267         HalVolume(const HalVolume &volume);
268         ~HalVolume();
269
270         HalVolume&
271         operator=(const HalVolume &volume);
272
273         operator bool_type() const;
274
275         std::string
276         getUDI() const;
277
278         /**
279          * \return The Volume drive's device file name.
280          */
281         std::string
282         getDeviceFile() const;
283
284         /**
285          * \return The Volume drive's device major number.
286          */
287         unsigned int
288         getDeviceMajor() const;
289
290         /**
291          * \return The Volume drive's device minor number.
292          */
293         unsigned int
294         getDeviceMinor() const;
295
296         bool
297         isDisc() const;
298
299         bool
300         isPartition() const;
301
302         bool
303         isMounted() const;
304
305         /**
306          * \return The filesystem name on the volume.
307          */
308         std::string
309         getFSType() const;
310
311         /**
312          * \return The filesystem usage purpose.
313          */
314         std::string
315         getFSUsage() const;
316
317         /**
318          * \return The mount point of the volume.
319          */
320         std::string
321         getMountPoint() const;
322
323       private:
324         friend class HalContext;
325         friend class HalDrive;
326         HalVolume(HalVolume_Impl *impl);
327
328         zypp::RW_pointer<HalVolume_Impl>  v_impl;
329       };
330
331
332       ////////////////////////////////////////////////////////////////
333     } // namespace hal
334     //////////////////////////////////////////////////////////////////
335     //////////////////////////////////////////////////////////////////
336   } // namespace target
337   ////////////////////////////////////////////////////////////////////
338   ////////////////////////////////////////////////////////////////////
339 } // namespace zypp
340 //////////////////////////////////////////////////////////////////////
341
342 #endif // ZYPP_TARGET_HAL_HALCONTEXT_H
343
344 /*
345 ** vim: set ts=2 sts=2 sw=2 ai et:
346 */