Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / s4u / s4u_file.cpp
1 /* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/simix.h"
7 #include "src/msg/msg_private.h"
8 #include "xbt/log.h"
9
10 #include "simgrid/s4u/Actor.hpp"
11 #include "simgrid/s4u/Comm.hpp"
12 #include "simgrid/s4u/File.hpp"
13 #include "simgrid/s4u/Host.hpp"
14 #include "simgrid/s4u/Mailbox.hpp"
15 #include "simgrid/s4u/Storage.hpp"
16
17 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
18
19 namespace simgrid {
20 namespace s4u {
21
22 File::File(const char* fullpath, void* userdata) : path_(fullpath), userdata_(userdata)
23 {
24   // this cannot fail because we get a xbt_die if the mountpoint does not exist
25   pimpl_           = simcall_file_open(fullpath, Host::current());
26   xbt_dynar_t info = simcall_file_get_info(pimpl_);
27   storage_type     = xbt_dynar_pop_as(info, char*);
28   storageId        = xbt_dynar_pop_as(info, char*);
29   mount_point      = xbt_dynar_pop_as(info, char*);
30   xbt_dynar_free(&info);
31 }
32
33 File::~File() {
34   //  Host::current()->extension<simgrid::MsgHostExt>()->file_descriptor_table->push_back(desc_id_);
35   simcall_file_close(pimpl_, Host::current());
36 }
37
38 sg_size_t File::read(sg_size_t size) {
39   return simcall_file_read(pimpl_, size, Host::current());
40 }
41 sg_size_t File::write(sg_size_t size) {
42   return simcall_file_write(pimpl_,size, Host::current());
43 }
44 sg_size_t File::size() {
45   return simcall_file_get_size(pimpl_);
46 }
47
48 void File::seek(sg_size_t pos) {
49   simcall_file_seek(pimpl_,pos,SEEK_SET);
50 }
51 sg_size_t File::tell() {
52   return simcall_file_tell(pimpl_);
53 }
54 void File::move(const char*fullpath) {
55   simcall_file_move(pimpl_,fullpath);
56 }
57 void File::unlink() {
58   sg_host_t attached = Host::current(); // FIXME: we should check where this file is attached
59   simcall_file_unlink(pimpl_,attached);
60 }
61
62 }} // namespace simgrid::s4u