From bded17ddf45f0643fd7f137d0acecdee853ea7d1 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 11 Nov 2019 10:59:47 +0100 Subject: [PATCH] deprecate a couple of SIMIX functions --- include/simgrid/simix.h | 14 ++++--- src/bindings/java/jmsg.cpp | 2 +- src/kernel/EngineImpl.cpp | 44 ++++++++++++++++++++ src/kernel/EngineImpl.hpp | 10 ++++- src/s4u/s4u_Engine.cpp | 11 +++-- src/simix/smx_deployment.cpp | 79 +++++------------------------------- 6 files changed, 79 insertions(+), 81 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index dc02ba4638..0b4c7152e0 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -91,17 +91,21 @@ SG_END_DECL /******************************** Deployment **********************************/ SG_BEGIN_DECL -XBT_PUBLIC void SIMIX_function_register_default(xbt_main_func_t code); +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_default() or Engine::register_default()") XBT_PUBLIC + void SIMIX_function_register_default(xbt_main_func_t code); +XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC void SIMIX_init_application(); -XBT_PUBLIC void SIMIX_init_application(); 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); SG_END_DECL #ifdef __cplusplus -XBT_PUBLIC void SIMIX_function_register(const std::string& name, void (*code)(std::vector)); -XBT_PUBLIC void SIMIX_function_register(const std::string& name, xbt_main_func_t code); -XBT_PUBLIC void SIMIX_launch_application(const std::string& file); +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC + void SIMIX_function_register(const std::string& name, void (*code)(std::vector)); +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC + void SIMIX_function_register(const std::string& name, xbt_main_func_t code); +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_load_deployment() or Engine::load_deployment()") XBT_PUBLIC + void SIMIX_launch_application(const std::string& file); #endif /********************************* Process ************************************/ diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index ebe959756d..66231b3972 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -238,7 +238,7 @@ Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, jstring jde { const char *deploymentFile = env->GetStringUTFChars(jdeploymentFile, 0); - SIMIX_function_register_default(java_main); + simgrid_register_default(java_main); MSG_launch_application(deploymentFile); } diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 4d98ab4ed8..9a44225168 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -4,12 +4,17 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/EngineImpl.hpp" +#include "simgrid/Exception.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/kernel/routing/NetZoneImpl.hpp" #include "simgrid/s4u/Host.hpp" #include "src/kernel/resource/DiskImpl.hpp" +#include "src/simix/smx_private.hpp" #include "src/surf/StorageImpl.hpp" #include "src/surf/network_interface.hpp" +#include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here + +extern int surf_parse_lineno; namespace simgrid { namespace kernel { @@ -35,5 +40,44 @@ EngineImpl::~EngineImpl() if (kv.second) kv.second->get_impl()->destroy(); } + +void EngineImpl::load_deployment(const std::string& file) +{ + sg_platf_exit(); + sg_platf_init(); + + surf_parse_open(file); + try { + int parse_status = surf_parse(); + surf_parse_close(); + xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno); + } catch (const Exception&) { + xbt_die( + "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; + } +} +void EngineImpl::register_function(const std::string& name, xbt_main_func_t code) +{ + simix_global->registered_functions[name] = [code](std::vector args) { + return simgrid::xbt::wrap_main(code, std::move(args)); + }; +} + +void EngineImpl::register_function(const std::string& name, void (*code)(std::vector)) +{ + simix_global->registered_functions[name] = [code](std::vector args) { + return std::bind(std::move(code), std::move(args)); + }; } + +void EngineImpl::register_default(xbt_main_func_t code) +{ + simix_global->default_function = [code](std::vector args) { + return simgrid::xbt::wrap_main(code, std::move(args)); + }; } + +} // namespace kernel +} // namespace simgrid diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index f82414901d..cdef002e8b 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -3,9 +3,9 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include - #include +#include +#include #include #include @@ -25,6 +25,12 @@ public: EngineImpl(const EngineImpl&) = delete; EngineImpl& operator=(const EngineImpl&) = delete; virtual ~EngineImpl(); + + void load_deployment(const std::string& file); + void register_function(const std::string& name, xbt_main_func_t code); + void register_function(const std::string& name, void (*code)(std::vector)); + void register_default(xbt_main_func_t code); + routing::NetZoneImpl* netzone_root_ = nullptr; }; diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index ba96fac442..de8004ee71 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -96,12 +96,13 @@ void Engine::load_platform(const std::string& platf) /** Registers the main function of an actor that will be launched from the deployment file */ void Engine::register_function(const std::string& name, int (*code)(int, char**)) { - SIMIX_function_register(name, code); + pimpl->register_function(name, code); } + /** Registers the main function of an actor that will be launched from the deployment file */ void Engine::register_function(const std::string& name, void (*code)(std::vector)) { - SIMIX_function_register(name, code); + pimpl->register_function(name, code); } /** Registers a function as the default main function of actors * @@ -110,8 +111,9 @@ void Engine::register_function(const std::string& name, void (*code)(std::vector */ void Engine::register_default(int (*code)(int, char**)) { - SIMIX_function_register_default(code); + pimpl->register_default(code); } + /** Load a deployment file and launch the actors that it contains * * \rst @@ -120,8 +122,9 @@ void Engine::register_default(int (*code)(int, char**)) */ void Engine::load_deployment(const std::string& deploy) { - SIMIX_launch_application(deploy); + pimpl->load_deployment(deploy); } + /** Returns the amount of hosts in the platform */ size_t Engine::get_host_count() { diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 422f0a86d4..f32f5fff20 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -3,97 +3,38 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/Exception.hpp" #include "simgrid/s4u/Host.hpp" #include "smx_private.hpp" #include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here #include +#include #include #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, "Logging specific to SIMIX (deployment)"); -extern int surf_parse_lineno; - -void SIMIX_init_application() +void SIMIX_init_application() // XBT_DEPRECATED_v329 { sg_platf_exit(); sg_platf_init(); } -/** - * @brief An application deployer. - * - * Creates the process described in @a file. - * @param file a filename of a xml description of the application. This file - * follows this DTD : - * - * @include surfxml.dtd - * - * Here is a small example of such a platform - * - * @include small_deployment.xml - * - */ -void SIMIX_launch_application(const std::string& file) -{ - XBT_ATTRIB_UNUSED int parse_status; - xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_launch_application."); - - SIMIX_init_application(); - - surf_parse_open(file); - try { - parse_status = surf_parse(); - surf_parse_close(); - xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno); - } catch (const simgrid::Exception&) { - 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; - } -} - -// Wrap a main() function into a ActorCodeFactory: -static simgrid::simix::ActorCodeFactory toActorCodeFactory(xbt_main_func_t code) +void SIMIX_launch_application(const std::string& file) // XBT_DEPRECATED_v329 { - return [code](std::vector args) { return simgrid::xbt::wrap_main(code, std::move(args)); }; + simgrid_load_deployment(file.c_str()); } -static simgrid::simix::ActorCodeFactory toActorCodeFactory(void (*code)(std::vector)) +void SIMIX_function_register(const std::string& name, xbt_main_func_t code) // XBT_DEPRECATED_v329 { - return [code](std::vector args) { return std::bind(std::move(code), std::move(args)); }; + simgrid::s4u::Engine::get_instance()->register_function(name, code); } - -/** - * @brief Registers a #xbt_main_func_t code in a global table. - * - * Registers a code function in a global table. - * This table is then used by #SIMIX_launch_application. - * @param name the reference name of the function. - * @param code the function - */ -void SIMIX_function_register(const std::string& name, xbt_main_func_t code) +void SIMIX_function_register(const std::string& name, void (*code)(std::vector)) // XBT_DEPRECATED_v329 { - simix_global->registered_functions[name] = toActorCodeFactory(code); + simgrid::s4u::Engine::get_instance()->register_function(name, code); } -void SIMIX_function_register(const std::string& name, void (*code)(std::vector)) -{ - simix_global->registered_functions[name] = toActorCodeFactory(code); -} - -/** - * @brief Registers a #xbt_main_func_t code as default value. - * - * Registers a code function as being the default value. This function will get used by SIMIX_launch_application() when - * there is no registered function of the requested name in. - * @param code the function - */ -void SIMIX_function_register_default(xbt_main_func_t code) +void SIMIX_function_register_default(xbt_main_func_t code) // XBT_DEPRECATED_v329 { - xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_function_register."); - simix_global->default_function = toActorCodeFactory(code); + simgrid::s4u::Engine::get_instance()->register_default(code); } /** -- 2.20.1