Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #184 from Takishipp/signals
[simgrid.git] / src / msg / msg_environment.cpp
1 /* Copyright (c) 2004-2017. 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 #include "simgrid/s4u/Engine.hpp"
7 #include "simgrid/s4u/NetZone.hpp"
8 #include "src/msg/msg_private.h"
9
10 #if SIMGRID_HAVE_LUA
11 #include <lua.h>
12 #include <lauxlib.h>
13 #include <lualib.h>
14 #endif
15
16 SG_BEGIN_DECL()
17
18 /********************************* MSG **************************************/
19
20 /** \ingroup msg_simulation
21  * \brief A platform constructor.
22  *
23  * Creates a new platform, including hosts, links and the routing_table.
24  * \param file a filename of a xml description of a platform. This file follows this DTD :
25  *
26  *     \include simgrid.dtd
27  *
28  * Here is a small example of such a platform 
29  *
30  *     \include small_platform.xml
31  *
32  * Have a look in the directory examples/msg/ to have a big example.
33  */
34 void MSG_create_environment(const char *file)
35 {
36   SIMIX_create_environment(file);
37 }
38
39 void MSG_post_create_environment() {
40   xbt_lib_cursor_t cursor;
41   void **data;
42   char *name;
43
44   /* Initialize MSG storages */
45   xbt_lib_foreach(storage_lib, cursor, name, data) {
46     __MSG_storage_create(xbt_dict_cursor_get_elm(cursor));
47   }
48 }
49
50 msg_netzone_t MSG_zone_get_root()
51 {
52   return simgrid::s4u::Engine::instance()->netRoot();
53 }
54
55 const char* MSG_zone_get_name(msg_netzone_t netzone)
56 {
57   return netzone->name();
58 }
59
60 msg_netzone_t MSG_zone_get_by_name(const char* name)
61 {
62   return simgrid::s4u::Engine::instance()->netzoneByNameOrNull(name);
63 }
64
65 void MSG_zone_get_sons(msg_netzone_t netzone, xbt_dict_t whereto)
66 {
67   for (auto elem : *netzone->children()) {
68     xbt_dict_set(whereto, elem->name(), static_cast<void*>(elem), nullptr);
69   }
70 }
71
72 const char* MSG_zone_get_property_value(msg_netzone_t netzone, const char* name)
73 {
74   return netzone->property(name);
75 }
76
77 void MSG_zone_set_property_value(msg_netzone_t netzone, const char* name, char* value)
78 {
79   netzone->setProperty(name, value);
80 }
81
82 void MSG_zone_get_hosts(msg_netzone_t netzone, xbt_dynar_t whereto)
83 {
84   /* converts vector to dynar */
85   std::vector<simgrid::s4u::Host*> hosts;
86   netzone->hosts(&hosts);
87   for (auto host : hosts)
88     xbt_dynar_push(whereto, &host);
89 }
90
91 SG_END_DECL()