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"
12 #include "simgrid/s4u/storage.hpp"
17 boost::unordered_map<std::string, Host*> *Host::hosts
18 = new boost::unordered_map<std::string, Host*>();
20 Host::Host(const char*name) {
21 p_inferior = sg_host_by_name(name);
23 xbt_die("No such host: %s",name); //FIXME: raise an exception
30 Host *Host::byName(std::string name) {
33 res = hosts->at(name);
34 } catch (std::out_of_range& e) {}
37 res = new Host(name.c_str());
38 hosts->insert({name,res});
42 Host *Host::current(){
43 smx_process_t smx_proc = SIMIX_process_self();
45 xbt_die("Cannot call Host::current() from the maestro context");
47 return Host::byName(SIMIX_host_get_name(SIMIX_process_get_host(smx_proc)));
50 const char* Host::name() {
51 return sg_host_name(p_inferior);
55 simcall_host_on(p_inferior);
57 void Host::turnOff() {
58 simcall_host_off(p_inferior);
61 return simcall_host_get_state(p_inferior);
64 boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
66 mounts = new boost::unordered_map<std::string, Storage&> ();
68 xbt_dict_t dict = simcall_host_get_mounted_storage_list(p_inferior);
70 xbt_dict_cursor_t cursor;
73 xbt_dict_foreach(dict, cursor, mountname, storagename) {
74 mounts->insert({mountname, Storage::byName(storagename)});
83 } // namespace simgrid