Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tend to the google coding standards in all S4U API
[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(const char* fullpath, void* userdata);
29   File(const char* fullpath, sg_host_t host, void* userdata);
30   ~File();
31
32   /** Retrieves the path to the file */
33   const char* getPath() { return path_; }
34
35   /** Simulates a read action. Returns the size of data actually read
36    *
37    *  FIXME: reading from a remotely mounted disk is not implemented yet.
38    *  Any storage is considered as local, and no network communication ever occur.
39    */
40   sg_size_t read(sg_size_t size);
41
42   /** Simulates a write action. Returns the size of data actually written. */
43   sg_size_t write(sg_size_t size);
44   sg_size_t write(sg_size_t size, sg_host_t host);
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* getUserdata() { 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_offset_t pos);
56   void seek(sg_offset_t pos, int origin);
57
58   /** Retrieves the current file position */
59   sg_size_t tell();
60
61   /** Rename a file
62    *
63    * WARNING: It is forbidden to move the file to another mount point */
64   void move(const char* fullpath);
65
66   /** Remove a file from disk */
67   int unlink();
68   int unlink(sg_host_t host);
69
70   /* FIXME: add these to the S4U API:
71   XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
72   XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath);
73   XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath);
74   */
75   const char* storage_type;
76   const char* storageId;
77   std::string mount_point;
78   int desc_id = 0;
79
80 private:
81   surf_file_t pimpl_ = nullptr;
82   const char* path_  = nullptr;
83   void* userdata_    = nullptr;
84   sg_host_t host_    = nullptr;
85 };
86 }
87 } // namespace simgrid::s4u
88
89 #endif /* SIMGRID_S4U_HOST_HPP */