Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : new comparison of region (program data and libsimgrid data)
[simgrid.git] / src / msg / msg_environment.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. 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 "msg_private.h"
8 #include "xbt/sysdep.h"
9 #include "xbt/log.h"
10 #include "xbt/dict.h"
11 #ifdef HAVE_LUA
12 #include <lua.h>
13 #include <lauxlib.h>
14 #include <lualib.h>
15 #endif
16
17 /********************************* MSG **************************************/
18
19 /** \ingroup msg_simulation
20  * \brief A platform constructor.
21  *
22  * Creates a new platform, including hosts, links and the
23  * routing_table. 
24  * \param file a filename of a xml description of a platform. This file 
25  * follows this DTD :
26  *
27  *     \include simgrid.dtd
28  *
29  * Here is a small example of such a platform 
30  *
31  *     \include small_platform.xml
32  *
33  * Have a look in the directory examples/msg/ to have a big example.
34  */
35 void MSG_create_environment(const char *file)
36 {
37   xbt_lib_cursor_t cursor;
38   void **data;
39   char *name;
40
41   SIMIX_create_environment(file);
42
43   /* Initialize MSG hosts */
44   xbt_lib_foreach(host_lib, cursor, name, data) {
45     if(data[SIMIX_HOST_LEVEL])
46       __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL], NULL);
47   }
48 }
49
50 /**
51  * @ingroup MSG_LUA
52  * \brief A platform constructor bypassing the parser.
53  *
54  * load lua script file to set up new platform, including hosts,links
55  * and the routing table
56  */
57
58 void MSG_load_platform_script(const char *script_file)
59 {
60 #ifdef HAVE_LUA
61   lua_State *L = lua_open();
62   luaL_openlibs(L);
63
64   if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) {
65     printf("error: %s\n", lua_tostring(L, -1));
66     return;
67   }
68 #else
69   xbt_die
70       ("Lua is not available! It is mandatory to use MSG_load_platform_script however. Bailing out...");
71 #endif
72 }