Logo AND Algorithmique Numérique Distribuée

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