#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 */
-#ifndef SIMDAG_H
-#define SIMDAG_H
+#ifndef SIMDAG_SIMDAG_H
+#define SIMDAG_SIMDAG_H
#include "simdag/datatypes.h"
#include "xbt/misc.h"
/************************** 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);
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 ************************************/
/************************** 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()
#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 */
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
#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.
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.
*/
/* 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 */
+ }
+}
+#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;*/
/* 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);
}
*/
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);
}
+#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;
*/
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) {
/* 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);
}