Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: inline a header file
[simgrid.git] / src / surf / StorageImpl.cpp
1 /* Copyright (c) 2013-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "StorageImpl.hpp"
8 #include "src/kernel/lmm/maxmin.hpp"
9 #include "surf_private.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
12
13 simgrid::surf::StorageModel* surf_storage_model = nullptr;
14
15 namespace simgrid {
16 namespace surf {
17
18 /*************
19  * Callbacks *
20  *************/
21
22 simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
23 simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
24 simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
25 simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storageActionStateChangedCallbacks;
26
27 /* List of storages */
28 std::unordered_map<std::string, StorageImpl*>* StorageImpl::storages =
29     new std::unordered_map<std::string, StorageImpl*>();
30
31 StorageImpl* StorageImpl::byName(std::string name)
32 {
33   if (storages->find(name) == storages->end())
34     return nullptr;
35   return storages->at(name);
36 }
37
38 /*********
39  * Model *
40  *********/
41
42 StorageModel::StorageModel() : Model()
43 {
44   maxminSystem_ = new simgrid::kernel::lmm::System(true /* lazy update */);
45 }
46
47 StorageModel::~StorageModel()
48 {
49   surf_storage_model = nullptr;
50 }
51
52 /************
53  * Resource *
54  ************/
55
56 StorageImpl::StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
57                          std::string type_id, std::string content_name, sg_size_t size, std::string attach)
58     : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
59     , piface_(this)
60     , typeId_(type_id)
61     , content_name(content_name)
62     , size_(size)
63     , attach_(attach)
64 {
65   StorageImpl::turnOn();
66   XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
67   constraintRead_  = maxminSystem->constraint_new(this, bread);
68   constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
69   storages->insert({name, this});
70 }
71
72 StorageImpl::~StorageImpl()
73 {
74   storageDestructedCallbacks(this);
75 }
76
77
78 bool StorageImpl::isUsed()
79 {
80   THROW_UNIMPLEMENTED;
81   return false;
82 }
83
84 void StorageImpl::apply_event(tmgr_trace_event_t /*event*/, double /*value*/)
85 {
86   THROW_UNIMPLEMENTED;
87 }
88
89 void StorageImpl::turnOn()
90 {
91   if (isOff()) {
92     Resource::turnOn();
93     storageStateChangedCallbacks(this, 0, 1);
94   }
95 }
96 void StorageImpl::turnOff()
97 {
98   if (isOn()) {
99     Resource::turnOff();
100     storageStateChangedCallbacks(this, 1, 0);
101   }
102 }
103
104 /**********
105  * Action *
106  **********/
107 void StorageAction::setState(Action::State state)
108 {
109   Action::State old = getState();
110   Action::setState(state);
111   storageActionStateChangedCallbacks(this, old, state);
112 }
113 }
114 }