From a38c139dae908a891ed224eb09f8d517f7bdf6b3 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 7 Nov 2011 11:31:15 +0100 Subject: [PATCH] Continue parser cleanups Prepare to split the interface of sg_platf in two: one public interface (include/simgrid/platf.h) will contain the function available to the user code to create elements while another interface (src/include/simgrid/platf_interface.h) will contain what internal modules need to declare callbacks on the element creation events. For now, the files are still very empty, but I try to not break stuff even further, so I commit soon. --- buildtools/Cmake/DefinePackages.cmake | 2 ++ include/simgrid/platf.h | 21 +++++++++++++++ src/include/simgrid/platf_interface.h | 27 +++++++++++++++++++ src/include/surf/datatypes.h | 1 - src/include/surf/surf.h | 5 +--- src/include/surf/surfxml_parse_values.h | 16 ----------- src/include/surf/trace_mgr.h | 1 + src/surf/sg_platf.c | 35 +++++++++++++++++++++++++ src/surf/surf_routing.c | 2 +- src/surf/surfxml_parse.c | 17 ++---------- 10 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 src/include/simgrid/platf_interface.h create mode 100644 src/surf/sg_platf.c diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index ef743ce0d5..c8043df848 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -48,6 +48,7 @@ set(EXTRA_DIST src/surf/gtnets/gtnets_topology.h src/surf/cpu_ti_private.h src/surf/surf_routing_private.h + src/include/simgrid/platf_interface.h src/include/surf/surf_resource.h src/include/surf/datatypes.h src/include/surf/maxmin.h @@ -230,6 +231,7 @@ set(SURF_SRC src/surf/workstation_ptask_L07.c src/surf/cpu_ti.c src/surf/cpu_im.c + src/surf/sg_platf.c src/xbt/xbt_sg_stubs.c ) diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index c6ec0f6c17..8014a9b70f 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -11,6 +11,27 @@ #include /* our toolbox */ +typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */ + +/** Defines whether a given resource is working or not */ +typedef enum { + SURF_RESOURCE_ON = 1, /**< Up & ready */ + SURF_RESOURCE_OFF = 0 /**< Down & broken */ +} e_surf_resource_state_t; + + +typedef struct s_surf_parsing_host_arg { + char* V_host_id; //id + double V_host_power_peak; //power + int V_host_core; //core + double V_host_power_scale; //availability + tmgr_trace_t V_host_power_trace; //availability file + e_surf_resource_state_t V_host_state_initial; //state + tmgr_trace_t V_host_state_trace; //state file + const char* V_host_coord; +} s_surf_parsing_host_arg_t, *surf_parsing_host_arg_t; + + XBT_PUBLIC(void) sg_platf_new_AS_open(const char *id, const char *mode); XBT_PUBLIC(void) sg_platf_new_AS_close(void); diff --git a/src/include/simgrid/platf_interface.h b/src/include/simgrid/platf_interface.h new file mode 100644 index 0000000000..a78eb2f639 --- /dev/null +++ b/src/include/simgrid/platf_interface.h @@ -0,0 +1,27 @@ +/* platf_interface.h - Internal interface to the SimGrid platforms */ + +/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010, 2011. 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 SG_PLATF_INTERFACE_H +#define SG_PLATF_INTERFACE_H + +#include "simgrid/platf.h" /* public interface */ + +/* Module management functions */ +void sg_platf_init(void); +void sg_platf_exit(void); + +/* Managing the parsing callbacks */ + +typedef void (*surf_parse_host_fct_t)(surf_parsing_host_arg_t); +void surf_parse_host_add_cb(surf_parse_host_fct_t); + +void surf_parse_host(surf_parsing_host_arg_t h); + + + +#endif /* SG_PLATF_INTERFACE_H */ diff --git a/src/include/surf/datatypes.h b/src/include/surf/datatypes.h index ff6bd66a09..bac27788c4 100644 --- a/src/include/surf/datatypes.h +++ b/src/include/surf/datatypes.h @@ -29,7 +29,6 @@ typedef struct lmm_constraint *lmm_constraint_t; typedef struct lmm_system *lmm_system_t; typedef struct tmgr_history *tmgr_history_t; -typedef struct tmgr_trace *tmgr_trace_t; typedef struct tmgr_trace_event *tmgr_trace_event_t; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index cde8899573..f33177c428 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -16,13 +16,10 @@ #include "surf/datatypes.h" #include "xbt/lib.h" #include "surf/surf_routing.h" +#include "simgrid/platf_interface.h" SG_BEGIN_DECL() /* Actions and models are highly connected structures... */ -typedef enum { - SURF_RESOURCE_ON = 1, /**< Up & ready */ - SURF_RESOURCE_OFF = 0 /**< Down & broken */ -} e_surf_resource_state_t; typedef enum { SURF_LINK_FULLDUPLEX = 2, diff --git a/src/include/surf/surfxml_parse_values.h b/src/include/surf/surfxml_parse_values.h index 70cbc24a26..c38d061365 100644 --- a/src/include/surf/surfxml_parse_values.h +++ b/src/include/surf/surfxml_parse_values.h @@ -57,18 +57,6 @@ typedef struct s_surf_parsing_router_arg { char* V_router_coord; } s_surf_parsing_router_arg_t; -typedef struct s_surf_parsing_host_arg *surf_parsing_host_arg_t; -typedef struct s_surf_parsing_host_arg { - char* V_host_id; //id - double V_host_power_peak; //power - int V_host_core; //core - double V_host_power_scale; //availability - tmgr_trace_t V_host_power_trace; //availability file - e_surf_resource_state_t V_host_state_initial; //state - tmgr_trace_t V_host_state_trace; //state file - const char* V_host_coord; -} s_surf_parsing_host_arg_t; - typedef struct s_surf_parsing_link_up_down *surf_parsing_link_up_down_t; typedef struct s_surf_parsing_link_up_down { void* link_up; @@ -76,15 +64,11 @@ typedef struct s_surf_parsing_link_up_down { } s_surf_parsing_link_up_down_t; -typedef void (*surf_parse_host_fct_t)(surf_parsing_host_arg_t); -void surf_parse_host_add_cb(surf_parse_host_fct_t); - extern surf_parsing_router_arg_t struct_router; extern surf_parsing_cluster_arg_t struct_cluster; extern surf_parsing_peer_arg_t struct_peer; extern surf_parsing_link_arg_t struct_lnk; -void surf_parse_host(surf_parsing_host_arg_t h); void surf_parse_link(void); #endif /* SURFXML_PARSE_VALUES_H_ */ diff --git a/src/include/surf/trace_mgr.h b/src/include/surf/trace_mgr.h index d8de2e75db..394cddca52 100644 --- a/src/include/surf/trace_mgr.h +++ b/src/include/surf/trace_mgr.h @@ -11,6 +11,7 @@ #include "xbt/dynar.h" #include "surf/maxmin.h" #include "surf/datatypes.h" +#include "simgrid/platf_interface.h" /* Creation functions */ XBT_PUBLIC(tmgr_history_t) tmgr_history_new(void); diff --git a/src/surf/sg_platf.c b/src/surf/sg_platf.c new file mode 100644 index 0000000000..89eff09117 --- /dev/null +++ b/src/surf/sg_platf.c @@ -0,0 +1,35 @@ +/* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. 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. */ + +#include "xbt/misc.h" +#include "xbt/log.h" +#include "xbt/str.h" +#include "xbt/dict.h" +#include "simgrid/platf_interface.h" +#include "surf/surf_private.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); +xbt_dynar_t surf_parse_host_cb_list = NULL; // of functions of type: surf_parsing_host_arg_t -> void + +/** Module management function: creates all internal data structures */ +void sg_platf_init(void) { + surf_parse_host_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_t), NULL); +} +/** Module management function: frees all internal data structures */ +void sg_platf_exit(void) { + xbt_dynar_free(&surf_parse_host_cb_list); +} + +void surf_parse_host(surf_parsing_host_arg_t h){ + unsigned int iterator; + surf_parse_host_fct_t fun; + xbt_dynar_foreach(surf_parse_host_cb_list, iterator, fun) { + if (fun) (*fun) (h); + } +} +void surf_parse_host_add_cb(surf_parse_host_fct_t fct) { + xbt_dynar_push(surf_parse_host_cb_list, &fct); +} diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 8344e4a733..634b3c7e38 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -6,7 +6,7 @@ #include /* regular expression library */ -#include "simgrid/platf.h" // platform creation API +#include "simgrid/platf_interface.h" // platform creation API internal interface #include "surf_routing_private.h" #include "surf/surf_routing.h" diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index a438b8f5ac..e2573452ab 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -49,7 +49,6 @@ int surf_parse_get_int(const char *string) { /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */ //xbt_dynar_t STag_surfxml_host_cb_list = NULL; -xbt_dynar_t surf_parse_host_cb_list = NULL; // of functions of type: surf_parsing_host_arg_t -> void xbt_dynar_t STag_surfxml_platform_cb_list = NULL; xbt_dynar_t ETag_surfxml_platform_cb_list = NULL; xbt_dynar_t ETag_surfxml_host_cb_list = NULL; @@ -162,8 +161,7 @@ void surf_parse_init_callbacks(void) ETag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - surf_parse_host_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_t), NULL); - + sg_platf_init(); ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); @@ -225,7 +223,7 @@ void surf_parse_reset_callbacks(void) void surf_parse_free_callbacks(void) { - xbt_dynar_free(&surf_parse_host_cb_list); + sg_platf_exit(); xbt_dynar_free(&STag_surfxml_platform_cb_list); xbt_dynar_free(&ETag_surfxml_platform_cb_list); @@ -294,7 +292,6 @@ void STag_surfxml_platform(void) } void STag_surfxml_host(void){ -// XBT_INFO("STag_surfxml_host [%s]",A_surfxml_host_id); s_surf_parsing_host_arg_t host; memset(&host,0,sizeof(host)); @@ -314,16 +311,6 @@ void STag_surfxml_host(void){ surf_parse_host(&host); } -void surf_parse_host(surf_parsing_host_arg_t h){ - unsigned int iterator; - surf_parse_host_fct_t fun; - xbt_dynar_foreach(surf_parse_host_cb_list, iterator, fun) { - if (fun) (*fun) (h); - } -} -void surf_parse_host_add_cb(surf_parse_host_fct_t fct) { - xbt_dynar_push(surf_parse_host_cb_list, &fct); -} void ETag_surfxml_host(void){ surfxml_call_cb_functions(ETag_surfxml_host_cb_list); } -- 2.20.1