Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement some more getters in surf::Link and s4u::Link
[simgrid.git] / include / simgrid / s4u / File.hpp
1 /* Copyright (c) 2006-2015. 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 #ifndef SIMGRID_S4U_FILE_HPP
7 #define SIMGRID_S4U_FILE_HPP
8
9 #include <xbt/base.h>
10
11 #include <simgrid/simix.h>
12 #include <string>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** @brief A simulated file
18  *
19  * Used to simulate the time it takes to access to a file, but does not really store any information.
20  *
21  * They are located on @ref simgrid::s4u::Storage that are accessed from a given @ref simgrid::s4u::Host through
22  * mountpoints.
23  * For now, you cannot change the mountpoints programatically, and must declare them from your platform file.
24  */
25 XBT_PUBLIC_CLASS File
26 {
27 public:
28   File(std::string fullpath, void* userdata);
29   File(std::string fullpath, sg_host_t host, void* userdata);
30   ~File();
31
32   /** Retrieves the path to the file */
33   const char* getPath() { return path_.c_str(); }
34
35   /** Simulates a local read action. Returns the size of data actually read */
36   sg_size_t read(sg_size_t size);
37
38   /** Simulates a write action. Returns the size of data actually written. */
39   sg_size_t write(sg_size_t size);
40
41   /** Allows to store user data on that host */
42   void setUserdata(void* data) { userdata_ = data; }
43   /** Retrieves the previously stored data */
44   void* getUserdata() { return userdata_; }
45
46   /** Retrieve the datasize */
47   sg_size_t size();
48
49   /** Sets the file head to the given position. */
50   void seek(sg_offset_t pos);
51   void seek(sg_offset_t pos, int origin);
52
53   /** Retrieves the current file position */
54   sg_size_t tell();
55
56   /** Rename a file. WARNING: It is forbidden to move the file to another mount point */
57   void move(std::string fullpath);
58
59   /** Remove a file from disk */
60   int unlink();
61
62   std::string storage_type;
63   std::string storageId;
64   std::string mount_point;
65   int desc_id = 0;
66
67 private:
68   surf_file_t pimpl_ = nullptr;
69   std::string path_;
70   void* userdata_ = nullptr;
71 };
72 }
73 } // namespace simgrid::s4u
74
75 #endif /* SIMGRID_S4U_HOST_HPP */