diff options
author | Mark Spruiell <mes@zeroc.com> | 2014-07-21 17:14:45 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2014-07-21 17:14:45 -0700 |
commit | f6871bc421840e0cabff34f2f477a9e53d14f812 (patch) | |
tree | c53a747b0c2a330802ceca7d80da7f5af3b05d4a /rb/src/IceRuby/Connection.cpp | |
parent | Fixed windows compiler error (diff) | |
download | ice-f6871bc421840e0cabff34f2f477a9e53d14f812.tar.bz2 ice-f6871bc421840e0cabff34f2f477a9e53d14f812.tar.xz ice-f6871bc421840e0cabff34f2f477a9e53d14f812.zip |
ICE-5580 - port connection ACM functionality to scripting languages
Diffstat (limited to 'rb/src/IceRuby/Connection.cpp')
-rw-r--r-- | rb/src/IceRuby/Connection.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/rb/src/IceRuby/Connection.cpp b/rb/src/IceRuby/Connection.cpp index 2c8e6de61db..db2fa3d98c8 100644 --- a/rb/src/IceRuby/Connection.cpp +++ b/rb/src/IceRuby/Connection.cpp @@ -9,6 +9,7 @@ #include <Connection.h> #include <Endpoint.h> +#include <Types.h> #include <Util.h> #include <Ice/Object.h> @@ -72,6 +73,90 @@ IceRuby_Connection_flushBatchRequests(VALUE self) extern "C" VALUE +IceRuby_Connection_setACM(VALUE self, VALUE t, VALUE c, VALUE h) +{ + ICE_RUBY_TRY + { + Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); + assert(p); + + IceUtil::Optional<Ice::Int> timeout; + IceUtil::Optional<Ice::ACMClose> close; + IceUtil::Optional<Ice::ACMHeartbeat> heartbeat; + + if(t != Unset) + { + timeout = static_cast<Ice::Int>(getInteger(t)); + } + + if(c != Unset) + { + volatile VALUE type = callRuby(rb_path2class, "Ice::ACMClose"); + if(callRuby(rb_obj_is_instance_of, c, type) != Qtrue) + { + throw RubyException(rb_eTypeError, + "value for 'close' argument must be Unset or an enumerator of Ice.ACMClose"); + } + volatile VALUE closeValue = callRuby(rb_funcall, c, rb_intern("to_i"), 0); + assert(TYPE(closeValue) == T_FIXNUM); + close = static_cast<Ice::ACMClose>(FIX2LONG(closeValue)); + } + + if(h != Unset) + { + volatile VALUE type = callRuby(rb_path2class, "Ice::ACMHeartbeat"); + if(callRuby(rb_obj_is_instance_of, h, type) != Qtrue) + { + throw RubyException(rb_eTypeError, + "value for 'heartbeat' argument must be Unset or an enumerator of Ice.ACMHeartbeat"); + } + volatile VALUE heartbeatValue = callRuby(rb_funcall, h, rb_intern("to_i"), 0); + assert(TYPE(heartbeatValue) == T_FIXNUM); + heartbeat = static_cast<Ice::ACMHeartbeat>(FIX2LONG(heartbeatValue)); + } + + (*p)->setACM(timeout, close, heartbeat); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_Connection_getACM(VALUE self) +{ + ICE_RUBY_TRY + { + Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); + assert(p); + + Ice::ACM acm = (*p)->getACM(); + volatile VALUE type = callRuby(rb_path2class, "Ice::ACM"); + assert(type != Qnil); + volatile VALUE r = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), type); + assert(r != Qnil); + + callRuby(rb_ivar_set, r, rb_intern("@timeout"), LONG2FIX(acm.timeout)); + + type = callRuby(rb_path2class, "Ice::ACMClose"); + assert(type != Qnil); + volatile VALUE c = callRuby(rb_funcall, type, rb_intern("from_int"), 1, LONG2NUM(static_cast<int>(acm.close))); + callRuby(rb_ivar_set, r, rb_intern("@close"), c); + + type = callRuby(rb_path2class, "Ice::ACMHeartbeat"); + assert(type != Qnil); + volatile VALUE h = + callRuby(rb_funcall, type, rb_intern("from_int"), 1, LONG2NUM(static_cast<int>(acm.heartbeat))); + callRuby(rb_ivar_set, r, rb_intern("@heartbeat"), h); + + return r; + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE IceRuby_Connection_type(VALUE self) { ICE_RUBY_TRY @@ -242,6 +327,8 @@ IceRuby::initConnection(VALUE iceModule) // rb_define_method(_connectionClass, "close", CAST_METHOD(IceRuby_Connection_close), 1); rb_define_method(_connectionClass, "flushBatchRequests", CAST_METHOD(IceRuby_Connection_flushBatchRequests), 0); + rb_define_method(_connectionClass, "setACM", CAST_METHOD(IceRuby_Connection_setACM), 3); + rb_define_method(_connectionClass, "getACM", CAST_METHOD(IceRuby_Connection_getACM), 0); rb_define_method(_connectionClass, "type", CAST_METHOD(IceRuby_Connection_type), 0); rb_define_method(_connectionClass, "timeout", CAST_METHOD(IceRuby_Connection_timeout), 0); rb_define_method(_connectionClass, "getInfo", CAST_METHOD(IceRuby_Connection_getInfo), 0); |