Imported Upstream version 17.14.0
[platform/upstream/libzypp.git] / zypp / target / modalias / Modalias.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/modalias/Modalias.h
10  *
11 */
12 #ifndef ZYPP_TARGET_MODALIAS_MODALIAS_H
13 #define ZYPP_TARGET_MODALIAS_MODALIAS_H
14
15 #include <iosfwd>
16 #include <vector>
17 #include <string>
18
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/IdString.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25   ///////////////////////////////////////////////////////////////////
26   namespace target
27   { /////////////////////////////////////////////////////////////////
28
29     ///////////////////////////////////////////////////////////////////
30     //
31     //  CLASS NAME : Modalias
32     //
33     /** Hardware abstaction layer singleton.
34      */
35     class Modalias
36     {
37       friend std::ostream & operator<<( std::ostream & str, const Modalias & obj );
38
39       public:
40         /** Implementation  */
41         struct Impl;
42
43       public:
44         typedef std::vector<std::string> ModaliasList;
45
46         /** Singleton access. */
47         static Modalias & instance();
48
49         /** Dtor */
50         ~Modalias();
51
52       public:
53
54         /** Checks if a device on the system matches a modalias pattern.
55          *
56          * Returns \c false if no matching device is found, and the modalias
57          * of the first matching device otherwise. (More than one device
58          * may match a given pattern.)
59          *
60          * On a system that has the following device,
61          * \code
62          *   pci:v00008086d0000265Asv00008086sd00004556bc0Csc03i00
63          * \endcode
64          * the following query will return \c true:
65          * \code
66          *   modalias_matches("pci:v00008086d0000265Asv*sd*bc*sc*i*")
67          * \endcode
68          */
69         bool query( IdString cap_r ) const
70         { return query( cap_r.c_str() ); }
71         /** \overload */
72         bool query( const char * cap_r ) const;
73         /** \overload */
74         bool query( const std::string & cap_r ) const
75         { return query( cap_r.c_str() ); }
76
77         /** List of modaliases found on system */
78         const ModaliasList & modaliasList() const;
79
80         /** Manually set list of modaliases to use */
81         void modaliasList( ModaliasList newlist_r );
82
83       private:
84         /** Singleton ctor. */
85         Modalias();
86
87         /** Pointer to implementation */
88         RW_pointer<Impl> _pimpl;
89     };
90     ///////////////////////////////////////////////////////////////////
91
92     /** \relates Modalias Stream output */
93     std::ostream & operator<<( std::ostream & str, const Modalias & obj );
94
95     /////////////////////////////////////////////////////////////////
96   } // namespace target
97   ///////////////////////////////////////////////////////////////////
98   /////////////////////////////////////////////////////////////////
99 } // namespace zypp
100 ///////////////////////////////////////////////////////////////////
101 #endif // ZYPP_TARGET_MODALIAS_MODALIAS_H