Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding the exchange object

  • Loading branch information...
commit 7900a56ef863608adf1b5f7bd55c7db45707d6f7 1 parent d743c58
@tenderlove authored
View
6 Rakefile
@@ -22,7 +22,7 @@ namespace :build do
end
end
- file EXT => ['vendor/lib/libzmq.a', 'ext/quail/Makefile'] do
+ task :ext => ['vendor/lib/libzmq.a', 'ext/quail/Makefile'] do
Dir.chdir('ext/quail') do
sh 'make'
end
@@ -37,9 +37,9 @@ namespace :build do
end
end
- task :all => [EXT]
end
-task :build => ["build:all"]
+task :build => ["build:ext"]
+Rake::Task[:test].prerequisites << :build
# vim: syntax=Ruby
View
1  ext/quail/native.c
@@ -7,4 +7,5 @@ void Init_native()
rb_const_set(mQuail, rb_intern("GLOBAL"), INT2NUM(CZMQ_SCOPE_GLOBAL));
Init_Quail_Handle(mQuail);
+ Init_Quail_Exchange(mQuail);
}
View
24 ext/quail/quail_exchange.c
@@ -0,0 +1,24 @@
+#include <quail_exchange.h>
+
+static VALUE create_exchange( VALUE self,
+ VALUE rb_h,
+ VALUE name,
+ VALUE scope,
+ VALUE address)
+{
+ void * handle;
+ int eid;
+
+ Data_Get_Struct(rb_h, void, handle);
+ eid = czmq_create_exchange( handle,
+ StringValuePtr(name),
+ NUM2INT(scope),
+ StringValuePtr(address) );
+ return INT2NUM(eid);
+}
+
+void Init_Quail_Exchange(VALUE mQuail)
+{
+ VALUE cQuailHandle = rb_define_class_under(mQuail, "Exchange", rb_cObject);
+ rb_define_private_method(cQuailHandle, "create_exchange", create_exchange, 4);
+}
View
8 ext/quail/quail_exchange.h
@@ -0,0 +1,8 @@
+#ifndef QUAIL_EXCHANGE
+#define QUAIL_EXCHANGE
+
+#include <native.h>
+
+void Init_Quail_Exchange(VALUE mQuail);
+
+#endif
View
1  lib/quail.rb
@@ -1 +1,2 @@
require 'quail/native'
+require 'quail/exchange'
View
12 lib/quail/exchange.rb
@@ -0,0 +1,12 @@
+module Quail
+ class Exchange
+ attr_accessor :eid
+
+ def initialize handle,
+ exchange_name = 'E',
+ scope = Quail::GLOBAL,
+ address = '127.0.0.1:5000'
+ @eid = create_exchange(handle, exchange_name, scope, address)
+ end
+ end
+end
View
12 test/quail/test_exchange.rb
@@ -0,0 +1,12 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
+
+module Quail
+ class TestExchange < Quail::TestCase
+ def test_initialize
+ handle = Quail::Handle.new('localhost')
+ assert_nothing_raised {
+ exchange = Quail::Exchange.new(handle)
+ }
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.