1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg_private.h"
9 #include "simix/smx_process_private.h"
11 #include "simgrid/s4u/host.hpp"
13 using namespace simgrid;
15 boost::unordered_map<std::string, simgrid::s4u::Host*> *simgrid::s4u::Host::hosts
16 = new boost::unordered_map<std::string, simgrid::s4u::Host*>();
18 s4u::Host::Host(const char*name) {
19 p_sghost = sg_host_by_name(name);
21 xbt_die("No such host: %s",name); //FIXME: raise an exception
24 s4u::Host *s4u::Host::byName(std::string name) {
25 s4u::Host * res = NULL;
27 res = hosts->at(name);
28 } catch (std::out_of_range& e) {}
31 res = new s4u::Host(name.c_str());
32 hosts->insert({name,res});
36 s4u::Host *s4u::Host::current(){
37 smx_process_t smx_proc = SIMIX_process_self();
39 xbt_die("Cannot call Host::current() from the maestro context");
41 return s4u::Host::byName(SIMIX_host_get_name(SIMIX_process_get_host(smx_proc)));
44 const char* s4u::Host::getName() {
45 return sg_host_name(p_sghost);
48 void s4u::Host::turnOn() {
49 simcall_host_on(p_sghost);
51 void s4u::Host::turnOff() {
52 simcall_host_off(p_sghost);
54 bool s4u::Host::isOn() {
55 return simcall_host_get_state(p_sghost);