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 "src/msg/msg_private.h"
9 #include "src/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)
22 p_inferior = sg_host_by_name(name);
24 xbt_die("No such host: %s",name); //FIXME: raise an exception
31 Host *Host::byName(std::string name) {
34 res = hosts->at(name);
35 } catch (std::out_of_range& e) {}
38 res = new Host(name.c_str());
39 hosts->insert({name,res});
43 Host *Host::current(){
44 smx_process_t smx_proc = SIMIX_process_self();
46 xbt_die("Cannot call Host::current() from the maestro context");
48 return Host::byName(sg_host_get_name(SIMIX_process_get_host(smx_proc)));
51 const char* Host::name() {
52 return sg_host_get_name(p_inferior);
56 simcall_host_on(p_inferior);
58 void Host::turnOff() {
59 simcall_host_off(p_inferior);
62 return sg_host_get_state(p_inferior);
65 boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
67 mounts = new boost::unordered_map<std::string, Storage&> ();
69 xbt_dict_t dict = simcall_host_get_mounted_storage_list(p_inferior);
71 xbt_dict_cursor_t cursor;
74 xbt_dict_foreach(dict, cursor, mountname, storagename) {
75 mounts->insert({mountname, Storage::byName(storagename)});
84 } // namespace simgrid