mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-03-23 05:31:31 +00:00
Use shared_from_this while creating BpfProgram or BpfMap, make get_map_names and get_program_names non-const
This commit is contained in:
@ -74,7 +74,7 @@ void BpfObject::load() {
|
|||||||
|
|
||||||
// ==================== Program Methods ====================
|
// ==================== Program Methods ====================
|
||||||
|
|
||||||
py::list BpfObject::get_program_names() const {
|
py::list BpfObject::get_program_names() {
|
||||||
if (!loaded_) {
|
if (!loaded_) {
|
||||||
throw BpfException("BPF object not loaded");
|
throw BpfException("BPF object not loaded");
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ BpfObject::_get_or_create_program(struct bpf_program *prog) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create and cache
|
// Create and cache
|
||||||
auto bpf_prog = std::make_shared<BpfProgram>(this, prog, prog_name);
|
auto bpf_prog = std::make_shared<BpfProgram>(shared_from_this(), prog, prog_name);
|
||||||
prog_cache_[prog_name] = bpf_prog;
|
prog_cache_[prog_name] = bpf_prog;
|
||||||
|
|
||||||
return bpf_prog;
|
return bpf_prog;
|
||||||
@ -125,7 +125,7 @@ std::shared_ptr<BpfProgram> BpfObject::get_program(const std::string &name) {
|
|||||||
|
|
||||||
// Create and cache
|
// Create and cache
|
||||||
struct bpf_program *raw_prog = find_program_by_name(name);
|
struct bpf_program *raw_prog = find_program_by_name(name);
|
||||||
auto prog = std::make_shared<BpfProgram>(this, raw_prog, name);
|
auto prog = std::make_shared<BpfProgram>(shared_from_this(), raw_prog, name);
|
||||||
prog_cache_[name] = prog;
|
prog_cache_[name] = prog;
|
||||||
|
|
||||||
return prog;
|
return prog;
|
||||||
@ -148,8 +148,8 @@ BpfObject::find_program_by_name(const std::string &name) const {
|
|||||||
|
|
||||||
py::dict BpfObject::get_cached_programs() const {
|
py::dict BpfObject::get_cached_programs() const {
|
||||||
py::dict programs;
|
py::dict programs;
|
||||||
for (const auto &[name, prog] : prog_cache_) {
|
for (const auto &entry : prog_cache_) {
|
||||||
programs[name] = prog;
|
programs[entry.first.c_str()] = entry.second;
|
||||||
}
|
}
|
||||||
return programs;
|
return programs;
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ py::dict BpfObject::attach_all() {
|
|||||||
|
|
||||||
// ==================== Map Methods ====================
|
// ==================== Map Methods ====================
|
||||||
|
|
||||||
py::list BpfObject::get_map_names() const {
|
py::list BpfObject::get_map_names() {
|
||||||
if (!loaded_) {
|
if (!loaded_) {
|
||||||
throw BpfException("BPF object not loaded");
|
throw BpfException("BPF object not loaded");
|
||||||
}
|
}
|
||||||
@ -249,8 +249,8 @@ struct bpf_map *BpfObject::find_map_by_name(const std::string &name) const {
|
|||||||
|
|
||||||
py::dict BpfObject::get_cached_maps() const {
|
py::dict BpfObject::get_cached_maps() const {
|
||||||
py::dict maps;
|
py::dict maps;
|
||||||
for (const auto &[name, map] : maps_cache_) {
|
for (const auto &entry : maps_cache_) {
|
||||||
maps[name] = map;
|
maps[entry.first.c_str()] = entry.second;
|
||||||
}
|
}
|
||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public:
|
|||||||
py::dict attach_all();
|
py::dict attach_all();
|
||||||
|
|
||||||
// Program access
|
// Program access
|
||||||
[[nodiscard]] py::list get_program_names() const;
|
[[nodiscard]] py::list get_program_names();
|
||||||
[[nodiscard]] std::shared_ptr<BpfProgram>
|
[[nodiscard]] std::shared_ptr<BpfProgram>
|
||||||
get_program(const std::string &name);
|
get_program(const std::string &name);
|
||||||
[[nodiscard]] struct bpf_program *
|
[[nodiscard]] struct bpf_program *
|
||||||
@ -73,7 +73,7 @@ public:
|
|||||||
[[nodiscard]] py::dict get_cached_programs() const;
|
[[nodiscard]] py::dict get_cached_programs() const;
|
||||||
|
|
||||||
// Map access
|
// Map access
|
||||||
[[nodiscard]] py::list get_map_names() const;
|
[[nodiscard]] py::list get_map_names();
|
||||||
[[nodiscard]] std::shared_ptr<BpfMap> get_map(const std::string &name);
|
[[nodiscard]] std::shared_ptr<BpfMap> get_map(const std::string &name);
|
||||||
[[nodiscard]] struct bpf_map *find_map_by_name(const std::string &name) const;
|
[[nodiscard]] struct bpf_map *find_map_by_name(const std::string &name) const;
|
||||||
[[nodiscard]] py::dict get_cached_maps() const;
|
[[nodiscard]] py::dict get_cached_maps() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user