From 4be8e24c6d490dfbca2fe7e62da90202065d9d03 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 14 Jan 2016 16:43:46 +0100 Subject: [PATCH] Remove sg_platf_*_add_cb, use the signal directly --- doc/doxygen/inside_extending.doc | 2 +- src/include/simgrid/platf_interface.h | 9 ------- src/msg/msg_global.cpp | 3 ++- src/simix/smx_global.cpp | 3 ++- src/surf/cpu_cas01.cpp | 3 ++- src/surf/cpu_ti.cpp | 3 ++- src/surf/host_ptask_L07.cpp | 5 ++-- src/surf/instr_routing.cpp | 5 ++-- src/surf/network_cm02.cpp | 5 ++-- src/surf/network_constant.cpp | 3 ++- src/surf/network_ns3.cpp | 9 ++++--- src/surf/platform.hpp | 24 ++++++++++++++++++ src/surf/sg_platf.cpp | 36 +++++++++++++-------------- src/surf/surf_routing.cpp | 6 ++--- tools/cmake/DefinePackages.cmake | 1 + 15 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 src/surf/platform.hpp diff --git a/doc/doxygen/inside_extending.doc b/doc/doxygen/inside_extending.doc index d232f9ff94..e16c1e6ba8 100644 --- a/doc/doxygen/inside_extending.doc +++ b/doc/doxygen/inside_extending.doc @@ -44,7 +44,7 @@ void surf_cpu_model_init_plop() surf_cpu_model_pm = new CpuPlopModel(); - sg_platf_postparse_add_cb(cpu_add_traces); + simgrid::surf::on_postparse.connect(cpu_add_traces); xbt_dynar_push(model_list, &surf_cpu_model_pm); } diff --git a/src/include/simgrid/platf_interface.h b/src/include/simgrid/platf_interface.h index 39c771c87d..00a5fd63f5 100644 --- a/src/include/simgrid/platf_interface.h +++ b/src/include/simgrid/platf_interface.h @@ -22,15 +22,6 @@ SG_BEGIN_DECL() XBT_PUBLIC(void) sg_platf_init(void); XBT_PUBLIC(void) sg_platf_exit(void); -/* Managing the parsing callbacks */ - -typedef void (*sg_platf_link_cb_t)(sg_platf_link_cbarg_t); -typedef void (*sg_platf_cluster_cb_t)(sg_platf_cluster_cbarg_t); - -XBT_PUBLIC(void) sg_platf_link_add_cb(sg_platf_link_cb_t); -XBT_PUBLIC(void) sg_platf_cluster_add_cb(sg_platf_cluster_cb_t fct); -XBT_PUBLIC(void) sg_platf_postparse_add_cb(void_f_void_t fct); - /** \brief Pick the right models for CPU, net and host, and call their model_init_preparse * * Must be called within parsing/creating the environment (after the s, if any, and before or friends such as ) diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index a025930960..110694e215 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -16,6 +16,7 @@ #include "xbt/replay.h" #include "simgrid/sg_config.h" /* Configuration mechanism of SimGrid */ #include "src/surf/callbacks.h" +#include "src/surf/platform.hpp" XBT_LOG_NEW_CATEGORY(msg, "All MSG categories"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_kernel, msg, @@ -67,7 +68,7 @@ void MSG_init_nocheck(int *argc, char **argv) { SIMIX_function_register_process_create(MSG_process_create_from_SIMIX); SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX); - sg_platf_postparse_add_cb(MSG_post_create_environment); + simgrid::surf::on_postparse.connect(MSG_post_create_environment); simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host& host) { MSG_host_create_(&host); }); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 6acc54cd18..7721908bc8 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -37,6 +37,7 @@ #endif #include "src/mc/mc_record.h" +#include "src/surf/platform.hpp" #ifdef HAVE_SMPI #include "src/smpi/private.h" @@ -230,7 +231,7 @@ void SIMIX_global_init(int *argc, char **argv) #endif /* register a function to be called by SURF after the environment creation */ sg_platf_init(); - sg_platf_postparse_add_cb(SIMIX_post_create_environment); + simgrid::surf::on_postparse.connect(SIMIX_post_create_environment); simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host& host) { SIMIX_host_create(&host); }); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 6050f16a4c..ff1f38b131 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -8,6 +8,7 @@ #include "cpu_ti.hpp" #include "maxmin_private.hpp" #include "simgrid/sg_config.h" +#include "src/surf/platform.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu, "Logging specific to the SURF CPU IMPROVED module"); @@ -32,7 +33,7 @@ void surf_cpu_model_init_Cas01() surf_cpu_model_vm = new simgrid::surf::CpuCas01Model(); xbt_dynar_push(all_existing_models, &surf_cpu_model_vm); - sg_platf_postparse_add_cb(simgrid::surf::cpu_add_traces); + simgrid::surf::on_postparse.connect(simgrid::surf::cpu_add_traces); } namespace simgrid { diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 306312d1b2..564cd84e71 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -7,6 +7,7 @@ #include "cpu_ti.hpp" #include "trace_mgr_private.h" #include "xbt/heap.h" +#include "src/surf/platform.hpp" #ifndef SURF_MODEL_CPUTI_H_ #define SURF_MODEL_CPUTI_H_ @@ -390,7 +391,7 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high) static void cpu_ti_define_callbacks() { - sg_platf_postparse_add_cb(simgrid::surf::cpu_add_traces); + simgrid::surf::on_postparse.connect(simgrid::surf::cpu_add_traces); } /********* diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 255bfb310a..0c04470e33 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -13,6 +13,7 @@ #include "cpu_interface.hpp" #include "surf_routing.hpp" #include "xbt/lib.h" +#include "src/surf/platform.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host); @@ -33,8 +34,8 @@ void surf_host_model_init_ptask_L07(void) xbt_assert(!surf_network_model, "network model type already defined"); // Define the callbacks to parse the XML - sg_platf_link_add_cb(ptask_netlink_parse_init); - sg_platf_postparse_add_cb(host_add_traces); + simgrid::surf::on_link.connect(ptask_netlink_parse_init); + simgrid::surf::on_postparse.connect(host_add_traces); surf_host_model = new simgrid::surf::HostL07Model(); xbt_dynar_push(all_existing_models, &surf_host_model); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 5504f3d2ef..9f992f3314 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -8,6 +8,7 @@ #include "src/surf/surf_private.h" #include "xbt/graph.h" +#include "src/surf/platform.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy"); @@ -343,8 +344,8 @@ void instr_routing_define_callbacks () //always need the call backs to ASes (we need only the root AS), //to create the rootContainer and the rootType properly if (!TRACE_needs_platform()) return; - sg_platf_link_add_cb(instr_routing_parse_start_link); - sg_platf_postparse_add_cb(instr_routing_parse_end_platform); + simgrid::surf::on_link.connect(instr_routing_parse_start_link); + simgrid::surf::on_postparse.connect(instr_routing_parse_end_platform); } /* diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index c83cd4a71a..5163c8ce3d 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -9,6 +9,7 @@ #include "network_cm02.hpp" #include "maxmin_private.hpp" #include "simgrid/sg_config.h" +#include "src/surf/platform.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); @@ -27,8 +28,8 @@ int sg_network_crosstraffic = 0; void net_define_callbacks(void) { /* Figuring out the network links */ - sg_platf_link_add_cb(netlink_parse_init); - sg_platf_postparse_add_cb(net_add_traces); + simgrid::surf::on_link.connect(netlink_parse_init); + simgrid::surf::on_postparse.connect(net_add_traces); } /********* diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index e7a4195f2f..876546d1b4 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -8,6 +8,7 @@ #include "surf/random_mgr.h" #include "host_interface.hpp" +#include "src/surf/platform.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); static int host_number_int = 0; @@ -30,7 +31,7 @@ void surf_network_model_init_Constant() simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host&) { host_number_int++; }); - sg_platf_link_add_cb(netcste_parse_nolink); + simgrid::surf::on_link.connect(netcste_parse_nolink); simgrid::surf::Model *model = surf_network_model; xbt_dynar_push(all_existing_models, &model); diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 8649f82775..474c88bd94 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -8,6 +8,7 @@ #include "src/surf/surf_private.h" #include "src/surf/host_interface.hpp" #include "simgrid/sg_config.h" +#include "src/surf/platform.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3); @@ -232,11 +233,11 @@ static void define_callbacks_ns3(void) { simgrid::s4u::Host::onCreation.connect(simgrid_ns3_add_host); simgrid::surf::netcardCreatedCallbacks.connect(simgrid_ns3_add_router); - sg_platf_link_add_cb (&parse_ns3_add_link); - sg_platf_cluster_add_cb (&parse_ns3_add_cluster); + simgrid::surf::on_link.connect (&parse_ns3_add_link); + simgrid::surf::on_cluster.connect (&parse_ns3_add_cluster); simgrid::surf::asCreatedCallbacks.connect(parse_ns3_add_AS); - sg_platf_postparse_add_cb(&create_ns3_topology); //get_one_link_routes - sg_platf_postparse_add_cb(&parse_ns3_end_platform); //InitializeRoutes + simgrid::surf::on_postparse.connect(&create_ns3_topology); //get_one_link_routes + simgrid::surf::on_postparse.connect(&parse_ns3_end_platform); //InitializeRoutes } /********* diff --git a/src/surf/platform.hpp b/src/surf/platform.hpp new file mode 100644 index 0000000000..9db38ba0d5 --- /dev/null +++ b/src/surf/platform.hpp @@ -0,0 +1,24 @@ +/* Copyright (c) 2016. The SimGrid Team. + * All rights reserved. */ + +/* 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. */ + +#ifndef SIMGRID_PLATFORM_HPP +#define SIMGRID_PLATFORM_HPP + +#include +#include +#include + +namespace simgrid { +namespace surf { + +extern XBT_PRIVATE simgrid::xbt::signal on_link; +extern XBT_PRIVATE simgrid::xbt::signal on_cluster; +extern XBT_PRIVATE simgrid::xbt::signal on_postparse; + +} +} + +#endif diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index f1079cc1dc..c925a4c12a 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -15,14 +15,22 @@ #include "surf/surf.h" #include "src/simix/smx_private.h" +#include "src/surf/platform.hpp" #include "cpu_interface.hpp" #include "host_interface.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); -static simgrid::xbt::signal on_link; -static simgrid::xbt::signal on_cluster; -static simgrid::xbt::signal on_postparse; + +namespace simgrid { +namespace surf { + +simgrid::xbt::signal on_link; +simgrid::xbt::signal on_cluster; +simgrid::xbt::signal on_postparse; + +} +} static int surf_parse_models_setup_already_called = 0; @@ -35,9 +43,9 @@ void sg_platf_init(void) { /** Module management function: frees all internal data structures */ void sg_platf_exit(void) { - on_link.disconnect_all_slots(); - on_cluster.disconnect_all_slots(); - on_postparse.disconnect_all_slots(); + simgrid::surf::on_link.disconnect_all_slots(); + simgrid::surf::on_cluster.disconnect_all_slots(); + simgrid::surf::on_postparse.disconnect_all_slots(); /* make sure that we will reinit the models while loading the platf once reinited */ surf_parse_models_setup_already_called = 0; @@ -114,13 +122,13 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router) } void sg_platf_new_link(sg_platf_link_cbarg_t link){ - on_link(link); + simgrid::surf::on_link(link); } void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) { routing_new_cluster(cluster); - on_cluster(cluster); + simgrid::surf::on_cluster(cluster); } void sg_platf_new_storage(sg_platf_storage_cbarg_t storage) @@ -360,7 +368,7 @@ void sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASro void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ } void sg_platf_end() { - on_postparse(); + simgrid::surf::on_postparse(); } void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) @@ -400,16 +408,6 @@ void sg_platf_new_AS_end() } /* ***************************************** */ -void sg_platf_link_add_cb(sg_platf_link_cb_t fct) { - on_link.connect(fct); -} -void sg_platf_cluster_add_cb(sg_platf_cluster_cb_t fct) { - on_cluster.connect(fct); -} -void sg_platf_postparse_add_cb(void_f_void_t fct) { - on_postparse.connect(fct); -} - void sg_platf_rng_stream_init(unsigned long seed[6]) { RngStream_SetPackageSeed(seed); sg_platf_rng_stream = RngStream_CreateStream(NULL); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index b9a584ff9e..6b633bf97f 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -13,7 +13,7 @@ #include "simgrid/platf_interface.h" // platform creation API internal interface #include "simgrid/sg_config.h" #include "storage_interface.hpp" - +#include "src/surf/platform.hpp" #include "surf/surfxml_parse_values.h" /************* @@ -1226,8 +1226,8 @@ static void check_disk_attachment() void routing_register_callbacks() { - sg_platf_postparse_add_cb(routing_parse_postparse); - sg_platf_postparse_add_cb(check_disk_attachment); + simgrid::surf::on_postparse.connect(routing_parse_postparse); + simgrid::surf::on_postparse.connect(check_disk_attachment); instr_routing_define_callbacks(); } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 6f1feb437f..a09ab3966e 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -63,6 +63,7 @@ set(EXTRA_DIST src/surf/ns3/ns3_simulator.h src/surf/ns3/red-queue.h src/surf/platf_generator_private.h + src/surf/platform.hpp src/surf/plugins/energy.hpp src/surf/simgrid.dtd src/surf/simgrid_dtd.c -- 2.20.1