Adds Lorcon::Device.write() for compatibility with Lorcon1

git-svn-id: file:///home/svn/framework3/trunk@7233 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2009-10-23 14:40:47 +00:00
parent 07653cb452
commit 070f85d6b5
2 changed files with 21 additions and 5 deletions

View File

@ -457,12 +457,15 @@ static VALUE Lorcon_inject_packet(VALUE self, VALUE packet) {
lorcon_packet_t *pack = NULL;
int ret;
if (rb_obj_is_kind_of(packet, cPacket) == 0) {
rb_raise(rb_eTypeError, "wrong type %s expected %s",
rb_class2name(packet), rb_class2name(cPacket));
rb_raise(rb_eTypeError, "wrong type expected %s", rb_class2name(cPacket));
return Qnil;
}
return Qnil;
Data_Get_Struct(self, struct rldev, rld);
Data_Get_Struct(packet, struct rlpack, rlp);
@ -477,6 +480,21 @@ static VALUE Lorcon_inject_packet(VALUE self, VALUE packet) {
return INT2FIX(ret);
}
static VALUE Lorcon_write_raw(VALUE self, VALUE rpacket) {
struct rldev *rld;
int ret;
Data_Get_Struct(self, struct rldev, rld);
if(TYPE(rpacket) != T_STRING) {
rb_raise(rb_eArgError, "packet data must be a string");
return Qnil;
}
ret = lorcon_send_bytes(rld->context, RSTRING_LEN(rpacket), RSTRING_PTR(rpacket));
return INT2FIX(ret);
}
static VALUE Lorcon_set_filter(VALUE self, VALUE filter) {
struct rldev *rld;
int ret;
@ -597,9 +615,8 @@ void Init_Lorcon2() {
rb_define_method(cDevice, "loop", Lorcon_capture_loop, -1);
rb_define_method(cDevice, "each", Lorcon_capture_loop, -1);
rb_define_method(cDevice, "each_packet", Lorcon_capture_loop, -1);
rb_define_method(cDevice, "write", Lorcon_write_raw, 1);
rb_define_method(cDevice, "inject", Lorcon_inject_packet, 1);
rb_define_module_function(mLorcon, "drivers", Lorcon_list_drivers, 0);
rb_define_module_function(mLorcon, "version", Lorcon_get_version, 0);
rb_define_module_function(mLorcon, "find_driver", Lorcon_find_driver, 1);

View File

@ -8,7 +8,6 @@
#include <sys/socket.h>
#include <lorcon2/lorcon.h>
#include <lorcon2/lorcon_packet.h>
struct rldev {
struct lorcon *context;