Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish the tutorial for new model and api
[simgrid.git] / src / surf / new_model.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team.
2  * All rights reserved.                                                                 */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package.             */
6
7 /* ********************************************************************* */
8 /* TUTORIAL: New model                                                   */
9 /* ********************************************************************* */
10
11 #include "xbt/ex.h"
12 #include "xbt/dict.h"
13 #include "xbt/file_stat.h"
14 #include "portable.h"
15 #include "surf_private.h"
16 #include "new_model_private.h"
17 #include "surf/surf_resource.h"
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_new_model, surf,
20                                 "Logging specific to the SURF new model module");
21
22 surf_model_t surf_new_model = NULL;
23 lmm_system_t new_model_maxmin_system = NULL;
24 static int new_model_selective_update = 0;
25 static xbt_swag_t
26     new_model_running_action_set_that_does_not_need_being_checked = NULL;
27
28 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
29 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
30
31 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state);
32 static surf_action_t new_model_action_execute ();
33
34 static surf_action_t new_model_action_fct()
35 {
36   surf_action_t action = new_model_action_execute();
37   return action;
38 }
39
40 static surf_action_t new_model_action_execute ()
41 {
42   THROW_UNIMPLEMENTED;
43   return NULL;
44 }
45
46 static void* new_model_create_resource(const char* id, const char* model,const char* type_id,const char* content_name)
47 {
48   THROW_UNIMPLEMENTED;
49   return NULL;
50 }
51
52 static void new_model_finalize(void)
53 {
54   lmm_system_free(new_model_maxmin_system);
55   new_model_maxmin_system = NULL;
56
57   surf_model_exit(surf_new_model);
58   surf_new_model = NULL;
59
60   xbt_swag_free
61       (new_model_running_action_set_that_does_not_need_being_checked);
62   new_model_running_action_set_that_does_not_need_being_checked = NULL;
63 }
64
65 static void new_model_update_actions_state(double now, double delta)
66 {
67   return;
68 }
69
70 static double new_model_share_resources(double NOW)
71 {
72   return -1;
73 }
74
75 static int new_model_resource_used(void *resource_id)
76 {
77   THROW_UNIMPLEMENTED;
78   return 0;
79 }
80
81 static void new_model_resources_state(void *id, tmgr_trace_event_t event_type,
82                                  double value, double time)
83 {
84   THROW_UNIMPLEMENTED;
85 }
86
87 static int new_model_action_unref(surf_action_t action)
88 {
89   THROW_UNIMPLEMENTED;
90   return 0;
91 }
92
93 static void new_model_action_cancel(surf_action_t action)
94 {
95   surf_action_state_set(action, SURF_ACTION_FAILED);
96   return;
97 }
98
99 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state)
100 {
101   surf_action_state_set(action, state);
102   return;
103 }
104
105 static void new_model_action_suspend(surf_action_t action)
106 {
107   XBT_IN("(%p)", action);
108   if (((surf_action_lmm_t) action)->suspended != 2) {
109     lmm_update_variable_weight(new_model_maxmin_system,
110                                ((surf_action_lmm_t) action)->variable,
111                                0.0);
112     ((surf_action_lmm_t) action)->suspended = 1;
113   }
114   XBT_OUT();
115 }
116
117 static void new_model_action_resume(surf_action_t action)
118 {
119   THROW_UNIMPLEMENTED;
120 }
121
122 static int new_model_action_is_suspended(surf_action_t action)
123 {
124   return (((surf_action_lmm_t) action)->suspended == 1);
125 }
126
127 static void new_model_action_set_max_duration(surf_action_t action, double duration)
128 {
129   THROW_UNIMPLEMENTED;
130 }
131
132 static void new_model_action_set_priority(surf_action_t action, double priority)
133 {
134   THROW_UNIMPLEMENTED;
135 }
136
137 static void new_model_define_callbacks()
138 {
139 }
140
141 static void surf_new_model_init_internal(void)
142 {
143   s_surf_action_t action;
144
145   XBT_DEBUG("surf_new_model_model_init_internal");
146   surf_new_model = surf_model_init();
147
148   new_model_running_action_set_that_does_not_need_being_checked =
149       xbt_swag_new(xbt_swag_offset(action, state_hookup));
150
151   surf_new_model->name = "New Model";
152   surf_new_model->action_unref = new_model_action_unref;
153   surf_new_model->action_cancel = new_model_action_cancel;
154   surf_new_model->action_state_set = new_model_action_state_set;
155
156   surf_new_model->model_private->finalize = new_model_finalize;
157   surf_new_model->model_private->update_actions_state = new_model_update_actions_state;
158   surf_new_model->model_private->share_resources = new_model_share_resources;
159   surf_new_model->model_private->resource_used = new_model_resource_used;
160   surf_new_model->model_private->update_resource_state = new_model_resources_state;
161
162   surf_new_model->suspend = new_model_action_suspend;
163   surf_new_model->resume = new_model_action_resume;
164   surf_new_model->is_suspended = new_model_action_is_suspended;
165   surf_new_model->set_max_duration = new_model_action_set_max_duration;
166   surf_new_model->set_priority = new_model_action_set_priority;
167
168   surf_new_model->extension.new_model.fct = new_model_action_fct;
169   surf_new_model->extension.new_model.create_resource = new_model_create_resource;
170
171   if (!new_model_maxmin_system) {
172     new_model_maxmin_system = lmm_system_new(new_model_selective_update);
173   }
174
175 }
176
177 void surf_new_model_init_default(void)
178 {
179   surf_new_model_init_internal();
180   new_model_define_callbacks();
181
182   xbt_dynar_push(model_list, &surf_new_model);
183 }