File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -206,7 +206,7 @@ std::shared_ptr<BpfMap> BpfObject::get_map(const std::string& name) {
206206
207207 // Create and cache
208208 struct bpf_map *raw_map = find_map_by_name (name);
209- auto map = std::make_shared<BpfMap>(this , raw_map, name);
209+ auto map = std::make_shared<BpfMap>(shared_from_this () , raw_map, name);
210210 maps_cache_[name] = map;
211211
212212 return map;
@@ -227,7 +227,7 @@ std::shared_ptr<BpfMap> BpfObject::_get_or_create_map(struct bpf_map *map) {
227227 }
228228
229229 // Create and cache
230- auto bpf_map = std::make_shared<BpfMap>(this , map, map_name);
230+ auto bpf_map = std::make_shared<BpfMap>(shared_from_this () , map, map_name);
231231 maps_cache_[map_name] = bpf_map;
232232
233233 return bpf_map;
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class BpfMap;
1919 * This is the main entry point for loading BPF programs.
2020 * Owns the bpf_object* and manages all programs and maps within it.
2121 */
22- class BpfObject {
22+ class BpfObject : public std ::enable_shared_from_this<BpfObject> {
2323private:
2424 struct bpf_object *obj_;
2525 std::string object_path_;
Original file line number Diff line number Diff line change 33
44#include < libbpf.h>
55#include < pybind11/stl.h>
6+ #include < memory>
67#include < string>
78
8- namespace py = pybind11 ;
9+ class BpfObject ;
910
1011class BpfProgram {
1112private:
12- struct bpf_object *obj_ ;
13+ std::weak_ptr<BpfObject> parent_obj_ ;
1314 struct bpf_program *prog_;
1415 struct bpf_link *link_;
15- std::string object_path_;
1616 std::string program_name_;
17- std::vector<std::pair<bpf_program *, bpf_link *> > programs;
1817
1918public:
20- explicit BpfProgram (std::string object_path , std::string program_name = " " );
19+ explicit BpfProgram (std::shared_ptr<BpfObject> parent, struct bpf_program *raw_prog , std::string program_name = " " );
2120
2221 ~BpfProgram ();
2322
24- struct bpf_object *get_obj () const ;
25-
26- bool load ();
23+ BpfProgram (const BpfProgram&) = delete ;
24+ BpfProgram& operator =(const BpfProgram&) = delete ;
25+ BpfProgram (BpfProgram&&) noexcept ;
26+ BpfProgram& operator =(BpfProgram&&) noexcept ;
2727
2828 bool attach ();
29-
30- bool destroy ();
29+ bool detach ();
3130
3231 void load_and_attach ();
3332
34- [[nodiscard]] bool is_loaded () const { return obj_ != nullptr ; }
3533 [[nodiscard]] bool is_attached () const { return link_ != nullptr ; }
34+ [[nodiscard]] std::string get_name () const { return program_name_; }
3635};
3736
3837#endif // PYLIBBPF_BPF_PROGRAM_H
You can’t perform that action at this time.
0 commit comments