1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg/private.h" /* s_simdata_process_t */
8 #include "bindings/ruby_bindings.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ruby,bindings,"Ruby Bindings");
13 * Functions for Ruby Process Management (Up Calls)
16 // get Ruby Process Name
17 VALUE rb_process_getName(VALUE ruby_process) {
18 return rb_funcall(ruby_process,rb_intern("getName"),0);
22 VALUE rb_process_getID(VALUE ruby_process) {
23 return rb_funcall(ruby_process,rb_intern("getID"),0);
27 VALUE rb_process_getBind(VALUE ruby_process) {
28 return rb_funcall(ruby_process,rb_intern("getBind"),0);
32 void rb_process_setBind(VALUE ruby_process,long bind) {
33 VALUE r_bind = LONG2FIX(bind);
34 rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind);
38 VALUE rb_process_isAlive(VALUE ruby_process) {
39 return rb_funcall(ruby_process,rb_intern("alive?"),0);
43 void rb_process_kill_up(VALUE ruby_process) {
44 rb_funcall(ruby_process,rb_intern("kill"),0);
48 void rb_process_join( VALUE ruby_process ) {
49 rb_funcall(ruby_process,rb_intern("join"),0);
52 // FIXME: all this calls must be manually inlined I guess
54 void rb_process_unschedule( VALUE ruby_process ) {
55 rb_funcall(ruby_process,rb_intern("unschedule"),0);
59 void rb_process_schedule( VALUE ruby_process ) {
60 rb_funcall(ruby_process,rb_intern("schedule"),0);
63 /***************************************************
64 Function for Native Process ( Bound ) Management
66 Methods Belong to MSG Module
67 ****************************************************/
70 m_process_t rb_process_to_native(VALUE ruby_process) {
71 VALUE id = rb_process_getBind(ruby_process);
73 rb_raise(rb_eRuntimeError,"Process Not Bound >>> id_Bind Null");
76 long l_id= FIX2LONG(id);
77 return (m_process_t)l_id;
81 void rb_process_bind(VALUE ruby_process,m_process_t process) {
82 long bind = (long)(process);
83 rb_process_setBind(ruby_process,bind);
88 void rb_process_suspend(VALUE class,VALUE ruby_process) {
90 m_process_t process = rb_process_to_native(ruby_process);
93 rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process");
97 // Trying to suspend The Process
99 if ( MSG_OK != MSG_process_suspend(process))
100 rb_raise(rb_eRuntimeError,"MSG_process_suspend() failed");
103 void rb_process_resume(VALUE class,VALUE ruby_process) {
104 m_process_t process = rb_process_to_native(ruby_process);
106 rb_raise(rb_eRuntimeError,"Process not Bound...while resuming process");
110 // Trying to resume the process
111 if ( MSG_OK != MSG_process_resume(process))
112 rb_raise(rb_eRuntimeError,"MSG_process_resume() failed");
115 VALUE rb_process_isSuspended(VALUE class,VALUE ruby_process) {
116 m_process_t process = rb_process_to_native(ruby_process);
118 rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended");
121 if(MSG_process_is_suspended(process))
126 void rb_process_kill_down(VALUE class,VALUE ruby_process) {
127 m_process_t process = rb_process_to_native(ruby_process);
130 rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process");
133 // Delete The Global Reference / Ruby Process
134 rb_process_kill_up(ruby_process);
135 // Delete the Native Process
136 MSG_process_kill(process);
139 VALUE rb_process_getHost(VALUE class,VALUE ruby_process) {
140 m_process_t process = rb_process_to_native(ruby_process);
145 rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
149 host = MSG_process_get_host(process);
151 return Data_Wrap_Struct(class, 0, rb_host_free, host);
152 /*if(host->data) printf("Ok\n");
155 rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed");
158 printf("Houuuuuuuuuuuuuuna3!!\n");
159 return Data_Wrap_Struct(class, 0, rb_host_free, host);*/
162 void rb_process_exit(VALUE class,VALUE ruby_process) {
163 m_process_t process = rb_process_to_native(ruby_process);
165 rb_raise(rb_eRuntimeError,"Process Not Bound...while exiting process");
168 SIMIX_context_stop(SIMIX_process_self()->context);