From: thiery Date: Thu, 15 Jun 2006 14:44:52 +0000 (+0000) Subject: Add private structures and functions + wrapping for Surf links and workstations X-Git-Tag: v3.3~2977 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8d0eaea75f444b5ac20edfca6d4ce04cee7307e7 Add private structures and functions + wrapping for Surf links and workstations git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2381 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/simdag/datatypes.h b/include/simdag/datatypes.h index f21af30453..1b1ad0beb0 100644 --- a/include/simdag/datatypes.h +++ b/include/simdag/datatypes.h @@ -2,21 +2,28 @@ #define SIMDAG_DATATYPES_H /* Link */ +typedef struct SG_link_data *SG_link_data_t; + typedef struct SG_link { - void *data; + SG_link_data_t sgdata; /* SG internal data */ + void *data; /* user data */ char *name; + /*double capacity;*/ /*double current_bandwidth; double current_latency;*/ } s_SG_link_t, *SG_link_t; /* Workstation */ +typedef struct SG_workstation_data *SG_workstation_data_t; + typedef struct SG_workstation { - void *data; + SG_workstation_data_t sgdata; /* SG internal data */ + void *data; /* user data */ char *name; - /*double power; + + /* double power; double available_power;*/ - /* TODO: route */ } s_SG_workstation_t, *SG_workstation_t; /* Task state */ diff --git a/include/simdag/simdag.h b/include/simdag/simdag.h index 90ed019f48..609f689d1e 100644 --- a/include/simdag/simdag.h +++ b/include/simdag/simdag.h @@ -1,5 +1,5 @@ -#ifndef SIMDAG_H -#define SIMDAG_H +#ifndef SIMDAG_SIMDAG_H +#define SIMDAG_SIMDAG_H #include "simdag/datatypes.h" #include "xbt/misc.h" @@ -8,20 +8,24 @@ SG_BEGIN_DECL() /************************** Link handling ***********************************/ -SG_link_t SG_link_create(void *data, const char *name,/* double capacity,*/ - double bandwidth, double latency); +/* private (called by SG_environment_create) +SG_link_t SG_link_create(void *data, const char *name, +double bandwidth, double latency);*/ void* SG_link_get_data(SG_link_t link); void SG_link_set_data(SG_link_t link, void *data); const char* SG_link_get_name(SG_link_t link); double SG_link_get_capacity(SG_link_t link); double SG_link_get_current_bandwidth(SG_link_t link); double SG_link_get_current_latency(SG_link_t link); +/* private (called by SG_clean) void SG_link_destroy(SG_link_t link); +*/ /************************** Workstation handling ****************************/ +/* private (called by SG_environment_create) SG_workstation_t SG_workstation_create(void *data, const char *name, double power, - double available_power); + double available_power);*/ SG_workstation_t SG_workstation_get_by_name(const char *name); SG_workstation_t* SG_workstation_get_list(void); int SG_workstation_get_number(void); @@ -32,7 +36,9 @@ SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workst int SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst); double SG_workstation_get_power(SG_workstation_t workstation); double SG_workstation_get_available_power(SG_workstation_t workstation); +/* private (called by SG_clean) void SG_workstation_destroy(SG_workstation_t workstation); +*/ /************************** Task handling ************************************/ @@ -62,7 +68,9 @@ void SG_task_destroy(SG_task_t task); /************************** Global *******************************************/ void SG_init(int *argc, char **argv); +void SG_create_environment(const char *platform_file); SG_task_t *SG_simulate(double how_long); /* returns a NULL-terminated array of SG_task_t whose state has changed */ +void SG_clean(); /* cleans everything */ SG_END_DECL() diff --git a/src/simdag/private.h b/src/simdag/private.h index e032bdca32..c86ff69b8d 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -2,6 +2,10 @@ #define SIMDAG_PRIVATE_H #include "xbt/dict.h" +#include "simdag/simdag.h" +#include "simdag/datatypes.h" + +/* Global variables */ typedef struct SG_global { xbt_dict_t workstations; /* workstation list */ @@ -10,4 +14,24 @@ typedef struct SG_global { extern SG_global_t sg_global; +/* Link private data */ +typedef struct SG_link_data { + void* surf_link; /* surf object */ + +} s_SG_link_data_t; + +/* Workstation private data */ +typedef struct SG_workstation_data { + void* surf_workstation; /* surf object */ + /* TODO: route */ +} s_SG_workstation_data_t; + +/* Private functions */ + +SG_link_t __SG_link_create(const char *name, void *surf_link, void *data); +void __SG_link_destroy(SG_link_t link); + +SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data); +void __SG_workstation_destroy(SG_workstation_t workstation); + #endif diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 332e26cfc2..985797bae9 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -4,6 +4,10 @@ #include "xbt/sysdep.h" #include "surf/surf.h" +#define CHECK_INIT_DONE() xbt_assert0(init_done, "SG_init not called yet") + +SG_global_t sg_global = NULL; + static int init_done = 0; /* Initialises SG internal data. This function should be called before any other SG function. @@ -20,20 +24,24 @@ void SG_init(int *argc, char **argv) { init_done = 1; } -/* Checks that SG_init has been called. - */ -void check_init_done() { - xbt_assert0(init_done, "SG_init not called yet"); -} - /* Creates the environnement described in a xml file of a platform descriptions. */ -void SG_create_environnement(const char *platform_file) { - check_init_done(); +void SG_create_environment(const char *platform_file) { + xbt_dict_cursor_t cursor = NULL; + char *name = NULL; + void *workstation = NULL; + + CHECK_INIT_DONE(); surf_timer_resource_init(platform_file); surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */ -} + /* now let's create the SG wrappers */ + xbt_dict_foreach(workstation_set, cursor, name, workstation) { + + __SG_workstation_create(name, workstation, NULL); + } + +} /* Launches the simulation. Returns a NULL-terminated array of SG_task_t whose state has changed. */ @@ -42,3 +50,14 @@ SG_task_t* SG_simulate(double how_long) /* TODO */ return NULL; } + +/* Destroys all SG data. This function should be called when the simulation is over. + */ +void SG_clean() { + if (init_done) { + xbt_dict_free(&sg_global->workstations); + xbt_free(sg_global); + surf_exit(); + /* TODO: destroy the workstations, the links and the tasks */ + } +} diff --git a/src/simdag/sd_link.c b/src/simdag/sd_link.c index 272ceba542..fcfc57858f 100644 --- a/src/simdag/sd_link.c +++ b/src/simdag/sd_link.c @@ -1,15 +1,19 @@ +#include "private.h" #include "simdag/simdag.h" #include "xbt/sysdep.h" /* xbt_new0 */ /* Creates a link. */ -SG_link_t SG_link_create(void *data, const char *name,/* double capacity,*/ double bandwidth, double latency) { - /* xbt_assert0(capacity >= 0, "Invalid parameter");*/ /* or capacity > 0 ? */ +SG_link_t __SG_link_create(const char *name, void *surf_link, void *data) { + xbt_assert0(surf_link != NULL, "surf_link is NULL !"); + SG_link_data_t sgdata = xbt_new0(s_SG_link_data_t, 1); /* link private data */ + sgdata->surf_link = surf_link; SG_link_t link = xbt_new0(s_SG_link_t, 1); - - link->data = data; link->name = xbt_strdup(name); + link->data = data; + link->sgdata = sgdata; + /*link->capacity = capacity;*/ /* link->current_bandwidth = bandwidth; link->current_latency = latency;*/ @@ -68,11 +72,11 @@ double SG_link_get_current_latency(SG_link_t link) { /* Destroys a link. The user data (if any) should have been destroyed first. */ -void SG_link_destroy(SG_link_t link) { +void __SG_link_destroy(SG_link_t link) { xbt_assert0(link, "Invalid parameter"); if (link->name) - free(link->name); + xbt_free(link->name); - free(link); + xbt_free(link); } diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index d4a81dd79e..3a22af598f 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -119,8 +119,8 @@ void SG_task_unschedule(SG_task_t task) { */ void SG_task_destroy(SG_task_t task) { if (task->name) - free(task->name); + xbt_free(task->name); /* TODO: dependencies + watch */ - free(task); + xbt_free(task); } diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 38ffb85d70..42b93b49d4 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -1,20 +1,21 @@ +#include "private.h" #include "simdag/simdag.h" #include "xbt/dict.h" #include "xbt/sysdep.h" -#include "private.h" -/* Creates a workstation. +/* Creates a workstation and registers it in SG. */ -SG_workstation_t SG_workstation_create(void *data, const char *name, double power, - double available_power) { - xbt_assert0(power >= 0 && available_power >= 0, "Invalid parameter"); /* or > 0 ? */ - - SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1); +SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data) { + SG_workstation_data_t sgdata = xbt_new0(s_SG_workstation_data_t, 1); /* workstation private data */ + sgdata->surf_workstation = surf_workstation; - workstation->data = data; + SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1); workstation->name = xbt_strdup(name); - /*workstation->power = power; - workstation->available_power = power;*/ + workstation->data = data; /* user data */ + workstation->sgdata = sgdata; /* private data */ + + xbt_dict_set(sg_global->workstations, name, workstation, free); /* add the workstation to the dictionary */ + /* TODO: route */ return workstation; @@ -73,7 +74,8 @@ void* SG_workstation_get_data(SG_workstation_t workstation) { */ const char* SG_workstation_get_name(SG_workstation_t workstation) { xbt_assert0(workstation != NULL, "Invalid parameter"); - return workstation->name; + return NULL; + /* return workstation->name;*/ } SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) { @@ -106,13 +108,15 @@ double SG_workstation_get_available_power(SG_workstation_t workstation) { /* Destroys a workstation. The user data (if any) should have been destroyed first. */ -void SG_workstation_destroy(SG_workstation_t workstation) { +void __SG_workstation_destroy(SG_workstation_t workstation) { xbt_assert0(workstation != NULL, "Invalid parameter"); - if (workstation->name) - free(workstation->name); - + SG_workstation_data_t sgdata = workstation->sgdata; + if (sgdata != NULL) { + xbt_free(sgdata); + } + /* TODO: route */ - free(workstation); + xbt_free(workstation); }