1 /* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SURF_HOST_INTERFACE_HPP
7 #define SURF_HOST_INTERFACE_HPP
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/kernel/resource/CpuImpl.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12 #include "src/kernel/resource/LinkImpl.hpp"
13 #include <xbt/PropertyHolder.hpp>
24 /** @ingroup SURF_host_interface
25 * @brief SURF Host model interface class
26 * @details A model is an object which handle the interactions between its Resources and its Actions
28 class XBT_PRIVATE HostModel : public Model {
31 virtual Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
32 const double* bytes_amount, double rate) = 0;
38 /** @ingroup SURF_host_interface
39 * @brief SURF Host interface class
40 * @details A host represents a machine with an aggregation of a Cpu, a RoutingEdge and Disk(s)
42 class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
44 boost::intrusive::list<actor::ActorImpl,
45 boost::intrusive::member_hook<actor::ActorImpl, boost::intrusive::list_member_hook<>,
46 &actor::ActorImpl::host_actor_list_hook>>;
48 ActorList actor_list_;
49 std::vector<actor::ProcessArg*> actors_at_boot_;
51 std::map<std::string, DiskImpl*, std::less<>> disks_;
52 xbt::string name_{"noname"};
56 virtual ~HostImpl(); // Use destroy() instead of this destructor.
57 HostImpl(const std::string& name, s4u::Host* piface);
60 friend VirtualMachineImpl;
61 explicit HostImpl(const std::string& name);
63 void destroy(); // Must be called instead of the destructor
65 std::vector<s4u::Disk*> get_disks() const;
66 s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
67 void add_disk(const s4u::Disk* disk);
68 void remove_disk(const std::string& name);
70 virtual const s4u::Host* get_iface() const { return &piface_; }
71 virtual s4u::Host* get_iface() { return &piface_; }
73 /** Retrieves the name of that host as a C++ string */
74 xbt::string const& get_name() const { return name_; }
75 /** Retrieves the name of that host as a C string */
76 const char* get_cname() const { return name_.c_str(); }
79 void turn_off(const actor::ActorImpl* issuer);
80 std::vector<s4u::ActorPtr> get_all_actors();
81 size_t get_actor_count() const;
82 void add_actor(actor::ActorImpl* actor) { actor_list_.push_back(*actor); }
83 void remove_actor(actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); }
84 void add_actor_at_boot(actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); }
88 template <class F> void foreach_actor(F function)
90 for (auto& actor : actor_list_)
94 } // namespace resource
96 } // namespace simgrid
98 #endif /* HOST_INTERFACE_HPP */