Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add function MSG_load_platform_script that load the console lua script to set up...
[simgrid.git] / src / 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 #include "lua.h"
12 #include "lauxlib.h"
13 #include "lualib.h"
14
15 /** \defgroup msg_easier_life      Platform and Application management
16  *  \brief This section describes functions to manage the platform creation
17  *  and the application deployment. You should also have a look at 
18  *  \ref MSG_examples  to have an overview of their usage.
19  */
20 /** @addtogroup msg_easier_life
21  *    \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Platforms and Applications" --> \endhtmlonly
22  * 
23  */
24
25 /********************************* MSG **************************************/
26
27 /** \ingroup msg_easier_life
28  * \brief A name directory service...
29  *
30  * Finds a m_host_t using its name.
31  * \param name the name of an host.
32  * \return the corresponding host
33  */
34 m_host_t MSG_get_host_by_name(const char *name)
35 {
36   smx_host_t simix_h = NULL;
37   simix_h = SIMIX_host_get_by_name(name);
38   
39   if (simix_h == NULL)
40     return NULL;
41
42   return (m_host_t)SIMIX_host_get_data(simix_h);
43 }
44
45 /** \ingroup msg_easier_life
46  * \brief A platform constructor.
47  *
48  * Creates a new platform, including hosts, links and the
49  * routing_table. 
50  * \param file a filename of a xml description of a platform. This file 
51  * follows this DTD :
52  *
53  *     \include simgrid.dtd
54  *
55  * Here is a small example of such a platform 
56  *
57  *     \include small_platform.xml
58  *
59  * Have a look in the directory examples/msg/ to have a big example.
60  */
61 void MSG_create_environment(const char *file)
62 {
63   xbt_dict_cursor_t c;
64   smx_host_t h;
65   char *name;
66
67   SIMIX_create_environment(file);
68   SIMIX_init();
69
70   /* Initialize MSG hosts */
71   xbt_dict_foreach(SIMIX_host_get_dict(), c, name, h) {
72     __MSG_host_create(h, NULL);
73   }
74   return;
75 }
76
77 /**
78  * \brief A platform constructor bypassing the parser.
79  *
80  * load lua script file to set up new platform, including hosts,links
81  * and the routing table
82  */
83
84 void MSG_load_platform_script(const char *script_file) {
85
86     lua_State *L = lua_open();
87     luaL_openlibs(L);
88
89     if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) {
90          printf("error: %s\n", lua_tostring(L, -1));
91          return;
92        }
93
94     return;
95 }