Skip to content

Instantly share code, notes, and snippets.

@paukul
Created March 16, 2010 23:11
Show Gist options
  • Save paukul/334651 to your computer and use it in GitHub Desktop.
Save paukul/334651 to your computer and use it in GitHub Desktop.
#include "mod.h"
VALUE IntruderMod = Qnil;
extern VALUE IntruderModule;
extern VALUE IntruderTerm;
VALUE intruder_mod_init(VALUE self, VALUE modname, VALUE node){
rb_iv_set(self, "@node", node);
rb_iv_set(self, "@modname", modname);
return self;
}
VALUE intruder_mod_alloc(VALUE class){
INTRUDER_MOD *im = (INTRUDER_MOD*)malloc(sizeof(INTRUDER_MOD));
VALUE obj;
obj = Data_Wrap_Struct(class, 0, free, im);
return obj;
}
VALUE private_intruder_mod_rpc(VALUE self, VALUE args){
VALUE response;
VALUE fun = rb_ary_shift(args);
VALUE params = rb_ary_shift(args);
INTRUDER_NODE *inode;
INTRUDER_TERM *iterm;
Data_Get_Struct(params, INTRUDER_TERM, iterm);
char *mod = RSTRING_PTR(rb_iv_get(self, "@modname"));
Data_Get_Struct(rb_iv_get(self, "@node"), INTRUDER_NODE, inode);
ETERM *tuplep;
DEBUG("\nrpc call to %s:%s\n", mod, RSTRING_PTR(fun));
tuplep = erl_rpc(inode->fd, mod, RSTRING_PTR(fun), iterm->eterm);
if(tuplep == NULL)
raise_rException_for_erl_errno();
response = rb_value_from_eterm(tuplep);
return response;
}
void Init_intruder_mod(){
IntruderMod = rb_define_class_under(IntruderModule, "Mod", rb_cObject);
/* class methods */
rb_define_alloc_func(IntruderMod, intruder_mod_alloc);
/* instance methods */
rb_define_method(IntruderMod, "initialize", intruder_mod_init, 2);
rb_define_private_method(IntruderMod, "rpc", private_intruder_mod_rpc, -2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment