Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
tracker_manager.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2  *
3  * Copyright (c) 2022, 郑昱笙,濮雯旭,张典典(牛校牛子队)
4  * All rights reserved.
5  */
6 
7 #ifndef TRACKER_MANAGER_H
8 #define TRACKER_MANAGER_H
9 
10 #include <condition_variable>
11 #include <iostream>
12 #include <mutex>
13 #include <thread>
14 #include <map>
15 #include "model/tracker.h"
16 
18 
22 {
23  private:
24  struct tracker_base_data {
25  std::string name;
26  std::unique_ptr<tracker_base> tracker;
27  };
28  int id_count = 1;
29  std::map<int, tracker_base_data> trackers;
30 
31  public:
33  spdlog::debug("tracker_manager::~tracker_manager()");
34  }
35  // remove a tracker with id
36  void remove_tracker(int id)
37  {
38  trackers.erase(id);
39  }
40  // get tracker lists
41  // return a list of tracker id and name
42  std::vector<std::tuple<int, std::string>> get_tracker_list()
43  {
44  std::vector<std::tuple<int, std::string>> list;
45  for (auto &[id, data] : trackers) {
46  list.push_back({id, data.name});
47  }
48  return list;
49  }
50  // start a tracker and return id
51  std::size_t start_tracker(std::unique_ptr<tracker_base> tracker_ptr, const std::string &name)
52  {
53  if (!tracker_ptr)
54  {
55  std::cout << "tracker_ptr is null in start_tracker\n";
56  return 0;
57  }
58  tracker_ptr->thread = std::jthread(&tracker_base::start_tracker, tracker_ptr.get());
59  trackers.emplace(id_count++, tracker_base_data{name, std::move(tracker_ptr)});
60  return trackers.size() - 1;
61  }
62  // stop all tracker
64  {
65  trackers.clear();
66  }
67 };
68 
69 #endif
tracker.h
tracker_base::start_tracker
virtual void start_tracker(void)=0
start the tracker thread
tracker_manager::get_tracker_list
std::vector< std::tuple< int, std::string > > get_tracker_list()
Definition: tracker_manager.h:42
tracker_manager::start_tracker
std::size_t start_tracker(std::unique_ptr< tracker_base > tracker_ptr, const std::string &name)
Definition: tracker_manager.h:51
tracker_manager::~tracker_manager
~tracker_manager()
Definition: tracker_manager.h:32
tracker_manager
tracker manager for owning and managing tracker instances
Definition: tracker_manager.h:21
tracker_manager::remove_tracker
void remove_tracker(int id)
Definition: tracker_manager.h:36
tracker_manager::remove_all_trackers
void remove_all_trackers()
Definition: tracker_manager.h:63