Logo AND Algorithmique Numérique Distribuée

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