summaryrefslogtreecommitdiff
path: root/ruby/src/IceRuby/Communicator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ruby/src/IceRuby/Communicator.cpp')
-rw-r--r--ruby/src/IceRuby/Communicator.cpp104
1 files changed, 81 insertions, 23 deletions
diff --git a/ruby/src/IceRuby/Communicator.cpp b/ruby/src/IceRuby/Communicator.cpp
index 6bd17c05426..19d39267e44 100644
--- a/ruby/src/IceRuby/Communicator.cpp
+++ b/ruby/src/IceRuby/Communicator.cpp
@@ -10,11 +10,12 @@
#include <Communicator.h>
#include <ImplicitContext.h>
#include <Logger.h>
-#include <ObjectFactory.h>
#include <Properties.h>
#include <Proxy.h>
#include <Types.h>
#include <Util.h>
+#include <ValueFactoryManager.h>
+#include <IceUtil/DisableWarnings.h>
#include <Ice/Communicator.h>
#include <Ice/Initialize.h>
#include <Ice/Locator.h>
@@ -37,9 +38,9 @@ IceRuby_Communicator_mark(Ice::CommunicatorPtr* p)
assert(p);
try
{
- ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast((*p)->findObjectFactory(""));
- assert(pof);
- pof->mark();
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast((*p)->getValueFactoryManager());
+ assert(vfm);
+ vfm->markSelf();
}
catch(const Ice::CommunicatorDestroyedException&)
{
@@ -128,6 +129,7 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
seq.insert(seq.begin(), getString(progName));
data.compactIdResolver = new IdResolver;
+ data.valueFactoryManager = new ValueFactoryManager;
if(hasArgs)
{
@@ -171,6 +173,17 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
communicator = Ice::initialize(data);
}
}
+ catch(const Ice::LocalException& ex)
+ {
+ cerr << ex << endl;
+ for(i = 0; i < ac + 1; ++i)
+ {
+ free(av[i]);
+ }
+ delete[] av;
+
+ throw;
+ }
catch(...)
{
for(i = 0; i < ac + 1; ++i)
@@ -181,7 +194,7 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
throw;
}
-
+
//
// Replace the contents of the given argument list with the filtered arguments.
//
@@ -205,9 +218,6 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
}
delete[] av;
- ObjectFactoryPtr factory = new ObjectFactory;
- communicator->addObjectFactory(factory, "");
-
VALUE result = Data_Wrap_Struct(_communicatorClass, IceRuby_Communicator_mark,
IceRuby_Communicator_free, new Ice::CommunicatorPtr(communicator));
@@ -240,12 +250,27 @@ IceRuby_stringToIdentity(VALUE self, VALUE str)
extern "C"
VALUE
-IceRuby_identityToString(VALUE self, VALUE id)
+IceRuby_identityToString(int argc, VALUE* argv, VALUE self)
{
ICE_RUBY_TRY
{
- Ice::Identity ident = getIdentity(id);
- string str = Ice::identityToString(ident);
+ if(argc < 1 || argc > 2)
+ {
+ throw RubyException(rb_eArgError, "wrong number of arguments");
+ }
+
+ Ice::Identity ident = getIdentity(argv[0]);
+
+
+ Ice::ToStringMode toStringMode = Ice::Unicode;
+ if(argc == 2)
+ {
+ volatile VALUE modeValue = callRuby(rb_funcall, argv[1], rb_intern("to_i"), 0);
+ assert(TYPE(modeValue) == T_FIXNUM);
+ toStringMode = static_cast<Ice::ToStringMode>(FIX2LONG(modeValue));
+ }
+
+ string str = Ice::identityToString(ident, toStringMode);
return createString(str);
}
ICE_RUBY_CATCH
@@ -256,12 +281,19 @@ extern "C"
VALUE
IceRuby_Communicator_destroy(VALUE self)
{
+ Ice::CommunicatorPtr p = getCommunicator(self);
+
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast(p->getValueFactoryManager());
+ assert(vfm);
+
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
p->destroy();
}
ICE_RUBY_CATCH
+
+ vfm->destroy();
+
return Qnil;
}
@@ -371,7 +403,7 @@ IceRuby_Communicator_proxyToProperty(VALUE self, VALUE obj, VALUE str)
volatile VALUE value = createString(q->second);
callRuby(rb_hash_aset, result, key, value);
}
- return result;
+ return result;
}
ICE_RUBY_CATCH
return Qnil;
@@ -414,10 +446,10 @@ IceRuby_Communicator_addObjectFactory(VALUE self, VALUE factory, VALUE id)
ICE_RUBY_TRY
{
Ice::CommunicatorPtr p = getCommunicator(self);
- ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast(p->findObjectFactory(""));
- assert(pof);
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast(p->getValueFactoryManager());
+ assert(vfm);
string idstr = getString(id);
- pof->add(factory, idstr);
+ vfm->addObjectFactory(factory, idstr);
}
ICE_RUBY_CATCH
return Qnil;
@@ -430,10 +462,25 @@ IceRuby_Communicator_findObjectFactory(VALUE self, VALUE id)
ICE_RUBY_TRY
{
Ice::CommunicatorPtr p = getCommunicator(self);
- ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast(p->findObjectFactory(""));
- assert(pof);
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast(p->getValueFactoryManager());
+ assert(vfm);
string idstr = getString(id);
- return pof->find(idstr);
+ return vfm->findObjectFactory(idstr);
+ }
+ ICE_RUBY_CATCH
+ return Qnil;
+}
+
+extern "C"
+VALUE
+IceRuby_Communicator_getValueFactoryManager(VALUE self)
+{
+ ICE_RUBY_TRY
+ {
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ ValueFactoryManagerPtr vfm = ValueFactoryManagerPtr::dynamicCast(p->getValueFactoryManager());
+ assert(vfm);
+ return vfm->getObject();
}
ICE_RUBY_CATCH
return Qnil;
@@ -566,12 +613,22 @@ IceRuby_Communicator_setDefaultLocator(VALUE self, VALUE locator)
extern "C"
VALUE
-IceRuby_Communicator_flushBatchRequests(VALUE self)
+IceRuby_Communicator_flushBatchRequests(VALUE self, VALUE compress)
{
ICE_RUBY_TRY
{
Ice::CommunicatorPtr p = getCommunicator(self);
- p->flushBatchRequests();
+
+ 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;
@@ -581,7 +638,7 @@ void
IceRuby::initCommunicator(VALUE iceModule)
{
rb_define_module_function(iceModule, "initialize", CAST_METHOD(IceRuby_initialize), -1);
- rb_define_module_function(iceModule, "identityToString", CAST_METHOD(IceRuby_identityToString), 1);
+ rb_define_module_function(iceModule, "identityToString", CAST_METHOD(IceRuby_identityToString), -1);
rb_define_module_function(iceModule, "stringToIdentity", CAST_METHOD(IceRuby_stringToIdentity), 1);
_communicatorClass = rb_define_class_under(iceModule, "CommunicatorI", rb_cObject);
@@ -596,6 +653,7 @@ IceRuby::initCommunicator(VALUE iceModule)
rb_define_method(_communicatorClass, "identityToString", CAST_METHOD(IceRuby_Communicator_identityToString), 1);
rb_define_method(_communicatorClass, "addObjectFactory", CAST_METHOD(IceRuby_Communicator_addObjectFactory), 2);
rb_define_method(_communicatorClass, "findObjectFactory", CAST_METHOD(IceRuby_Communicator_findObjectFactory), 1);
+ rb_define_method(_communicatorClass, "getValueFactoryManager", CAST_METHOD(IceRuby_Communicator_getValueFactoryManager), 0);
rb_define_method(_communicatorClass, "getImplicitContext", CAST_METHOD(IceRuby_Communicator_getImplicitContext), 0);
rb_define_method(_communicatorClass, "getProperties", CAST_METHOD(IceRuby_Communicator_getProperties), 0);
rb_define_method(_communicatorClass, "getLogger", CAST_METHOD(IceRuby_Communicator_getLogger), 0);
@@ -603,7 +661,7 @@ IceRuby::initCommunicator(VALUE iceModule)
rb_define_method(_communicatorClass, "setDefaultRouter", CAST_METHOD(IceRuby_Communicator_setDefaultRouter), 1);
rb_define_method(_communicatorClass, "getDefaultLocator", CAST_METHOD(IceRuby_Communicator_getDefaultLocator), 0);
rb_define_method(_communicatorClass, "setDefaultLocator", CAST_METHOD(IceRuby_Communicator_setDefaultLocator), 1);
- rb_define_method(_communicatorClass, "flushBatchRequests", CAST_METHOD(IceRuby_Communicator_flushBatchRequests), 0);
+ rb_define_method(_communicatorClass, "flushBatchRequests", CAST_METHOD(IceRuby_Communicator_flushBatchRequests), 1);
}
Ice::CommunicatorPtr