X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/02fbf5e463830a439464adae8626cd4f2dad27fd..8a0e560ec45d87b09644b07ea26ddb95d589c670:/examples/s4u/io-file-remote/s4u-io-file-remote.cpp diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp index 46fbede2e3..f93c062440 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -13,37 +13,34 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example") static int host(int argc, char* argv[]) { - simgrid::s4u::File* file = new simgrid::s4u::File(argv[1], nullptr); - const char* filename = file->getPath(); + simgrid::s4u::File file(argv[1], nullptr); + const char* filename = file.getPath(); XBT_INFO("Opened file '%s'", filename); - file->dump(); + file.dump(); - XBT_INFO("Try to read %llu from '%s'", file->size(), filename); - sg_size_t read = file->read(file->size()); - XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file->tell()); - XBT_INFO("Seek back to the begining of the stream..."); - file->seek(0, SEEK_SET); - XBT_INFO("Offset is now at: %llu", file->tell()); - - delete file; + XBT_INFO("Try to read %llu from '%s'", file.size(), filename); + sg_size_t read = file.read(file.size()); + XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file.tell()); + XBT_INFO("Seek back to the beginning of the stream..."); + file.seek(0, SEEK_SET); + XBT_INFO("Offset is now at: %llu", file.tell()); if (argc > 5) { - file = new simgrid::s4u::File(argv[2], nullptr); - filename = file->getPath(); + simgrid::s4u::File remoteFile(argv[2], nullptr); + filename = remoteFile.getPath(); XBT_INFO("Opened file '%s'", filename); - XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename); - sg_size_t write = file->write(file->size() * 1024); + XBT_INFO("Try to write %llu MiB to '%s'", remoteFile.size() / 1024, filename); + sg_size_t write = remoteFile.write(remoteFile.size() * 1024); XBT_INFO("Have written %llu bytes to '%s'.", write, filename); if (std::stoi(argv[5]) != 0) { - XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), + XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]); + remoteFile.remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]); } else { - XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), + XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - delete file; + remoteFile.remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); } } @@ -57,15 +54,17 @@ int main(int argc, char** argv) e.loadPlatform(argv[1]); e.registerFunction("host", host); e.loadDeployment(argv[2]); + std::map allStorages; + simgrid::s4u::getStorageList(&allStorages); - for (auto const& s : *simgrid::s4u::allStorages()) { + for (auto const& s : allStorages) { XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); } e.run(); - for (auto const& s : *simgrid::s4u::allStorages()) { + for (auto const& s : allStorages) { XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); }