aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/udev_helper.hpp
blob: 055a93cee11a9de5711c27b6f3476adc2e737e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Copyright 2017 Ettus Research (National Instruments)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#include <libudev.h>
#include <string>
#include <vector>

namespace mpm {
    /*!
     * The udev_helper class:
     *
     * talks to libudev and holds a udev context. Device enumeration is done
     * once during initialization.
     * On destruction the udev context is unreferenced again.
     */
    class udev_helper{
    public:
        udev_helper();
        ~udev_helper();
        /*!
         * Return the nvmem device associated with the parent address
         * \param address of the parent platform driver
         * \return a string containing the name of file of the device in /sys
         */
        std::string get_eeprom(const std::string &address);
        /*!
         * Find spidevices associated with the spi_master
         * \param address of the parent platform driver
         * \return a vector of string containing the device paths is /dev
         */
        std::vector<std::string> get_spidev_nodes(const std::string &spi_master);

    private:
        udev *_udev;
        udev_enumerate *_enumerate;
    };
}

#ifdef LIBMPM_PYTHON
void export_udev_helper(){
    LIBMPM_BOOST_PREAMBLE("udev")
    bp::class_<mpm::udev_helper>("udev_helper", bp::init<>())
        .def("get_eeprom", &mpm::udev_helper::get_eeprom)
        .def("get_spidev_nodes", &mpm::udev_helper::get_spidev_nodes)
    ;
}
#endif