Logo AND Algorithmique Numérique Distribuée

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