* The environment is either a XML file following the simgrid.dtd formalism, or a lua file.
* Some examples can be found in the directory examples/platforms.
*/
- void load_platform(const char* platf);
+ void load_platform(std::string platf);
/** Registers the main function of an actor that will be launched from the deployment file */
- void register_function(const char* name, int (*code)(int, char**));
- // FIXME: provide a register_function(std::string, void (*code)(int, char**)) and deprecate the int returning one
+ void register_function(std::string name, int (*code)(int, char**));
// FIXME: provide a register_function(std::string, std::vector<std::string>)
/** Registers a function as the default main function of actors
*/
void register_default(int (*code)(int, char**));
- template <class F> void register_actor(const char* name)
+ template <class F> void register_actor(std::string name)
{
simgrid::simix::register_function(name, [](std::vector<std::string> args) {
return simgrid::simix::ActorCode([args] {
});
}
- template <class F> void register_actor(const char* name, F code)
+ template <class F> void register_actor(std::string name, F code)
{
simgrid::simix::register_function(name, [code](std::vector<std::string> args) {
return simgrid::simix::ActorCode([code, args] { code(std::move(args)); });
}
/** @brief Load a deployment file and launch the actors that it contains */
- void load_deployment(const char* deploy);
+ void load_deployment(std::string deploy);
protected:
friend s4u::Host;
simgrid::s4u::NetZone* get_netzone_root();
void set_netzone_root(s4u::NetZone* netzone);
- simgrid::s4u::NetZone* netzone_by_name_or_null(const char* name);
+ simgrid::s4u::NetZone* netzone_by_name_or_null(std::string name);
/** @brief Retrieves all netzones of the type indicated by the template argument */
template <class T> std::vector<T*> get_filtered_netzones()
//////////////// Deprecated functions
public:
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_platform()") void loadPlatform(const char* platf)
+ XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_platform()") void loadPlatform(std::string platf)
{
load_platform(platf);
}
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_function()") void registerFunction(const char* name,
+ XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_function()") void registerFunction(std::string name,
int (*code)(int, char**))
{
register_function(name, code);
register_default(code);
}
template <class F>
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name)
+ XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(std::string name)
{
register_actor<F>(name);
}
template <class F>
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(const char* name, F code)
+ XBT_ATTRIB_DEPRECATED_v323("Please use Engine::register_actor()") void registerFunction(std::string name, F code)
{
register_actor<F>(name, code);
}
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(const char* deploy)
+ XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_deployment()") void loadDeployment(std::string deploy)
{
load_deployment(deploy);
}
{
return get_netzone_root();
}
- XBT_ATTRIB_DEPRECATED_v323("Please use Engine::netzone_by_name_or_null()") simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name)
+ XBT_ATTRIB_DEPRECATED_v323(
+ "Please use Engine::netzone_by_name_or_null()") simgrid::s4u::NetZone* getNetzoneByNameOrNull(std::string name)
{
return netzone_by_name_or_null(name);
}
std::vector<NetZone*> get_children();
/** Retrieve the property value (or nullptr if not set) */
- const char* get_property(const char* key);
- void set_property(const char* key, const char* value);
+ const char* get_property(std::string key);
+ void set_property(std::string key, std::string value);
/* Add content to the netzone, at parsing time. It should be sealed afterward. */
int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
XBT_PUBLIC void SIMIX_display_process_status();
/******************************* Environment **********************************/
-XBT_PUBLIC void SIMIX_create_environment(const char* file);
+XBT_PUBLIC void SIMIX_create_environment(std::string file);
/******************************** Deployment **********************************/
-XBT_PUBLIC void SIMIX_function_register(const char* name, xbt_main_func_t code);
+XBT_PUBLIC void SIMIX_function_register(std::string name, xbt_main_func_t code);
XBT_PUBLIC void SIMIX_function_register_default(xbt_main_func_t code);
XBT_PUBLIC void SIMIX_init_application();
-XBT_PUBLIC void SIMIX_launch_application(const char* file);
+XBT_PUBLIC void SIMIX_launch_application(std::string file);
XBT_PUBLIC void SIMIX_process_set_function(const char* process_host, const char* process_function,
xbt_dynar_t arguments, double process_start_time, double process_kill_time);
// Create ActorCode based on argv:
typedef std::function<ActorCode(std::vector<std::string> args)> ActorCodeFactory;
-XBT_PUBLIC void register_function(const char* name, ActorCodeFactory factory);
-
+XBT_PUBLIC void register_function(std::string name, ActorCodeFactory factory);
}
}
XBT_PUBLIC void surf_exit();
/* surf parse file related (public because called from a test suite) */
-XBT_PUBLIC void parse_platform_file(const char* file);
+XBT_PUBLIC void parse_platform_file(std::string file);
#endif
#include "src/surf/network_interface.hpp"
#include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON
+#include <string>
+
XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface");
namespace simgrid {
return SIMIX_get_clock();
}
-void Engine::load_platform(const char* platf)
+void Engine::load_platform(std::string platf)
{
SIMIX_create_environment(platf);
}
-void Engine::register_function(const char* name, int (*code)(int, char**))
+void Engine::register_function(std::string name, int (*code)(int, char**))
{
SIMIX_function_register(name, code);
}
{
SIMIX_function_register_default(code);
}
-void Engine::load_deployment(const char* deploy)
+void Engine::load_deployment(std::string deploy)
{
SIMIX_launch_application(deploy);
}
pimpl->netzone_root_ = netzone->get_impl();
}
-static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name)
+static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, std::string name)
{
- if (not strcmp(current->get_cname(), name))
+ if (current->get_name() == name)
return current;
for (auto const& elem : current->get_children()) {
}
/** @brief Retrieve the NetZone of the given name (or nullptr if not found) */
-NetZone* Engine::netzone_by_name_or_null(const char* name)
+NetZone* Engine::netzone_by_name_or_null(std::string name)
{
return netzone_by_name_recursive(get_netzone_root(), name);
}
}
/** Retrieve the property value (or nullptr if not set) */
-const char* NetZone::get_property(const char* key)
+const char* NetZone::get_property(std::string key)
{
return properties_.at(key).c_str();
}
-void NetZone::set_property(const char* key, const char* value)
+void NetZone::set_property(std::string key, std::string value)
{
simgrid::simix::simcall([this, key, value] { properties_[key] = value; });
}
* \include small_deployment.xml
*
*/
-void SIMIX_launch_application(const char *file)
+void SIMIX_launch_application(std::string file)
{
XBT_ATTRIB_UNUSED int parse_status;
xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_launch_application.");
try {
parse_status = surf_parse();
surf_parse_close();
- xbt_assert(not parse_status, "Parse error at %s:%d", file, surf_parse_lineno);
+ xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno);
}
catch (xbt_ex& e) {
- XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
- file, surf_parse_lineno);
+ XBT_ERROR(
+ "Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
+ file.c_str(), surf_parse_lineno);
throw;
}
}
* \param name the reference name of the function.
* \param code the function
*/
-void SIMIX_function_register(const char *name, xbt_main_func_t code)
+void SIMIX_function_register(std::string name, xbt_main_func_t code)
{
xbt_assert(simix_global,
"SIMIX_global_init has to be called before SIMIX_function_register.");
namespace simgrid {
namespace simix {
-void register_function(const char* name, ActorCodeFactory factory)
+void register_function(std::string name, ActorCodeFactory factory)
{
simix_global->registered_functions[name] = std::move(factory);
}
* \include small_platform.xml
*
*/
-void SIMIX_create_environment(const char *file)
+void SIMIX_create_environment(std::string file)
{
double start = 0;
double end = 0;
parse_platform_file(file);
}
catch (xbt_ex& e) {
- xbt_die("Error while loading %s: %s", file, e.what());
+ xbt_die("Error while loading %s: %s", file.c_str(), e.what());
}
if(XBT_LOG_ISENABLED(simix_environment, xbt_log_priority_debug))
end = xbt_os_time();
}
/* returns whether #file_path is a absolute file path. Surprising, isn't it ? */
-static bool is_absolute_file_path(const char* file_path)
+static bool is_absolute_file_path(std::string file_path)
{
#ifdef _WIN32
WIN32_FIND_DATA wfd = {0};
- HANDLE hFile = FindFirstFile(file_path, &wfd);
+ HANDLE hFile = FindFirstFile(file_path.c_str(), &wfd);
if (INVALID_HANDLE_VALUE == hFile)
return false;
FindClose(hFile);
return true;
#else
- return (file_path[0] == '/');
+ return (file_path.c_str()[0] == '/');
#endif
}
return fs;
}
-FILE *surf_fopen(const char *name, const char *mode)
+FILE* surf_fopen(std::string name, const char* mode)
{
FILE *file = nullptr;
- xbt_assert(name);
-
if (is_absolute_file_path(name)) /* don't mess with absolute file names */
- return fopen(name, mode);
+ return fopen(name.c_str(), mode);
/* search relative files in the path */
for (auto const& path_elm : surf_path) {
/* Generic functions common to all models */
-XBT_PRIVATE FILE* surf_fopen(const char* name, const char* mode);
+XBT_PRIVATE FILE* surf_fopen(std::string name, const char* mode);
XBT_PRIVATE std::ifstream* surf_ifsopen(std::string name);
XBT_PRIVATE void check_disk_attachment();
XBT_PUBLIC void sg_platf_init();
XBT_PUBLIC void sg_platf_exit();
-XBT_PUBLIC void surf_parse_open(const char* file);
+XBT_PUBLIC void surf_parse_open(std::string file);
XBT_PUBLIC void surf_parse_close();
XBT_PUBLIC void surf_parse_assert(bool cond, std::string msg);
XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(std::string msg);
}
/* This function acts as a main in the parsing area. */
-void parse_platform_file(const char *file)
+void parse_platform_file(std::string file)
{
#if SIMGRID_HAVE_LUA
- int len = (file == nullptr ? 0 : strlen(file));
- int is_lua = (file != nullptr && len > 3 && file[len - 3] == 'l' && file[len - 2] == 'u' && file[len - 1] == 'a');
+ const char* cfile = file.c_str();
+ int len = strlen(cfile);
+ int is_lua = len > 3 && file[len - 3] == 'l' && file[len - 2] == 'u' && file[len - 1] == 'a';
#endif
sg_platf_init();
lua_State* L = luaL_newstate();
luaL_openlibs(L);
- luaL_loadfile(L, file); // This loads the file without executing it.
+ luaL_loadfile(L, cfile); // This loads the file without executing it.
/* Run the script */
if (lua_pcall(L, 0, 0, 0)) {
#include "simgrid_dtd.c"
-static const char* surf_parsed_filename; // Currently parsed file (for the error messages)
+static std::string surf_parsed_filename; // Currently parsed file (for the error messages)
std::vector<simgrid::kernel::resource::LinkImpl*>
parsed_link_list; /* temporary store of current list link of a route */
if (not cond) {
int lineno = surf_parse_lineno;
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename.c_str(), lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
{
int lineno = surf_parse_lineno;
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename.c_str(), lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
"Use simgrid_update_xml to update your file automatically. "
"This program is installed automatically with SimGrid, or "
"available in the tools/ directory of the source archive.",
- surf_parsed_filename, version);
+ surf_parsed_filename.c_str(), version);
if (version < 4.1) {
XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
"That's fine, the new version is backward compatible. \n\n"
"Use simgrid_update_xml to update your file automatically to get rid of this warning. "
"This program is installed automatically with SimGrid, or "
"available in the tools/ directory of the source archive.",
- version, surf_parsed_filename);
+ version, surf_parsed_filename.c_str());
}
- xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
- "The most recent formalism that this version of SimGrid understands is v4.1.\n"
- "Please update your code, or use another, more adapted, file.",
- surf_parsed_filename, version);
+ xbt_assert(version <= 4.1,
+ "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
+ "The most recent formalism that this version of SimGrid understands is v4.1.\n"
+ "Please update your code, or use another, more adapted, file.",
+ surf_parsed_filename.c_str(), version);
}
void ETag_surfxml_platform(){
simgrid::s4u::on_platform_created();
XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(A_surfxml_zone_id);
- netzone->set_property(A_surfxml_prop_id, A_surfxml_prop_value);
+ netzone->set_property(std::string(A_surfxml_prop_id), A_surfxml_prop_value);
} else {
if (not current_property_set)
current_property_set = new std::unordered_map<std::string, std::string>; // Maybe, it should raise an error
/* Open and Close parse file */
YY_BUFFER_STATE surf_input_buffer;
-void surf_parse_open(const char *file)
+void surf_parse_open(std::string file)
{
- xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
-
surf_parsed_filename = file;
std::string dir = simgrid::xbt::Path(file).get_dir_name();
surf_path.push_back(dir);
surf_file_to_parse = surf_fopen(file, "r");
if (surf_file_to_parse == nullptr)
- xbt_die("Unable to open '%s'\n", file);
+ xbt_die("Unable to open '%s'\n", file.c_str());
surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
surf_parse__switch_to_buffer(surf_input_buffer);
surf_parse_lineno = 1;