Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar is picky, so let's be verbose
[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
13 namespace simgrid {
14 namespace s4u {
15
16 class Storage;
17
18 /** @brief A simulated file
19  *
20  * Used to simulate the time it takes to access to a file, but does not really store any information.
21  *
22  * They are located on @ref simgrid::s4u::Storage that are accessed from a given @ref simgrid::s4u::Host through 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 public:
27   File(const char *fullpath, void* userdata);
28   ~File();
29
30   /** Retrieves the path to the file */
31   const char *path() { return path_;}
32
33   /** Simulates a read action. Returns the size of data actually read
34    *
35    *  FIXME: reading from a remotely mounted disk is not implemented yet.
36    *  Any storage is considered as local, and no network communication ever occur.
37    */
38   sg_size_t read(sg_size_t size);
39   /** Simulates a write action. Returns the size of data actually written.
40    *
41    *  FIXME: reading from a remotely mounted disk is not implemented yet.
42    *  Any storage is considered as local, and no network communication ever occur.
43    */
44   sg_size_t write(sg_size_t size);
45
46   /** Allows to store user data on that host */
47   void setUserdata(void *data) {userdata_ = data;}
48   /** Retrieves the previously stored data */
49   void* userdata() {return userdata_;}
50
51   /** Retrieve the datasize */
52   sg_size_t size();
53
54   /** Sets the file head to the given position. */
55   void seek(sg_size_t pos);
56   /** Retrieves the current file position */
57   sg_size_t tell();
58
59   /** Rename a file
60    *
61    * WARNING: It is forbidden to move the file to another mount point */
62   void move(const char*fullpath);
63
64   /** Remove a file from disk */
65   void unlink();
66
67   /* FIXME: add these to the S4U API:
68   XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
69   XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath);
70   XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath);
71   */
72
73 private:
74   smx_file_t pimpl_ = nullptr;
75   const char *path_ = nullptr;
76   void *userdata_ = nullptr;
77 };
78
79 }} // namespace simgrid::s4u
80
81 #endif /* SIMGRID_S4U_HOST_HPP */