]> AND Public Git Repository - simgrid.git/blob - src/instr/instr_paje_containers.hpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement test with wait_for...
[simgrid.git] / src / instr / instr_paje_containers.hpp
1 /* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef INSTR_PAJE_CONTAINERS_HPP
7 #define INSTR_PAJE_CONTAINERS_HPP
8
9 #include <map>
10 #include <simgrid/s4u/Host.hpp>
11 #include <string>
12 #include <xbt/signal.hpp>
13
14 namespace simgrid::instr {
15 class Type;
16 class LinkType;
17 class StateType;
18 class VariableType;
19
20 class Container {
21   friend class NetZoneContainer;
22   static Container* root_container_;
23   static std::map<std::string, Container*, std::less<>> all_containers_;
24
25   long long int id_;
26   std::string name_; /* Unique name of this container */
27   Type* type_;       /* Type of this container */
28   Container* parent_;
29   std::map<std::string, Container*, std::less<>> children_;
30
31 protected:
32   static void set_root(Container* root) { root_container_ = root; }
33
34 private:
35   static xbt::signal<void(Container const&)> on_creation;
36   static xbt::signal<void(Container const&)> on_destruction;
37
38 public:
39   static void on_creation_cb(const std::function<void(Container const&)>& cb) { on_creation.connect(cb); }
40   static void on_destruction_cb(const std::function<void(Container const&)>& cb) { on_destruction.connect(cb); }
41
42   explicit Container(const std::string& name, const std::string& type_name, Container* parent);
43   Container(const Container&) = delete;
44   Container& operator=(const Container&) = delete;
45   virtual ~Container();
46
47
48   static Container* by_name_or_null(const std::string& name);
49   static Container* by_name(const std::string& name);
50   const std::string& get_name() const { return name_; }
51   const char* get_cname() const { return name_.c_str(); }
52   long long int get_id() const { return id_; }
53   void remove_from_parent();
54
55   Container* get_parent() const { return parent_; }
56   Type* get_type() const { return type_; }
57   StateType* get_state(const std::string& name);
58   LinkType* get_link(const std::string& name);
59   VariableType* get_variable(const std::string& name);
60   void create_child(const std::string& name, const std::string& type_name);
61   Container* get_child_by_name(const std::string& name) const { return children_.at(name); }
62   static Container* get_root() { return root_container_; }
63 };
64
65 class NetZoneContainer : public Container {
66 public:
67   NetZoneContainer(const std::string& name, unsigned int level, NetZoneContainer* parent);
68 };
69
70 class RouterContainer : public Container {
71 public:
72   RouterContainer(const std::string& name, Container* parent);
73 };
74
75 class HostContainer : public Container {
76 public:
77   HostContainer(s4u::Host const& host, NetZoneContainer* parent);
78 };
79 } // namespace simgrid::instr
80 #endif