]> AND Private Git Repository - loba.git/blob - hostdata.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Update XML files to version 4.
[loba.git] / hostdata.cpp
1 #include <algorithm>
2 #include <cstring>
3 #include <stdexcept>
4 #include <xbt/log.h>
5 #include <xbt/sysdep.h>
6
7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
8
9 #include "misc.h"
10 #include "options.h"
11
12 #include "hostdata.h"
13
14 std::vector<hostdata> hostdata::hosts;
15
16 void hostdata::create()
17 {
18     xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
19     int nhosts = xbt_dynar_length(host_dynar);
20     msg_host_t* host_list = static_cast<msg_host_t*>(xbt_dynar_to_array(host_dynar));
21     // only sort hosts for automatically created deployment
22     if (opt::auto_depl::enabled)
23         std::sort(host_list, host_list + nhosts,
24                   [](msg_host_t a, msg_host_t b) {
25                       return std::strcmp(MSG_host_get_name(a), MSG_host_get_name(b)) < 0;
26                   });
27     hosts.assign(host_list, host_list + nhosts);
28     xbt_free(host_list);
29
30     e_xbt_log_priority_t logp = xbt_log_priority_verbose;
31     if (!LOG_ISENABLED(logp))
32         return;
33     XBT_LOG(logp, "Got %zu hosts.", hosts.size());
34     for (int i = 0; i < nhosts; i++) {
35         XBT_LOG(logp, "Host #%d named \"%s\".", i, hosts[i].get_name());
36     }
37 }
38
39 void hostdata::destroy()
40 {
41     // hosts are automatically destroyed...
42 }
43
44 hostdata::hostdata(msg_host_t host)
45     : name(MSG_host_get_name(host))
46     , ctrl_mbox(std::string(name) + "_ctrl")
47     , data_mbox(std::string(name) + "_data")
48 {
49     MSG_host_set_data(host, this);
50 }
51
52 hostdata::~hostdata()
53 {
54 }