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

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