|
1 | | -#ifndef PYLIBBPF_MAPS_H |
2 | | -#define PYLIBBPF_MAPS_H |
| 1 | +#ifndef PYLIBBPF_BPF_MAP_H |
| 2 | +#define PYLIBBPF_BPF_MAP_H |
3 | 3 |
|
4 | 4 | #include <libbpf.h> |
5 | 5 | #include <pybind11/pybind11.h> |
6 | 6 | #include <vector> |
7 | 7 | #include <string> |
8 | 8 |
|
9 | | -#include "bpf_program.h" |
| 9 | +class BpfObject; |
10 | 10 |
|
11 | 11 | namespace py = pybind11; |
12 | 12 |
|
13 | 13 | class BpfMap { |
14 | 14 | private: |
| 15 | + std::weak_ptr<BpfObject> parent_obj_; |
15 | 16 | struct bpf_map *map_; |
16 | | - int map_fd = -1; |
17 | | - //TODO: turn below into a shared pointer and ref count it so that there is no resource leakage |
18 | | - BpfProgram *bpf_program; |
| 17 | + int map_fd_; |
| 18 | + std::string map_name_; |
19 | 19 |
|
20 | 20 | public: |
21 | | - BpfMap(BpfProgram *program_, const py::object &map_from_python); |
| 21 | + BpfMap(std::shared_ptr<BpfObject>, struct bpf_map *raw_map, const std::string &map_name); |
22 | 22 |
|
23 | 23 | ~BpfMap() = default; |
24 | 24 |
|
25 | 25 | [[nodiscard]] py::object lookup(const py::object &key) const; |
26 | | - |
27 | 26 | void update(const py::object &key, const py::object &value) const; |
28 | | - |
29 | 27 | void delete_elem(const py::object &key) const; |
30 | | - |
31 | 28 | py::list get_next_key(const py::object &key = py::none()) const; |
32 | | - |
33 | 29 | py::dict items() const; |
34 | | - |
35 | 30 | py::list keys() const; |
36 | | - |
37 | 31 | py::list values() const; |
38 | 32 |
|
39 | | - [[nodiscard]] std::string get_name() const; |
40 | | - |
41 | | - int get_type() const; |
42 | | - |
43 | | - int get_key_size() const; |
44 | | - |
45 | | - int get_value_size() const; |
46 | | - |
47 | | - int get_max_entries() const; |
| 33 | + [[nodiscard]] std::string get_name() const { return map_name_; } |
| 34 | + [[nodiscard]] int get_fd() const { return map_fd_; } |
| 35 | + [[nodiscard]] int get_type() const; |
| 36 | + [[nodiscard]] int get_key_size() const; |
| 37 | + [[nodiscard]] int get_value_size() const; |
| 38 | + [[nodiscard]] int get_max_entries() const; |
48 | 39 |
|
49 | 40 | private: |
50 | 41 | static std::vector<uint8_t> python_to_bytes(const py::object &obj, size_t size); |
51 | | - |
52 | 42 | static py::object bytes_to_python(const std::vector<uint8_t> &data); |
53 | 43 | }; |
54 | 44 |
|
|
0 commit comments