Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Skeleton of a timer (still lack a little bit of code to be effective).
[simgrid.git] / src / surf / surf_timer.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "surf_timer_private.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(timer, surf,
11                                 "Logging specific to the SURF timer module");
12
13 surf_timer_resource_t surf_timer_resource = NULL;
14 static tmgr_trace_t empty_trace = NULL;
15 static xbt_dict_t command_set = NULL;
16
17 static void timer_free(void *timer)
18 {
19   free(timer);
20 }
21
22 static command_t command_new(void *fun, void* args)
23 {
24   command_t command = xbt_new0(s_command_t, 1);
25
26   command->resource = (surf_resource_t) surf_timer_resource;
27   command->fun = fun;
28   command->args = args;
29 /*   command->name = name; */
30 /*   command->power_scale = power_scale; */
31 /*   xbt_assert0(command->power_scale>0,"Power has to be >0"); */
32 /*   command->power_current = power_initial; */
33 /*   if (power_trace) */
34 /*     command->power_event = */
35 /*      tmgr_history_add_trace(history, power_trace, 0.0, 0, command); */
36
37 /*   command->state_current = state_initial; */
38 /*   if (state_trace) */
39 /*     command->state_event = */
40 /*      tmgr_history_add_trace(history, state_trace, 0.0, 0, command); */
41
42 /*   command->constraint = */
43 /*       lmm_constraint_new(maxmin_system, command, */
44 /*                       command->power_current * command->power_scale); */
45
46 /*   xbt_dict_set(command_set, name, command, command_free); */
47
48   return command;
49 }
50
51 static void parse_timer(void)
52 {
53 }
54
55 static void parse_file(const char *file)
56 {
57 }
58
59 static void *name_service(const char *name)
60 {
61   DIE_IMPOSSIBLE;
62   return NULL;
63 }
64
65 static const char *get_resource_name(void *resource_id)
66 {
67   DIE_IMPOSSIBLE;
68   return "";
69 }
70
71 static int resource_used(void *resource_id)
72 {
73   return 1;
74 }
75
76 static void action_free(surf_action_t action)
77 {
78   DIE_IMPOSSIBLE;
79   return;
80 }
81
82 static void action_cancel(surf_action_t action)
83 {
84   DIE_IMPOSSIBLE;
85   return;
86 }
87
88 static void action_recycle(surf_action_t action)
89 {
90   DIE_IMPOSSIBLE;
91   return;
92 }
93
94 static void action_change_state(surf_action_t action,
95                                 e_surf_action_state_t state)
96 {
97   DIE_IMPOSSIBLE;
98   return;
99 }
100
101 static double share_resources(double now)
102 {
103   return -1.0;
104 }
105
106 static void update_actions_state(double now, double delta)
107 {
108   return;
109 }
110
111 static void update_resource_state(void *id,
112                                   tmgr_trace_event_t event_type,
113                                   double value)
114 {
115   command_t command = id;
116
117   // Move this command to the list of commands to execute
118
119   return;
120 }
121
122 static void set(double date, void *function, void *arg)
123 {
124   command_t command = NULL;
125
126   command = command_new(function, arg);
127
128   tmgr_history_add_trace(history, empty_trace, date, 0, command);
129   
130 }
131
132
133 static int get(void **function, void **arg)
134 {
135   return 0;
136 }
137
138 static void action_suspend(surf_action_t action)
139 {
140   DIE_IMPOSSIBLE;
141 }
142
143 static void action_resume(surf_action_t action)
144 {
145   DIE_IMPOSSIBLE;
146 }
147
148 static int action_is_suspended(surf_action_t action)
149 {
150   DIE_IMPOSSIBLE;
151   return 0;
152 }
153
154 static void finalize(void)
155 {
156   xbt_dict_free(&command_set);
157
158   xbt_swag_free(surf_timer_resource->common_public->states.ready_action_set);
159   xbt_swag_free(surf_timer_resource->common_public->states.
160                 running_action_set);
161   xbt_swag_free(surf_timer_resource->common_public->states.
162                 failed_action_set);
163   xbt_swag_free(surf_timer_resource->common_public->states.done_action_set);
164   free(surf_timer_resource->common_public);
165   free(surf_timer_resource->common_private);
166   free(surf_timer_resource->extension_public);
167
168   free(surf_timer_resource);
169   surf_timer_resource = NULL;
170 }
171
172 static void surf_timer_resource_init_internal(void)
173 {
174   s_surf_action_t action;
175
176   surf_timer_resource = xbt_new0(s_surf_timer_resource_t, 1);
177
178   surf_timer_resource->common_private =
179       xbt_new0(s_surf_resource_private_t, 1);
180   surf_timer_resource->common_public = xbt_new0(s_surf_resource_public_t, 1);
181
182   surf_timer_resource->extension_public =
183       xbt_new0(s_surf_timer_resource_extension_public_t, 1);
184
185   surf_timer_resource->common_public->states.ready_action_set =
186       xbt_swag_new(xbt_swag_offset(action, state_hookup));
187   surf_timer_resource->common_public->states.running_action_set =
188       xbt_swag_new(xbt_swag_offset(action, state_hookup));
189   surf_timer_resource->common_public->states.failed_action_set =
190       xbt_swag_new(xbt_swag_offset(action, state_hookup));
191   surf_timer_resource->common_public->states.done_action_set =
192       xbt_swag_new(xbt_swag_offset(action, state_hookup));
193
194   surf_timer_resource->common_public->name_service = name_service;
195   surf_timer_resource->common_public->get_resource_name = get_resource_name;
196   surf_timer_resource->common_public->action_get_state =
197       surf_action_get_state;
198   surf_timer_resource->common_public->action_free = action_free;
199   surf_timer_resource->common_public->action_cancel = action_cancel;
200   surf_timer_resource->common_public->action_recycle = action_recycle;
201   surf_timer_resource->common_public->action_change_state =
202       action_change_state;
203   surf_timer_resource->common_public->action_set_data = surf_action_set_data;
204   surf_timer_resource->common_public->name = "TIMER";
205
206   surf_timer_resource->common_private->resource_used = resource_used;
207   surf_timer_resource->common_private->share_resources = share_resources;
208   surf_timer_resource->common_private->update_actions_state =
209       update_actions_state;
210   surf_timer_resource->common_private->update_resource_state =
211       update_resource_state;
212   surf_timer_resource->common_private->finalize = finalize;
213
214   surf_timer_resource->common_public->suspend = action_suspend;
215   surf_timer_resource->common_public->resume = action_resume;
216   surf_timer_resource->common_public->is_suspended = action_is_suspended;
217
218   surf_timer_resource->extension_public->set = set;
219   surf_timer_resource->extension_public->get = get;
220
221   command_set = xbt_dict_new();
222   empty_trace = tmgr_empty_trace_new();
223
224   xbt_assert0(maxmin_system, "surf_init has to be called first!");
225 }
226
227 void surf_timer_resource_init(const char *filename)
228 {
229   if (surf_timer_resource)
230     return;
231   surf_timer_resource_init_internal();
232   xbt_dynar_push(resource_list, &surf_timer_resource);
233 }