Logo AND Algorithmique Numérique Distribuée

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