surf::StorageImpl* getImpl() { return pimpl_; }
/* The signals */
- /** @brief Callback signal fired when a new Link is created */
- static simgrid::xbt::signal<void(s4u::Storage&)> onCreation;
-
- /** @brief Callback signal fired when a Link is destroyed */
- static simgrid::xbt::signal<void(s4u::Storage&)> onDestruction;
+ /** @brief Callback signal fired when a new Storage is created */
+ static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
+ /** @brief Callback signal fired when a Storage is destroyed */
+ static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
+ /** @brief Callback signal fired when a Storage's state changes */
+ static simgrid::xbt::signal<void(s4u::Storage&)> on_state_change;
Host* attached_to_ = nullptr;
for (auto const& kv : storages_)
if (kv.second)
- delete kv.second->getImpl();
+ kv.second->getImpl()->destroy();
}
}
}
st.extension_set(new FileSystemStorageExt(&st));
}
-static void on_storage_destruction(simgrid::s4u::Storage& st)
-{
- delete st.extension<FileSystemStorageExt>();
-}
-
static void on_host_creation(simgrid::s4u::Host& host)
{
host.extension_set<FileDescriptorHostExt>(new FileDescriptorHostExt());
if (not FileSystemStorageExt::EXTENSION_ID.valid()) {
FileSystemStorageExt::EXTENSION_ID = simgrid::s4u::Storage::extension_create<FileSystemStorageExt>();
- simgrid::s4u::Storage::onCreation.connect(&on_storage_creation);
- simgrid::s4u::Storage::onDestruction.connect(&on_storage_destruction);
+ simgrid::s4u::Storage::on_creation.connect(&on_storage_creation);
}
if (not FileDescriptorHostExt::EXTENSION_ID.valid()) {
/*************
* Callbacks *
*************/
-simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
-simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::on_creation;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::on_destruction;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::on_state_change;
} /* namespace s4u */
} /* namespace simgrid */
host.extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
});
- simgrid::surf::storageCreatedCallbacks.connect([](simgrid::surf::StorageImpl* storage) {
- sg_storage_t s = simgrid::s4u::Storage::byName(storage->get_cname());
- xbt_assert(s != nullptr, "Storage not found for name %s", storage->get_cname());
+ simgrid::s4u::Storage::on_creation.connect([](simgrid::s4u::Storage& storage) {
+ sg_storage_t s = simgrid::s4u::Storage::byName(storage.get_cname());
+ xbt_assert(s != nullptr, "Storage not found for name %s", storage.get_cname());
});
}
namespace simgrid {
namespace surf {
-/*************
- * Callbacks *
- *************/
-
-simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
-simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
-simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
-simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
- storageActionStateChangedCallbacks;
-
/*********
* Model *
*********/
StorageImpl::~StorageImpl()
{
- storageDestructedCallbacks(this);
+ xbt_assert(currentlyDestroying_, "Don't delete Storages directly. Call destroy() instead.");
+}
+
+/** @brief Fire the required callbacks and destroy the object
+ *
+ * Don't delete directly a Storage, call s->destroy() instead.
+ */
+void StorageImpl::destroy()
+{
+ if (not currentlyDestroying_) {
+ currentlyDestroying_ = true;
+ s4u::Storage::on_destruction(this->piface_);
+ delete this;
+ }
}
bool StorageImpl::is_used()
{
if (is_off()) {
Resource::turn_on();
- storageStateChangedCallbacks(this, 0, 1);
+ s4u::Storage::on_state_change(this->piface_);
}
}
void StorageImpl::turn_off()
{
if (is_on()) {
Resource::turn_off();
- storageStateChangedCallbacks(this, 1, 0);
+ s4u::Storage::on_state_change(this->piface_);
}
}
+xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
+ StorageAction::on_state_change;
/**********
* Action *
{
Action::State old = get_state();
Action::set_state(state);
- storageActionStateChangedCallbacks(this, old, state);
+ on_state_change(this, old, state);
}
}
}
* Callbacks *
*************/
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emit the callbacks after Storage creation *
- * @details Callback functions have the following signature: `void(Storage*)`
- */
-XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emit the callbacks after Storage destruction *
- * @details Callback functions have the following signature: `void(StoragePtr)`
- */
-XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emit the callbacks after Storage State changed *
- * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
- * currentlyOn)`
- */
-XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks;
-
/** @ingroup SURF_callbacks
* @brief Callbacks handler which emit the callbacks after StorageAction State changed *
* @details Callback functions have the following signature: `void(StorageAction *action,
*/
XBT_PUBLIC_DATA
simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
- storageActionStateChangedCallbacks;
+ on_state_change;
/*********
* Model *
void turn_on() override;
void turn_off() override;
+ void destroy(); // Must be called instead of the destructor
+
/**
* @brief Read a file
*
sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
private:
+ bool currentlyDestroying_ = false;
// Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
// the Host directly.
std::string attach_;
*/
class StorageAction : public kernel::resource::Action {
public:
+ static xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
+ on_state_change;
+
/**
* @brief StorageAction constructor
*
StorageImpl* storage =
new StorageN11(this, id, get_maxmin_system(), Bread, Bwrite, type_id, content_name, storage_type->size, attach);
- storageCreatedCallbacks(storage);
XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tBread '%f'\n", id.c_str(), type_id.c_str(),
Bread);
: StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach)
{
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
- simgrid::s4u::Storage::onCreation(this->piface_);
+ simgrid::s4u::Storage::on_creation(this->piface_);
}
StorageAction* StorageN11::read(sg_size_t size)