Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
snake_case (and document) s4u::Exec
[simgrid.git] / include / simgrid / s4u / Storage.hpp
1 /* Copyright (c) 2006-2018. 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 INCLUDE_SIMGRID_S4U_STORAGE_HPP_
7 #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
8
9 #include <simgrid/forward.h>
10 #include <xbt/Extendable.hpp>
11 #include <xbt/base.h>
12
13 #include <map>
14 #include <string>
15 #include <unordered_map>
16
17 namespace simgrid {
18 namespace xbt {
19 extern template class XBT_PUBLIC Extendable<simgrid::s4u::Storage>;
20 }
21 namespace s4u {
22
23 XBT_ATTRIB_DEPRECATED_v322(
24     "simgrid::s4u::getStorageList() is deprecated in favor of Engine::getAllStorages(). Please switch before v3.22")
25     XBT_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
26
27 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
28   friend s4u::Engine;
29   friend simgrid::surf::StorageImpl;
30
31 public:
32   explicit Storage(std::string name, surf::StorageImpl * pimpl);
33   virtual ~Storage() = default;
34   /** Retrieve a Storage by its name. It must exist in the platform file */
35   static Storage* byName(std::string name);
36
37   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); }
38   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); }
39
40   /** @brief Retrieves the name of that storage as a C++ string */
41   std::string const& get_name() const;
42   /** @brief Retrieves the name of that storage as a C string */
43   const char* get_cname() const;
44
45   const char* getType();
46   Host* getHost();
47
48   std::map<std::string, std::string>* getProperties();
49   const char* getProperty(std::string key);
50   void setProperty(std::string, std::string value);
51
52   void setUserdata(void* data) { userdata_ = data; }
53   void* getUserdata() { return userdata_; }
54
55   sg_size_t read(sg_size_t size);
56   sg_size_t write(sg_size_t size);
57   surf::StorageImpl* getImpl() { return pimpl_; }
58
59   /* The signals */
60   /** @brief Callback signal fired when a new Link is created */
61   static simgrid::xbt::signal<void(s4u::Storage&)> onCreation;
62
63   /** @brief Callback signal fired when a Link is destroyed */
64   static simgrid::xbt::signal<void(s4u::Storage&)> onDestruction;
65
66   Host* attached_to_              = nullptr;
67
68 private:
69   surf::StorageImpl* const pimpl_ = nullptr;
70   std::string name_;
71   void* userdata_ = nullptr;
72 };
73
74 } /* namespace s4u */
75 } /* namespace simgrid */
76
77 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */