Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
07b63df115691516643c3b23b1f8b13ebc58d531
[simgrid.git] / src / surf / callbacks.cpp
1 /* Copyright (c) 2015. 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 <xbt/asserts.h>
8
9 #include "src/surf/callbacks.h"
10 #include "src/surf/surf_interface.hpp"
11 #include "src/surf/host_interface.hpp"
12
13 void surf_on_host_created(void (*callback)(sg_host_t))
14 {
15   simgrid::surf::Host::onCreation.connect([callback](simgrid::surf::Host* host) {
16     const char* id = host->getName();
17     sg_host_t h = sg_host_by_name(id);
18     xbt_assert(h != NULL, "Host not found for name %s", id);
19     callback(h);
20   });
21 }
22
23 void surf_on_storage_created(void (*callback)(sg_storage_t))
24 {
25   simgrid::surf::storageCreatedCallbacks.connect([callback](simgrid::surf::Storage* storage) {
26     const char* id = storage->getName();
27     // TODO, create sg_storage_by_name
28     sg_storage_t s = xbt_lib_get_elm_or_null(storage_lib, id);
29     xbt_assert(s != NULL, "Storage not found for name %s", id);
30     callback(s);
31   });
32 }