Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the API between Engine and EngineImpl when registering functions
[simgrid.git] / src / msg / msg_legacy.cpp
1 /* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/Exception.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "xbt/functional.hpp"
10
11 #define MSG_CALL(type, oldname, args)
12
13 /* ************************** Engine *************************** */
14 void MSG_create_environment(const char* filename)
15 {
16   simgrid_load_platform(filename);
17 }
18
19 void MSG_launch_application(const char* filename)
20 {
21   simgrid_load_deployment(filename);
22 }
23 msg_error_t MSG_main()
24 {
25   simgrid_run();
26   return MSG_OK;
27 }
28 void MSG_function_register(const char* name, int (*code)(int, char**))
29 {
30   simgrid::s4u::Engine::get_instance()->register_function(
31       name, [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
32 }
33 void MSG_function_register_default(int (*code)(int, char**))
34 {
35   simgrid::s4u::Engine::get_instance()->register_default(
36       [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
37 }
38 double MSG_get_clock()
39 {
40   return simgrid_get_clock();
41 }
42
43 /* ************************** Mailboxes ************************ */
44 void MSG_mailbox_set_async(const char* alias)
45 {
46   sg_mailbox_set_receiver(alias);
47 }
48 int MSG_task_listen(const char* alias)
49 {
50   return sg_mailbox_listen(alias);
51 }
52
53 /* ************************** Actors *************************** */
54 int MSG_process_get_PID(const_sg_actor_t actor)
55 {
56   return sg_actor_get_PID(actor);
57 }
58 int MSG_process_get_PPID(const_sg_actor_t actor)
59 {
60   return sg_actor_get_PPID(actor);
61 }
62 msg_process_t MSG_process_from_PID(int PID)
63 {
64   return sg_actor_by_PID(PID);
65 }
66 const char* MSG_process_get_name(const_sg_actor_t actor)
67 {
68   return sg_actor_get_name(actor);
69 }
70 sg_host_t MSG_process_get_host(const_sg_actor_t actor)
71 {
72   return sg_actor_get_host(actor);
73 }
74 xbt_dict_t MSG_process_get_properties(const_sg_actor_t actor)
75 {
76   return sg_actor_get_properties(actor);
77 }
78 const char* MSG_process_get_property_value(const_sg_actor_t actor, const char* name)
79 {
80   return sg_actor_get_property_value(actor, name);
81 }
82 void MSG_process_suspend(sg_actor_t actor)
83 {
84   sg_actor_suspend(actor);
85 }
86 void MSG_process_resume(sg_actor_t actor)
87 {
88   sg_actor_resume(actor);
89 }
90 int MSG_process_is_suspended(sg_actor_t actor)
91 {
92   return sg_actor_is_suspended(actor);
93 }
94 void MSG_process_restart(sg_actor_t actor)
95 {
96   sg_actor_restart(actor);
97 }
98 void MSG_process_auto_restart_set(sg_actor_t actor, int auto_restart)
99 {
100   sg_actor_set_auto_restart(actor, auto_restart);
101 }
102
103 void MSG_process_daemonize(sg_actor_t actor)
104 {
105   sg_actor_daemonize(actor);
106 }
107 void MSG_process_migrate(sg_actor_t actor, sg_host_t host)
108 {
109   sg_actor_set_host(actor, host);
110 }
111 void MSG_process_join(sg_actor_t actor, double timeout)
112 {
113   sg_actor_join(actor, timeout);
114 }
115 void MSG_process_kill(sg_actor_t actor)
116 {
117   sg_actor_kill(actor);
118 }
119 void MSG_process_killall()
120 {
121   sg_actor_kill_all();
122 }
123 void MSG_process_set_kill_time(sg_actor_t actor, double kill_time)
124 {
125   sg_actor_set_kill_time(actor, kill_time);
126 }
127 void MSG_process_yield()
128 {
129   sg_actor_yield();
130 }
131
132 msg_error_t MSG_process_sleep(double duration)
133 {
134   try {
135     sg_actor_sleep_for(duration);
136     return MSG_OK;
137   } catch (const simgrid::HostFailureException&) {
138     return MSG_HOST_FAILURE;
139   }
140 }
141
142 /** @brief Returns the user data of a process.
143  *
144  * This function checks whether @a process is a valid pointer and returns the user data associated to this process.
145  */
146 void* MSG_process_get_data(const_sg_actor_t process)
147 {
148   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
149
150   /* get from SIMIX the MSG process data, and then the user data */
151   return sg_actor_data(process);
152 }
153
154 /** @brief Sets the user data of a process.
155  *
156  * This function checks whether @a process is a valid pointer and sets the user data associated to this process.
157  */
158 msg_error_t MSG_process_set_data(msg_process_t process, void* data)
159 {
160   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
161   sg_actor_data_set(process, data);
162
163   return MSG_OK;
164 }
165
166 msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties)
167 {
168   return sg_actor_attach(name, data, host, properties);
169 }
170
171 void MSG_process_detach()
172 {
173   sg_actor_detach();
174 }
175 aid_t MSG_process_self_PID()
176 {
177   return sg_actor_self_get_pid();
178 }
179
180 /** @brief Return the PPID of the current process.
181  *
182  * This function returns the PID of the parent of the currently running #msg_process_t.
183  */
184 aid_t MSG_process_self_PPID()
185 {
186   return sg_actor_self_get_ppid();
187 }
188
189 /** @brief Return the name of the current process. */
190 const char* MSG_process_self_name()
191 {
192   return sg_actor_self_get_name();
193 }
194 /** @brief Return the current process.
195  *
196  * This function returns the currently running #msg_process_t.
197  */
198 msg_process_t MSG_process_self()
199 {
200   return sg_actor_self();
201 }
202
203 /** @brief Take an extra reference on that process to prevent it to be garbage-collected */
204 void MSG_process_ref(const_sg_actor_t process)
205 {
206   sg_actor_ref(process);
207 }
208 /** @brief Release a reference on that process so that it can get be garbage-collected */
209 void MSG_process_unref(const_sg_actor_t process)
210 {
211   sg_actor_unref(process);
212 }
213 /** @brief Return the current number MSG processes. */
214 int MSG_process_get_number()
215 {
216   return simgrid_get_actor_count();
217 }
218 /* ************************** NetZones *************************** */
219 sg_netzone_t MSG_zone_get_root()
220 {
221   return sg_zone_get_root();
222 }
223 const char* MSG_zone_get_name(const_sg_netzone_t zone)
224 {
225   return sg_zone_get_name(zone);
226 }
227 sg_netzone_t MSG_zone_get_by_name(const char* name)
228 {
229   return sg_zone_get_by_name(name);
230 }
231 void MSG_zone_get_sons(const_sg_netzone_t zone, xbt_dict_t whereto)
232 {
233   return sg_zone_get_sons(zone, whereto);
234 }
235 const char* MSG_zone_get_property_value(const_sg_netzone_t zone, const char* name)
236 {
237   return sg_zone_get_property_value(zone, name);
238 }
239 void MSG_zone_set_property_value(sg_netzone_t zone, const char* name, const char* value)
240 {
241   sg_zone_set_property_value(zone, name, value);
242 }
243 void MSG_zone_get_hosts(const_sg_netzone_t zone, xbt_dynar_t whereto)
244 {
245   sg_zone_get_hosts(zone, whereto);
246 }
247
248 /* ************************** Storages *************************** */
249 const char* MSG_storage_get_name(const_sg_storage_t storage)
250 {
251   return sg_storage_get_name(storage);
252 }
253 sg_storage_t MSG_storage_get_by_name(const char* name)
254 {
255   return sg_storage_get_by_name(name);
256 }
257 xbt_dict_t MSG_storage_get_properties(const_sg_storage_t storage)
258 {
259   return sg_storage_get_properties(storage);
260 }
261 void MSG_storage_set_property_value(sg_storage_t storage, const char* name, const char* value)
262 {
263   sg_storage_set_property_value(storage, name, value);
264 }
265 const char* MSG_storage_get_property_value(const_sg_storage_t storage, const char* name)
266 {
267   return sg_storage_get_property_value(storage, name);
268 }
269 xbt_dynar_t MSG_storages_as_dynar()
270 {
271   return sg_storages_as_dynar();
272 }
273 void MSG_storage_set_data(sg_storage_t storage, void* data)
274 {
275   sg_storage_set_data(storage, data);
276 }
277 void* MSG_storage_get_data(const_sg_storage_t storage)
278 {
279   return sg_storage_get_data(storage);
280 }
281 const char* MSG_storage_get_host(const_sg_storage_t storage)
282 {
283   return sg_storage_get_host(storage);
284 }
285 sg_size_t MSG_storage_read(sg_storage_t storage, sg_size_t size)
286 {
287   return sg_storage_read(storage, size);
288 }
289 sg_size_t MSG_storage_write(sg_storage_t storage, sg_size_t size)
290 {
291   return sg_storage_write(storage, size);
292 }
293
294 /* ************************** hosts *************************** */
295 xbt_dynar_t MSG_hosts_as_dynar()
296 {
297   return sg_hosts_as_dynar();
298 }
299 size_t MSG_get_host_number()
300 {
301   return sg_host_count();
302 }
303 sg_host_t MSG_get_host_by_name(const char* name)
304 {
305   return sg_host_by_name(name);
306 }
307 sg_host_t MSG_host_by_name(const char* name)
308 {
309   return sg_host_by_name(name);
310 }
311 const char* MSG_host_get_name(const_sg_host_t host)
312 {
313   return sg_host_get_name(host);
314 }
315 void* MSG_host_get_data(const_sg_host_t host)
316 {
317   return sg_host_data(host);
318 }
319 void MSG_host_set_data(sg_host_t host, void* data)
320 {
321   return sg_host_data_set(host, data);
322 }
323 xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host)
324 {
325   return sg_host_get_mounted_storage_list(host);
326 }
327 xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host)
328 {
329   return sg_host_get_attached_storage_list(host);
330 }
331 double MSG_host_get_speed(const_sg_host_t host)
332 {
333   return sg_host_speed(host);
334 }
335 double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index)
336 {
337   return sg_host_get_pstate_speed(host, pstate_index);
338 }
339 int MSG_host_get_core_number(const_sg_host_t host)
340 {
341   return sg_host_core_count(host);
342 }
343 int MSG_host_get_nb_pstates(const_sg_host_t host)
344 {
345   return sg_host_get_nb_pstates(host);
346 }
347 int MSG_host_get_pstate(const_sg_host_t host)
348 {
349   return sg_host_get_pstate(host);
350 }
351 void MSG_host_set_pstate(sg_host_t host, int pstate)
352 {
353   sg_host_set_pstate(host, pstate);
354 }
355 void MSG_host_on(sg_host_t h)
356 {
357   sg_host_turn_on(h);
358 }
359 void MSG_host_off(sg_host_t h)
360 {
361   sg_host_turn_off(h);
362 }
363 int MSG_host_is_on(const_sg_host_t h)
364 {
365   return sg_host_is_on(h);
366 }
367 xbt_dict_t MSG_host_get_properties(const_sg_host_t host)
368 {
369   return sg_host_get_properties(host);
370 }
371 const char* MSG_host_get_property_value(const_sg_host_t host, const char* name)
372 {
373   return sg_host_get_property_value(host, name);
374 }
375 void MSG_host_set_property_value(sg_host_t host, const char* name, const char* value)
376 {
377   sg_host_set_property_value(host, name, value);
378 }
379 void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto)
380 {
381   sg_host_get_actor_list(host, whereto);
382 }
383 sg_host_t MSG_host_self()
384 {
385   return sg_host_self();
386 }
387
388 double MSG_host_get_load(const_sg_host_t host)
389 {
390   return sg_host_load(host);
391 }
392 /* ************************** Virtual Machines *************************** */
393 sg_vm_t MSG_vm_create_core(sg_host_t pm, const char* name)
394 {
395   return sg_vm_create_core(pm, name);
396 }
397 sg_vm_t MSG_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount)
398 {
399   return sg_vm_create_multicore(pm, name, coreAmount);
400 }
401 int MSG_vm_is_created(sg_vm_t vm)
402 {
403   return sg_vm_is_created(vm);
404 }
405 int MSG_vm_is_running(sg_vm_t vm)
406 {
407   return sg_vm_is_running(vm);
408 }
409 int MSG_vm_is_suspended(sg_vm_t vm)
410 {
411   return sg_vm_is_suspended(vm);
412 }
413 const char* MSG_vm_get_name(const_sg_vm_t vm)
414 {
415   return sg_vm_get_name(vm);
416 }
417 void MSG_vm_set_ramsize(sg_vm_t vm, size_t size)
418 {
419   sg_vm_set_ramsize(vm, size);
420 }
421 size_t MSG_vm_get_ramsize(const_sg_vm_t vm)
422 {
423   return sg_vm_get_ramsize(vm);
424 }
425 sg_host_t MSG_vm_get_pm(const_sg_vm_t vm)
426 {
427   return sg_vm_get_pm(vm);
428 }
429 void MSG_vm_set_bound(sg_vm_t vm, double bound)
430 {
431   sg_vm_set_bound(vm, bound);
432 }
433 void MSG_vm_start(sg_vm_t vm)
434 {
435   sg_vm_start(vm);
436 }
437 void MSG_vm_suspend(sg_vm_t vm)
438 {
439   sg_vm_suspend(vm);
440 }
441 void MSG_vm_resume(sg_vm_t vm)
442 {
443   sg_vm_resume(vm);
444 }
445 void MSG_vm_shutdown(sg_vm_t vm)
446 {
447   sg_vm_shutdown(vm);
448 }
449 void MSG_vm_destroy(sg_vm_t vm)
450 {
451   sg_vm_destroy(vm);
452 }
453 /********* barriers ************/
454 sg_bar_t MSG_barrier_init(unsigned int count)
455 {
456   return sg_barrier_init(count);
457 }
458
459 void MSG_barrier_destroy(const_sg_bar_t bar)
460 {
461   sg_barrier_destroy(bar);
462 }
463
464 int MSG_barrier_wait(sg_bar_t bar)
465 {
466   return sg_barrier_wait(bar);
467 }
468
469 sg_sem_t MSG_sem_init(int initial_value)
470 {
471   return sg_sem_init(initial_value);
472 }
473 void MSG_sem_acquire(sg_sem_t sem)
474 {
475   sg_sem_acquire(sem);
476 }
477 int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
478 {
479   return sg_sem_acquire_timeout(sem, timeout);
480 }
481 void MSG_sem_release(sg_sem_t sem)
482 {
483   sg_sem_release(sem);
484 }
485 int MSG_sem_get_capacity(sg_sem_t sem)
486 {
487   return sg_sem_get_capacity(sem);
488 }
489 void MSG_sem_destroy(const_sg_sem_t sem)
490 {
491   sg_sem_destroy(sem);
492 }
493 int MSG_sem_would_block(sg_sem_t sem)
494 {
495   return sg_sem_would_block(sem);
496 }