2 * Copyright 2010, The SimGrid Team. All right reserved.
4 * This program is free software; you can redistribute
5 * it and/or modify it under the terms of the license
6 *(GNU LGPL) which comes with this package.
9 #include "msg/private.h" /* s_simdata_process_t */
10 #include "bindings/ruby_bindings.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ruby,bindings,"Ruby Bindings");
15 * Functions for Ruby Process Management (Up Calls)
18 // get Ruby Process Name
19 VALUE rb_process_getName(VALUE ruby_process) {
20 return rb_funcall(ruby_process,rb_intern("getName"),0);
24 VALUE rb_process_getID(VALUE ruby_process) {
25 return rb_funcall(ruby_process,rb_intern("getID"),0);
29 VALUE rb_process_getBind(VALUE ruby_process) {
30 return rb_funcall(ruby_process,rb_intern("getBind"),0);
34 void rb_process_setBind(VALUE ruby_process,long bind) {
35 VALUE r_bind = LONG2FIX(bind);
36 rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind);
40 VALUE rb_process_isAlive(VALUE ruby_process) {
41 return rb_funcall(ruby_process,rb_intern("alive?"),0);
45 void rb_process_kill_up(VALUE ruby_process) {
46 rb_funcall(ruby_process,rb_intern("kill"),0);
50 void rb_process_join( VALUE ruby_process ) {
51 rb_funcall(ruby_process,rb_intern("join"),0);
54 // FIXME: all this calls must be manually inlined I guess
56 void rb_process_unschedule( VALUE ruby_process ) {
57 rb_funcall(ruby_process,rb_intern("unschedule"),0);
61 void rb_process_schedule( VALUE ruby_process ) {
62 rb_funcall(ruby_process,rb_intern("schedule"),0);
65 /***************************************************
66 Function for Native Process ( Bound ) Management
68 Methods Belong to MSG Module
69 ****************************************************/
72 m_process_t rb_process_to_native(VALUE ruby_process) {
73 VALUE id = rb_process_getBind(ruby_process);
75 rb_raise(rb_eRuntimeError,"Process Not Bound >>> id_Bind Null");
78 long l_id= FIX2LONG(id);
79 return (m_process_t)l_id;
83 void rb_process_bind(VALUE ruby_process,m_process_t process) {
84 long bind = (long)(process);
85 rb_process_setBind(ruby_process,bind);
90 void rb_process_suspend(VALUE class,VALUE ruby_process) {
92 m_process_t process = rb_process_to_native(ruby_process);
95 rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process");
99 // Trying to suspend The Process
101 if ( MSG_OK != MSG_process_suspend(process))
102 rb_raise(rb_eRuntimeError,"MSG_process_suspend() failed");
105 void rb_process_resume(VALUE class,VALUE ruby_process) {
106 m_process_t process = rb_process_to_native(ruby_process);
108 rb_raise(rb_eRuntimeError,"Process not Bound...while resuming process");
112 // Trying to resume the process
113 if ( MSG_OK != MSG_process_resume(process))
114 rb_raise(rb_eRuntimeError,"MSG_process_resume() failed");
117 VALUE rb_process_isSuspended(VALUE class,VALUE ruby_process) {
118 m_process_t process = rb_process_to_native(ruby_process);
120 rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended");
123 if(MSG_process_is_suspended(process))
128 void rb_process_kill_down(VALUE class,VALUE ruby_process) {
129 m_process_t process = rb_process_to_native(ruby_process);
132 rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process");
135 // Delete The Global Reference / Ruby Process
136 rb_process_kill_up(ruby_process);
137 // Delete the Native Process
138 MSG_process_kill(process);
141 VALUE rb_process_getHost(VALUE class,VALUE ruby_process) {
142 m_process_t process = rb_process_to_native(ruby_process);
147 rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
151 host = MSG_process_get_host(process);
153 return Data_Wrap_Struct(class, 0, rb_host_free, host);
154 /*if(host->data) printf("Ok\n");
157 rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed");
160 printf("Houuuuuuuuuuuuuuna3!!\n");
161 return Data_Wrap_Struct(class, 0, rb_host_free, host);*/
164 void rb_process_exit(VALUE class,VALUE ruby_process) {
165 m_process_t process = rb_process_to_native(ruby_process);
167 rb_raise(rb_eRuntimeError,"Process Not Bound...while exiting process");
170 SIMIX_context_stop(SIMIX_process_self()->context);