diff options
Diffstat (limited to 'ruby/src/IceRuby/Connection.cpp')
-rw-r--r-- | ruby/src/IceRuby/Connection.cpp | 140 |
1 files changed, 77 insertions, 63 deletions
diff --git a/ruby/src/IceRuby/Connection.cpp b/ruby/src/IceRuby/Connection.cpp index 2c32f9fab70..4f6b615ffc2 100644 --- a/ruby/src/IceRuby/Connection.cpp +++ b/ruby/src/IceRuby/Connection.cpp @@ -25,7 +25,6 @@ static VALUE _tcpConnectionInfoClass; static VALUE _udpConnectionInfoClass; static VALUE _wsConnectionInfoClass; static VALUE _sslConnectionInfoClass; -static VALUE _wssConnectionInfoClass; // ********************************************************************** // Connection @@ -47,14 +46,47 @@ IceRuby::createConnection(const Ice::ConnectionPtr& p) extern "C" VALUE -IceRuby_Connection_close(VALUE self, VALUE b) +IceRuby_Connection_close(VALUE self, VALUE mode) { ICE_RUBY_TRY { Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); assert(p); - (*p)->close(RTEST(b)); + volatile VALUE type = callRuby(rb_path2class, "Ice::ConnectionClose"); + if(callRuby(rb_obj_is_instance_of, mode, type) != Qtrue) + { + throw RubyException(rb_eTypeError, + "value for 'mode' argument must be an enumerator of Ice::ConnectionClose"); + } + volatile VALUE modeValue = callRuby(rb_funcall, mode, rb_intern("to_i"), 0); + assert(TYPE(modeValue) == T_FIXNUM); + Ice::ConnectionClose cc = static_cast<Ice::ConnectionClose>(FIX2LONG(modeValue)); + (*p)->close(cc); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_Connection_flushBatchRequests(VALUE self, VALUE compress) +{ + ICE_RUBY_TRY + { + Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); + assert(p); + + volatile VALUE type = callRuby(rb_path2class, "Ice::CompressBatch"); + if(callRuby(rb_obj_is_instance_of, compress, type) != Qtrue) + { + throw RubyException(rb_eTypeError, + "value for 'compress' argument must be an enumerator of Ice::CompressBatch"); + } + volatile VALUE compressValue = callRuby(rb_funcall, compress, rb_intern("to_i"), 0); + assert(TYPE(compressValue) == T_FIXNUM); + Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(FIX2LONG(compressValue)); + (*p)->flushBatchRequests(cb); } ICE_RUBY_CATCH return Qnil; @@ -62,14 +94,14 @@ IceRuby_Connection_close(VALUE self, VALUE b) extern "C" VALUE -IceRuby_Connection_flushBatchRequests(VALUE self) +IceRuby_Connection_heartbeat(VALUE self) { ICE_RUBY_TRY { Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); assert(p); - (*p)->flushBatchRequests(); + (*p)->heartbeat(); } ICE_RUBY_CATCH return Qnil; @@ -222,6 +254,7 @@ IceRuby_Connection_getEndpoint(VALUE self) ICE_RUBY_CATCH return Qnil; } + extern "C" VALUE IceRuby_Connection_setBufferSize(VALUE self, VALUE r, VALUE s) @@ -242,6 +275,21 @@ IceRuby_Connection_setBufferSize(VALUE self, VALUE r, VALUE s) extern "C" VALUE +IceRuby_Connection_throwException(VALUE self) +{ + ICE_RUBY_TRY + { + Ice::ConnectionPtr* p = reinterpret_cast<Ice::ConnectionPtr*>(DATA_PTR(self)); + assert(p); + + (*p)->throwException(); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE IceRuby_Connection_toString(VALUE self) { ICE_RUBY_TRY @@ -293,17 +341,17 @@ IceRuby_ConnectionInfo_free(Ice::ConnectionInfoPtr* p) VALUE IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) { + if(!p) + { + return Qnil; + } + VALUE info; if(Ice::WSConnectionInfoPtr::dynamicCast(p)) { info = Data_Wrap_Struct(_wsConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); Ice::WSConnectionInfoPtr ws = Ice::WSConnectionInfoPtr::dynamicCast(p); - rb_ivar_set(info, rb_intern("@localAddress"), createString(ws->localAddress)); - rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(ws->localPort)); - rb_ivar_set(info, rb_intern("@remoteAddress"), createString(ws->remoteAddress)); - rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(ws->remotePort)); - volatile VALUE result = callRuby(rb_hash_new); for(Ice::HeaderDict::const_iterator q = ws->headers.begin(); q != ws->headers.end(); ++q) { @@ -318,54 +366,24 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) info = Data_Wrap_Struct(_tcpConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); Ice::TCPConnectionInfoPtr tcp = Ice::TCPConnectionInfoPtr::dynamicCast(p); - rb_ivar_set(info, rb_intern("@localAddress"), createString(tcp->localAddress)); - rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(tcp->localPort)); - rb_ivar_set(info, rb_intern("@remoteAddress"), createString(tcp->remoteAddress)); - rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(tcp->remotePort)); + rb_ivar_set(info, rb_intern("@rcvSize"), INT2FIX(tcp->rcvSize)); + rb_ivar_set(info, rb_intern("@sndSize"), INT2FIX(tcp->sndSize)); } else if(Ice::UDPConnectionInfoPtr::dynamicCast(p)) { info = Data_Wrap_Struct(_udpConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); Ice::UDPConnectionInfoPtr udp = Ice::UDPConnectionInfoPtr::dynamicCast(p); - rb_ivar_set(info, rb_intern("@localAddress"), createString(udp->localAddress)); - rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(udp->localPort)); - rb_ivar_set(info, rb_intern("@remoteAddress"), createString(udp->remoteAddress)); - rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(udp->remotePort)); rb_ivar_set(info, rb_intern("@mcastAddress"), createString(udp->mcastAddress)); rb_ivar_set(info, rb_intern("@mcastPort"), INT2FIX(udp->mcastPort)); - } - else if(IceSSL::WSSConnectionInfoPtr::dynamicCast(p)) - { - info = Data_Wrap_Struct(_wssConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); - - IceSSL::WSSConnectionInfoPtr wss = IceSSL::WSSConnectionInfoPtr::dynamicCast(p); - rb_ivar_set(info, rb_intern("@localAddress"), createString(wss->localAddress)); - rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(wss->localPort)); - rb_ivar_set(info, rb_intern("@remoteAddress"), createString(wss->remoteAddress)); - rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(wss->remotePort)); - rb_ivar_set(info, rb_intern("@cipher"), createString(wss->cipher)); - rb_ivar_set(info, rb_intern("@certs"), stringSeqToArray(wss->certs)); - rb_ivar_set(info, rb_intern("@verified"), wss->verified ? Qtrue : Qfalse); - - volatile VALUE result = callRuby(rb_hash_new); - for(Ice::HeaderDict::const_iterator q = wss->headers.begin(); q != wss->headers.end(); ++q) - { - volatile VALUE key = createString(q->first); - volatile VALUE value = createString(q->second); - callRuby(rb_hash_aset, result, key, value); - } - rb_ivar_set(info, rb_intern("@headers"), result); + rb_ivar_set(info, rb_intern("@rcvSize"), INT2FIX(udp->rcvSize)); + rb_ivar_set(info, rb_intern("@sndSize"), INT2FIX(udp->sndSize)); } else if(IceSSL::ConnectionInfoPtr::dynamicCast(p)) { info = Data_Wrap_Struct(_sslConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); IceSSL::ConnectionInfoPtr ssl = IceSSL::ConnectionInfoPtr::dynamicCast(p); - rb_ivar_set(info, rb_intern("@localAddress"), createString(ssl->localAddress)); - rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(ssl->localPort)); - rb_ivar_set(info, rb_intern("@remoteAddress"), createString(ssl->remoteAddress)); - rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(ssl->remotePort)); rb_ivar_set(info, rb_intern("@cipher"), createString(ssl->cipher)); rb_ivar_set(info, rb_intern("@certs"), stringSeqToArray(ssl->certs)); rb_ivar_set(info, rb_intern("@verified"), ssl->verified ? Qtrue : Qfalse); @@ -374,20 +392,24 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p) { info = Data_Wrap_Struct(_ipConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + } + else + { + info = Data_Wrap_Struct(_connectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); + } + + if(Ice::IPConnectionInfoPtr::dynamicCast(p)) + { Ice::IPConnectionInfoPtr ip = Ice::IPConnectionInfoPtr::dynamicCast(p); rb_ivar_set(info, rb_intern("@localAddress"), createString(ip->localAddress)); rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(ip->localPort)); rb_ivar_set(info, rb_intern("@remoteAddress"), createString(ip->remoteAddress)); rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(ip->remotePort)); } - else - { - info = Data_Wrap_Struct(_connectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p)); - } + + rb_ivar_set(info, rb_intern("@underlying"), createConnectionInfo(p->underlying)); rb_ivar_set(info, rb_intern("@incoming"), p->incoming ? Qtrue : Qfalse); rb_ivar_set(info, rb_intern("@adapterName"), createString(p->adapterName)); - rb_ivar_set(info, rb_intern("@rcvSize"), INT2FIX(p->rcvSize)); - rb_ivar_set(info, rb_intern("@sndSize"), INT2FIX(p->sndSize)); return info; } @@ -403,7 +425,8 @@ IceRuby::initConnection(VALUE iceModule) // Instance methods. // 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, "flushBatchRequests", CAST_METHOD(IceRuby_Connection_flushBatchRequests), 1); + rb_define_method(_connectionClass, "heartbeat", CAST_METHOD(IceRuby_Connection_heartbeat), 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); @@ -411,6 +434,7 @@ IceRuby::initConnection(VALUE iceModule) rb_define_method(_connectionClass, "getInfo", CAST_METHOD(IceRuby_Connection_getInfo), 0); rb_define_method(_connectionClass, "getEndpoint", CAST_METHOD(IceRuby_Connection_getEndpoint), 0); rb_define_method(_connectionClass, "setBufferSize", CAST_METHOD(IceRuby_Connection_setBufferSize), 2); + rb_define_method(_connectionClass, "throwException", CAST_METHOD(IceRuby_Connection_throwException), 0); rb_define_method(_connectionClass, "toString", CAST_METHOD(IceRuby_Connection_toString), 0); rb_define_method(_connectionClass, "to_s", CAST_METHOD(IceRuby_Connection_toString), 0); rb_define_method(_connectionClass, "inspect", CAST_METHOD(IceRuby_Connection_toString), 0); @@ -462,7 +486,7 @@ IceRuby::initConnection(VALUE iceModule) // // WSConnectionInfo // - _wsConnectionInfoClass = rb_define_class_under(iceModule, "WSConnectionInfo", _ipConnectionInfoClass); + _wsConnectionInfoClass = rb_define_class_under(iceModule, "WSConnectionInfo", _connectionInfoClass); // // Instance members. @@ -472,7 +496,7 @@ IceRuby::initConnection(VALUE iceModule) // // SSLConnectionInfo // - _sslConnectionInfoClass = rb_define_class_under(iceModule, "SSLConnectionInfo", _ipConnectionInfoClass); + _sslConnectionInfoClass = rb_define_class_under(iceModule, "SSLConnectionInfo", _connectionInfoClass); // // Instance members. @@ -480,14 +504,4 @@ IceRuby::initConnection(VALUE iceModule) rb_define_attr(_wsConnectionInfoClass, "cipher", 1, 0); rb_define_attr(_wsConnectionInfoClass, "certs", 1, 0); rb_define_attr(_wsConnectionInfoClass, "verified", 1, 0); - - // - // WSSConnectionInfo - // - _wssConnectionInfoClass = rb_define_class_under(iceModule, "WSSConnectionInfo", _sslConnectionInfoClass); - - // - // Instance members. - // - rb_define_attr(_wssConnectionInfoClass, "headers", 1, 0); } |