1 /* Copyright (c) 2017-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
8 #include <unordered_map>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation");
14 /* - Display information on the disks mounted by the current host */
15 XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->get_cname());
17 /* - Retrieve all mount points of current host */
18 std::unordered_map<std::string, simgrid::s4u::Storage*> const& storage_list =
19 simgrid::s4u::Host::current()->get_mounted_storages();
21 /* - For each disk mounted on host, display disk name and mount point */
22 for (auto const& kv : storage_list)
23 XBT_INFO("Storage name: %s, mount name: %s", kv.second->get_cname(), kv.first.c_str());
25 /* - Write 200,000 bytes on Disk4 */
26 simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk4");
27 sg_size_t write = storage->write(200000);
28 XBT_INFO("Wrote %llu bytes on 'Disk4'", write);
30 /* - Now read 200,000 bytes */
31 sg_size_t read = storage->read(200000);
32 XBT_INFO("Read %llu bytes on 'Disk4'", read);
34 /* - Attach some user data to disk1 */
35 XBT_INFO("*** Get/set data for storage element: Disk4 ***");
37 std::string* data = static_cast<std::string*>(storage->get_data());
39 XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data");
41 storage->set_data(new std::string("Some user data"));
42 data = static_cast<std::string*>(storage->get_data());
43 XBT_INFO("Set and get data: '%s'", data->c_str());
47 int main(int argc, char** argv)
49 simgrid::s4u::Engine e(&argc, argv);
50 e.load_platform(argv[1]);
52 simgrid::s4u::Actor::create("", simgrid::s4u::Host::by_name("denise"), host);
55 XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());