Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make smx_file_t, surf_file_t and msg_file_t
[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 /** @addtogroup msg_easier_life
18  *    \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Platforms and Applications" --> \endhtmlonly
19  * 
20  */
21
22 /********************************* MSG **************************************/
23
24 /** \ingroup msg_easier_life
25  * \brief A name directory service...
26  *
27  * Finds a m_host_t using its name.
28  * \param name the name of an host.
29  * \return the corresponding host
30  */
31 m_host_t MSG_get_host_by_name(const char *name)
32 {
33   smx_host_t simix_h = NULL;
34   simix_h = simcall_host_get_by_name(name);
35
36   if (simix_h == NULL)
37     return NULL;
38
39   return (m_host_t) simcall_host_get_data(simix_h);
40 }
41
42 /** \ingroup msg_easier_life
43  * \brief A platform constructor.
44  *
45  * Creates a new platform, including hosts, links and the
46  * routing_table. 
47  * \param file a filename of a xml description of a platform. This file 
48  * follows this DTD :
49  *
50  *     \include simgrid.dtd
51  *
52  * Here is a small example of such a platform 
53  *
54  *     \include small_platform.xml
55  *
56  * Have a look in the directory examples/msg/ to have a big example.
57  */
58 void MSG_create_environment(const char *file)
59 {
60   xbt_lib_cursor_t cursor;
61   void **data;
62   char *name;
63
64   SIMIX_create_environment(file);
65
66   /* Initialize MSG hosts */
67   xbt_lib_foreach(host_lib, cursor, name, data) {
68     if(data[SIMIX_HOST_LEVEL])
69       __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL], NULL);
70   }
71 }
72
73 /**
74  * @ingroup MSG_LUA
75  * \brief A platform constructor bypassing the parser.
76  *
77  * load lua script file to set up new platform, including hosts,links
78  * and the routing table
79  */
80
81 void MSG_load_platform_script(const char *script_file)
82 {
83 #ifdef HAVE_LUA
84   lua_State *L = lua_open();
85   luaL_openlibs(L);
86
87   if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) {
88     printf("error: %s\n", lua_tostring(L, -1));
89     return;
90   }
91 #else
92   xbt_die
93       ("Lua is not available! It is mandatory to use MSG_load_platform_script however. Bailing out...");
94 #endif
95 }