Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
48821a9cba467f254b38c10ab0e6777fd0e45efa
[simgrid.git] / src / bindings / ruby_bindings.h
1 /* SimGrid -- Ruby bindings */
2
3 /* Copyright (c) 2010, the SimGrid team. All right 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
9 #ifndef RB_SG_BINDINGS
10 #define RB_SG_BINDINGS
11 /*
12  * There is 4 sections in this file:
13  *  - Header loading (ruby makes it quite difficult, damn it)
14  *  - definitions of ruby contextes for use in simix
15  *  - Functions to Manage The Ruby Process  (named Up Calls)
16  *  - Functions to Manage The Native Process Simulation Bound (named Down Calls)
17  */
18
19 #include "msg/msg.h"
20 #include "msg/datatypes.h"
21
22 #include "surf/surfxml_parse.h"
23 #include "simix/simix.h"
24 #include "simix/private.h"
25 #include "xbt/sysdep.h"
26 #include "xbt/log.h"
27 #include "xbt/asserts.h"
28
29 #include "simix/smx_context_private.h"
30
31 /* Damn Ruby. They load their full config.h, which breaks since we also load ours.
32  * So, we undef the offending defines
33  */
34 #undef PACKAGE_VERSION
35 #undef PACKAGE_NAME
36 #undef PACKAGE_TARNAME
37 #undef PACKAGE_STRING
38 #undef PACKAGE_BUGREPORT
39 #undef _GNU_SOURCE
40 #include <ruby.h>
41
42 /* ********************* *
43  * Context related stuff *
44  * ********************* */
45 typedef struct s_smx_ctx_ruby {
46   s_smx_ctx_base_t super;  /* Fields of super implementation */
47   VALUE process;   // The  Ruby Process Instance
48   //...
49 }s_smx_ctx_ruby_t,*smx_ctx_ruby_t;
50 void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory);
51
52 void Init_simgrid_ruby(void); /* Load the bindings */
53 void initRuby(void); // Mandatory to call Ruby methods from C
54
55 /* *********************************************** *
56  * Functions for Ruby Process Management (Up Call) *
57  *                                                 *
58  * Independent Methods                             *
59  * *********************************************** */
60
61 VALUE rb_process_getName( VALUE ruby_process );
62 VALUE rb_process_getID(VALUE ruby_process);
63 VALUE rb_process_getBind(VALUE ruby_class);
64 void  rb_process_setBind(VALUE ruby_class,long bind);
65 VALUE rb_process_isAlive(VALUE ruby_process);
66 void  rb_process_kill_up(VALUE ruby_process);
67 void  rb_process_join( VALUE ruby_process );
68 void  rb_process_unschedule( VALUE ruby_process );
69 void  rb_process_schedule( VALUE ruby_process );
70
71 /* ********************************************** *
72  * Function for Native Process (Bound) Management *
73  *                                                *
74  * Methods Belonging to The MSG Module            *
75  * ********************************************** */
76
77 // ProcessBind Method ; Process Ruby >> Process C
78
79 //friend Method // Not belong to the Class but Called within !!
80 m_process_t rb_process_to_native(VALUE ruby_process);
81 // Binding Process >> Friend Method
82 void rb_process_bind(VALUE ruby_class,m_process_t process);
83 void rb_process_create(VALUE Class,VALUE rb_process,VALUE host);
84 void rb_process_suspend(VALUE Class,VALUE ruby_process);
85 void rb_process_resume(VALUE Class,VALUE ruby_process);
86 // Returns Boolean ( Qtrue / Qfalse )
87 VALUE rb_process_isSuspended(VALUE Class,VALUE ruby_process);
88 void rb_process_kill_down(VALUE Class,VALUE ruby_process);
89 VALUE rb_process_getHost(VALUE Class,VALUE ruby_process);
90 void rb_process_exit(VALUE Class,VALUE ruby_process);
91
92 /* Functions related to hosts */
93 void  rb_host_free(m_host_t ht);
94 VALUE rb_host_get_by_name(VALUE Class, VALUE name);
95 VALUE rb_host_name(VALUE Class,VALUE host);
96 VALUE rb_host_number(VALUE Class);
97 VALUE rb_host_speed(VALUE Class,VALUE host);
98 void  rb_host_set_data(VALUE Class,VALUE host,VALUE data);
99 VALUE rb_host_get_data(VALUE Class,VALUE host);
100 VALUE rb_host_is_avail(VALUE Class,VALUE host);
101 VALUE rb_host_process(VALUE Class,VALUE process);
102
103 /* Functions related to tasks */
104 void rb_task_free(m_task_t tk);
105 // New Method  >>> Data NULL
106 VALUE rb_task_new(VALUE Class, VALUE name,VALUE comp_size,VALUE comm_size);
107 void  rb_task_set_data(VALUE Class,VALUE task,VALUE data); // Data as a String
108 VALUE rb_task_get_data(VALUE Class,VALUE task);
109 VALUE rb_task_comp(VALUE Class,VALUE task); // Get Computation Size
110 VALUE rb_task_name(VALUE Class,VALUE task);
111 VALUE rb_task_execute(VALUE Class,VALUE task);
112 void  rb_task_send(VALUE Class,VALUE task,VALUE mailbox);
113 VALUE rb_task_receive(VALUE Class,VALUE mailbox);// Receive : return a task
114 void  rb_task_receive2(VALUE Class,VALUE task,VALUE mailbox);// Receive Task 2 <<  Not Appreciated
115 VALUE rb_task_sender(VALUE Class,VALUE task);
116 VALUE rb_task_source(VALUE Class,VALUE task);
117 VALUE rb_task_listen(VALUE Class,VALUE task,VALUE alias); //Listen From Alias (=mailbox)
118 VALUE rb_task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); //Listen from Host
119 void rb_task_set_priority(VALUE Class,VALUE task,VALUE priority); // Set Priority
120 void rb_task_cancel(VALUE Class,VALUE task); // Cancel
121
122 /* Upcalls for the application handler */
123 void rb_application_handler_on_start_document(void);
124 void rb_application_handler_on_end_document(void);
125 void rb_application_handler_on_begin_process(void);
126 void rb_application_handler_on_process_arg(void);
127 void rb_application_handler_on_property(void);
128 void rb_application_handler_on_end_process(void);
129
130 #endif /* RB_SG_BINDINGS */