1 /* SimGrid -- Ruby bindings */
3 /* Copyright (c) 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #ifndef RB_SG_BINDINGS
11 #define RB_SG_BINDINGS
13 * There is 4 sections in this file:
14 * - Header loading (ruby makes it quite difficult, damn it)
15 * - definitions of ruby contextes for use in simix
16 * - Functions to Manage The Ruby Process (named Up Calls)
17 * - Functions to Manage The Native Process Simulation Bound (named Down Calls)
21 #include "msg/datatypes.h"
23 #include "surf/surfxml_parse.h"
24 #include "simix/simix.h"
25 #include "simix/private.h"
26 #include "xbt/sysdep.h"
28 #include "xbt/asserts.h"
30 #include "simix/smx_context_private.h"
32 /* Damn Ruby. They load their full config.h, which breaks since we also load ours.
33 * So, we undef the offending defines
35 #undef PACKAGE_VERSION
37 #undef PACKAGE_TARNAME
39 #undef PACKAGE_BUGREPORT
43 /* ********************* *
44 * Context related stuff *
45 * ********************* */
46 typedef struct s_smx_ctx_ruby {
47 s_smx_ctx_base_t super; /* Fields of super implementation */
48 VALUE process; // The Ruby Process Instance
50 }s_smx_ctx_ruby_t,*smx_ctx_ruby_t;
51 void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory);
53 void Init_libsimgrid(void); /* Load the bindings */
54 void initRuby(void); // Mandatory to call Ruby methods from C
56 /* *********************************************** *
57 * Functions for Ruby Process Management (Up Call) *
59 * Independent Methods *
60 * *********************************************** */
62 VALUE rb_process_getName( VALUE ruby_process );
63 VALUE rb_process_getID(VALUE ruby_process);
64 VALUE rb_process_getBind(VALUE ruby_class);
65 void rb_process_setBind(VALUE ruby_class,long bind);
66 VALUE rb_process_isAlive(VALUE ruby_process);
67 void rb_process_kill_up(VALUE ruby_process);
68 void rb_process_join( VALUE ruby_process );
69 void rb_process_unschedule( VALUE ruby_process );
70 void rb_process_schedule( VALUE ruby_process );
72 /* ********************************************** *
73 * Function for Native Process (Bound) Management *
75 * Methods Belonging to The MSG Module *
76 * ********************************************** */
78 // ProcessBind Method ; Process Ruby >> Process C
80 //friend Method // Not belong to the Class but Called within !!
81 m_process_t rb_process_to_native(VALUE ruby_process);
82 // Binding Process >> Friend Method
83 void rb_process_bind(VALUE ruby_class,m_process_t process);
84 void rb_process_create(VALUE Class,VALUE rb_process,VALUE host);
85 void rb_process_suspend(VALUE Class,VALUE ruby_process);
86 void rb_process_resume(VALUE Class,VALUE ruby_process);
87 // Returns Boolean ( Qtrue / Qfalse )
88 VALUE rb_process_isSuspended(VALUE Class,VALUE ruby_process);
89 void rb_process_kill_down(VALUE Class,VALUE ruby_process);
90 VALUE rb_process_getHost(VALUE Class,VALUE ruby_process);
91 void rb_process_exit(VALUE Class,VALUE ruby_process);
93 /* Functions related to hosts */
94 void rb_host_free(m_host_t ht);
95 VALUE rb_host_get_by_name(VALUE Class, VALUE name);
96 VALUE rb_host_name(VALUE Class,VALUE host);
97 VALUE rb_host_number(VALUE Class);
98 VALUE rb_host_speed(VALUE Class,VALUE host);
99 void rb_host_set_data(VALUE Class,VALUE host,VALUE data);
100 VALUE rb_host_get_data(VALUE Class,VALUE host);
101 VALUE rb_host_is_avail(VALUE Class,VALUE host);
102 VALUE rb_host_process(VALUE Class,VALUE process);
103 VALUE rb_host_get_all_hosts(VALUE Class);
105 /* Functions related to tasks */
107 typedef struct ruby_data {
108 void *ruby_task; // Pointer to send the ruby_task
109 void *user_data; // Pointer on the user data
110 }s_ruby_data_t,*rb_data_t;
112 void rb_task_free(m_task_t tk);
113 VALUE rb_task_new(VALUE Class, VALUE name,VALUE comp_size,VALUE comm_size);
114 VALUE rb_task_comp(VALUE Class,VALUE task); // Get Computation Size
115 VALUE rb_task_name(VALUE Class,VALUE task);
116 VALUE rb_task_execute(VALUE Class,VALUE task);
117 void rb_task_send(VALUE Class,VALUE task,VALUE mailbox);
118 VALUE rb_task_receive(VALUE Class,VALUE mailbox);// Receive : return a task
119 void rb_task_receive2(VALUE Class,VALUE task,VALUE mailbox);// Receive Task 2 << Not Appreciated
120 VALUE rb_task_sender(VALUE Class,VALUE task);
121 VALUE rb_task_source(VALUE Class,VALUE task);
122 VALUE rb_task_listen(VALUE Class,VALUE task,VALUE alias); //Listen From Alias (=mailbox)
123 VALUE rb_task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); //Listen from Host
124 void rb_task_set_priority(VALUE Class,VALUE task,VALUE priority); // Set Priority
125 void rb_task_cancel(VALUE Class,VALUE task); // Cancel
126 VALUE rb_task_has_data(VALUE Class,VALUE task); // check if the task contains a data
127 VALUE rb_task_get_data(VALUE Class,VALUE task); // get data
128 void rb_task_set_data(VALUE Class,VALUE task,VALUE data); // set data
130 /* Upcalls for the application handler */
131 void rb_application_handler_on_start_document(void);
132 void rb_application_handler_on_end_document(void);
133 void rb_application_handler_on_begin_process(void);
134 void rb_application_handler_on_process_arg(void);
135 void rb_application_handler_on_property(void);
136 void rb_application_handler_on_end_process(void);
138 #endif /* RB_SG_BINDINGS */