summaryrefslogtreecommitdiff
path: root/rb/src/IceRuby/Communicator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rb/src/IceRuby/Communicator.cpp')
-rw-r--r--rb/src/IceRuby/Communicator.cpp518
1 files changed, 259 insertions, 259 deletions
diff --git a/rb/src/IceRuby/Communicator.cpp b/rb/src/IceRuby/Communicator.cpp
index 8932525fe6b..7b0c56d04fb 100644
--- a/rb/src/IceRuby/Communicator.cpp
+++ b/rb/src/IceRuby/Communicator.cpp
@@ -36,13 +36,13 @@ IceRuby_Communicator_mark(Ice::CommunicatorPtr* p)
assert(p);
try
{
- ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast((*p)->findObjectFactory(""));
- assert(pof);
- pof->mark();
+ ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast((*p)->findObjectFactory(""));
+ assert(pof);
+ pof->mark();
}
catch(const Ice::CommunicatorDestroyedException&)
{
- // Ignore. This is expected.
+ // Ignore. This is expected.
}
}
@@ -60,156 +60,156 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
{
ICE_RUBY_TRY
{
- volatile VALUE initDataCls = callRuby(rb_path2class, "Ice::InitializationData");
- volatile VALUE args = Qnil, initData = Qnil;
- if(argc == 1)
- {
- if(isArray(argv[0]))
- {
- args = argv[0];
- }
- else if(callRuby(rb_obj_is_instance_of, argv[0], initDataCls) == Qtrue)
- {
- initData = argv[0];
- }
- else
- {
- throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
- }
- }
- else if(argc == 2)
- {
- if(!isArray(argv[0]) || callRuby(rb_obj_is_instance_of, argv[1], initDataCls) == Qfalse)
- {
- throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
- }
- args = argv[0];
- initData = argv[1];
- }
- else if(argc > 0)
- {
- throw RubyException(rb_eArgError, "invalid number of arguments to Ice::initialize");
- }
-
- Ice::StringSeq seq;
- if(!NIL_P(args) && !arrayToStringSeq(args, seq))
- {
- throw RubyException(rb_eTypeError, "invalid array argument to Ice::initialize");
- }
-
- //
- // Use the with-args or the without-args version of initialize()?
- //
- bool hasArgs = !seq.empty();
-
- Ice::InitializationData data;
- if(!NIL_P(initData))
- {
- volatile VALUE properties = callRuby(rb_iv_get, initData, "@properties");
- volatile VALUE logger = callRuby(rb_iv_get, initData, "@logger");
-
- if(!NIL_P(properties))
- {
- data.properties = getProperties(properties);
- }
-
- if(!NIL_P(logger))
- {
- throw RubyException(rb_eArgError, "custom logger is not supported");
- }
- }
-
- //
- // Insert the program name (stored in the Ruby global variable $0) as the first
- // element of the sequence.
- //
- volatile VALUE progName = callRuby(rb_gv_get, "$0");
- seq.insert(seq.begin(), getString(progName));
-
- data.properties = Ice::createProperties(seq, data.properties);
-
- //
- // Disable collocation optimization, otherwise an invocation on a
- // collocated servant results in a CollocationOptimizationException
- // (because Ruby uses the blobject API).
- //
- // TODO: Enable if a server mapping is added.
- //
- //data.properties->setProperty("Ice.Default.CollocationOptimization", "0");
-
- //
- // Remaining command line options are passed to the communicator
- // as an argument vector in case they contain plugin properties.
- //
- int ac = static_cast<int>(seq.size());
- char** av = new char*[ac + 1];
- int i = 0;
- for(Ice::StringSeq::const_iterator s = seq.begin(); s != seq.end(); ++s, ++i)
- {
- av[i] = strdup(s->c_str());
- }
- av[ac] = 0;
-
- Ice::CommunicatorPtr communicator;
- try
- {
- if(hasArgs)
- {
- communicator = Ice::initialize(ac, av, data);
- }
- else
- {
- communicator = Ice::initialize(data);
- }
- }
- catch(...)
- {
- for(i = 0; i < ac + 1; ++i)
- {
- free(av[i]);
- }
- delete[] av;
-
- throw;
- }
-
- //
- // Replace the contents of the given argument list with the filtered arguments.
- //
- if(!NIL_P(args))
- {
- callRuby(rb_ary_clear, args);
-
- //
- // We start at index 1 in order to skip the element that we inserted earlier.
- //
- for(i = 1; i < ac; ++i)
- {
- volatile VALUE str = createString(av[i]);
- callRuby(rb_ary_push, args, str);
- }
- }
-
- for(i = 0; i < ac + 1; ++i)
- {
- free(av[i]);
- }
- 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));
-
- CommunicatorMap::iterator p = _communicatorMap.find(communicator);
- if(p != _communicatorMap.end())
- {
- _communicatorMap.erase(p);
- }
- _communicatorMap.insert(CommunicatorMap::value_type(communicator, reinterpret_cast<const VALUE&>(result)));
-
- return result;
+ volatile VALUE initDataCls = callRuby(rb_path2class, "Ice::InitializationData");
+ volatile VALUE args = Qnil, initData = Qnil;
+ if(argc == 1)
+ {
+ if(isArray(argv[0]))
+ {
+ args = argv[0];
+ }
+ else if(callRuby(rb_obj_is_instance_of, argv[0], initDataCls) == Qtrue)
+ {
+ initData = argv[0];
+ }
+ else
+ {
+ throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
+ }
+ }
+ else if(argc == 2)
+ {
+ if(!isArray(argv[0]) || callRuby(rb_obj_is_instance_of, argv[1], initDataCls) == Qfalse)
+ {
+ throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
+ }
+ args = argv[0];
+ initData = argv[1];
+ }
+ else if(argc > 0)
+ {
+ throw RubyException(rb_eArgError, "invalid number of arguments to Ice::initialize");
+ }
+
+ Ice::StringSeq seq;
+ if(!NIL_P(args) && !arrayToStringSeq(args, seq))
+ {
+ throw RubyException(rb_eTypeError, "invalid array argument to Ice::initialize");
+ }
+
+ //
+ // Use the with-args or the without-args version of initialize()?
+ //
+ bool hasArgs = !seq.empty();
+
+ Ice::InitializationData data;
+ if(!NIL_P(initData))
+ {
+ volatile VALUE properties = callRuby(rb_iv_get, initData, "@properties");
+ volatile VALUE logger = callRuby(rb_iv_get, initData, "@logger");
+
+ if(!NIL_P(properties))
+ {
+ data.properties = getProperties(properties);
+ }
+
+ if(!NIL_P(logger))
+ {
+ throw RubyException(rb_eArgError, "custom logger is not supported");
+ }
+ }
+
+ //
+ // Insert the program name (stored in the Ruby global variable $0) as the first
+ // element of the sequence.
+ //
+ volatile VALUE progName = callRuby(rb_gv_get, "$0");
+ seq.insert(seq.begin(), getString(progName));
+
+ data.properties = Ice::createProperties(seq, data.properties);
+
+ //
+ // Disable collocation optimization, otherwise an invocation on a
+ // collocated servant results in a CollocationOptimizationException
+ // (because Ruby uses the blobject API).
+ //
+ // TODO: Enable if a server mapping is added.
+ //
+ //data.properties->setProperty("Ice.Default.CollocationOptimization", "0");
+
+ //
+ // Remaining command line options are passed to the communicator
+ // as an argument vector in case they contain plugin properties.
+ //
+ int ac = static_cast<int>(seq.size());
+ char** av = new char*[ac + 1];
+ int i = 0;
+ for(Ice::StringSeq::const_iterator s = seq.begin(); s != seq.end(); ++s, ++i)
+ {
+ av[i] = strdup(s->c_str());
+ }
+ av[ac] = 0;
+
+ Ice::CommunicatorPtr communicator;
+ try
+ {
+ if(hasArgs)
+ {
+ communicator = Ice::initialize(ac, av, data);
+ }
+ else
+ {
+ communicator = Ice::initialize(data);
+ }
+ }
+ catch(...)
+ {
+ for(i = 0; i < ac + 1; ++i)
+ {
+ free(av[i]);
+ }
+ delete[] av;
+
+ throw;
+ }
+
+ //
+ // Replace the contents of the given argument list with the filtered arguments.
+ //
+ if(!NIL_P(args))
+ {
+ callRuby(rb_ary_clear, args);
+
+ //
+ // We start at index 1 in order to skip the element that we inserted earlier.
+ //
+ for(i = 1; i < ac; ++i)
+ {
+ volatile VALUE str = createString(av[i]);
+ callRuby(rb_ary_push, args, str);
+ }
+ }
+
+ for(i = 0; i < ac + 1; ++i)
+ {
+ free(av[i]);
+ }
+ 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));
+
+ CommunicatorMap::iterator p = _communicatorMap.find(communicator);
+ if(p != _communicatorMap.end())
+ {
+ _communicatorMap.erase(p);
+ }
+ _communicatorMap.insert(CommunicatorMap::value_type(communicator, reinterpret_cast<const VALUE&>(result)));
+
+ return result;
}
ICE_RUBY_CATCH
return Qnil;
@@ -221,8 +221,8 @@ IceRuby_Communicator_destroy(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- p->destroy();
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ p->destroy();
}
ICE_RUBY_CATCH
return Qnil;
@@ -234,8 +234,8 @@ IceRuby_Communicator_shutdown(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- p->shutdown();
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ p->shutdown();
}
ICE_RUBY_CATCH
return Qnil;
@@ -247,8 +247,8 @@ IceRuby_Communicator_isShutdown(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- return p->isShutdown() ? Qtrue : Qfalse;
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ return p->isShutdown() ? Qtrue : Qfalse;
}
ICE_RUBY_CATCH
return Qnil;
@@ -260,10 +260,10 @@ IceRuby_Communicator_stringToProxy(VALUE self, VALUE str)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- string s = getString(str);
- Ice::ObjectPrx proxy = p->stringToProxy(s);
- return createProxy(proxy);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ string s = getString(str);
+ Ice::ObjectPrx proxy = p->stringToProxy(s);
+ return createProxy(proxy);
}
ICE_RUBY_CATCH
return Qnil;
@@ -275,18 +275,18 @@ IceRuby_Communicator_proxyToString(VALUE self, VALUE proxy)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::ObjectPrx prx;
- if(!NIL_P(proxy))
- {
- if(!checkProxy(proxy))
- {
- throw RubyException(rb_eTypeError, "argument must be a proxy");
- }
- prx = getProxy(proxy);
- }
- string str = p->proxyToString(prx);
- return createString(str);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::ObjectPrx prx;
+ if(!NIL_P(proxy))
+ {
+ if(!checkProxy(proxy))
+ {
+ throw RubyException(rb_eTypeError, "argument must be a proxy");
+ }
+ prx = getProxy(proxy);
+ }
+ string str = p->proxyToString(prx);
+ return createString(str);
}
ICE_RUBY_CATCH
return Qnil;
@@ -298,10 +298,10 @@ IceRuby_Communicator_propertyToProxy(VALUE self, VALUE str)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- string s = getString(str);
- Ice::ObjectPrx proxy = p->propertyToProxy(s);
- return createProxy(proxy);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ string s = getString(str);
+ Ice::ObjectPrx proxy = p->propertyToProxy(s);
+ return createProxy(proxy);
}
ICE_RUBY_CATCH
return Qnil;
@@ -313,10 +313,10 @@ IceRuby_Communicator_stringToIdentity(VALUE self, VALUE str)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- string s = getString(str);
- Ice::Identity ident = p->stringToIdentity(s);
- return createIdentity(ident);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ string s = getString(str);
+ Ice::Identity ident = p->stringToIdentity(s);
+ return createIdentity(ident);
}
ICE_RUBY_CATCH
return Qnil;
@@ -328,10 +328,10 @@ IceRuby_Communicator_identityToString(VALUE self, VALUE id)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::Identity ident = getIdentity(id);
- string str = p->identityToString(ident);
- return createString(str);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::Identity ident = getIdentity(id);
+ string str = p->identityToString(ident);
+ return createString(str);
}
ICE_RUBY_CATCH
return Qnil;
@@ -343,11 +343,11 @@ 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);
- string idstr = getString(id);
- pof->add(factory, idstr);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast(p->findObjectFactory(""));
+ assert(pof);
+ string idstr = getString(id);
+ pof->add(factory, idstr);
}
ICE_RUBY_CATCH
return Qnil;
@@ -359,11 +359,11 @@ IceRuby_Communicator_findObjectFactory(VALUE self, VALUE id)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast(p->findObjectFactory(""));
- assert(pof);
- string idstr = getString(id);
- return pof->find(idstr);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ ObjectFactoryPtr pof = ObjectFactoryPtr::dynamicCast(p->findObjectFactory(""));
+ assert(pof);
+ string idstr = getString(id);
+ return pof->find(idstr);
}
ICE_RUBY_CATCH
return Qnil;
@@ -377,9 +377,9 @@ IceRuby_Communicator_getDefaultContext(VALUE self)
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::Context ctx = p->getDefaultContext();
- return contextToHash(ctx);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::Context ctx = p->getDefaultContext();
+ return contextToHash(ctx);
}
ICE_RUBY_CATCH
return Qnil;
@@ -393,14 +393,14 @@ IceRuby_Communicator_setDefaultContext(VALUE self, VALUE context)
ICE_RUBY_TRY
{
- Ice::Context ctx;
- if(!hashToContext(context, ctx))
- {
- throw RubyException(rb_eTypeError, "argument must be a hash");
- }
-
- Ice::CommunicatorPtr p = getCommunicator(self);
- p->setDefaultContext(ctx);
+ Ice::Context ctx;
+ if(!hashToContext(context, ctx))
+ {
+ throw RubyException(rb_eTypeError, "argument must be a hash");
+ }
+
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ p->setDefaultContext(ctx);
}
ICE_RUBY_CATCH
return Qnil;
@@ -412,9 +412,9 @@ IceRuby_Communicator_getImplicitContext(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::ImplicitContextPtr implicitContext = p->getImplicitContext();
- return createImplicitContext(implicitContext);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::ImplicitContextPtr implicitContext = p->getImplicitContext();
+ return createImplicitContext(implicitContext);
}
ICE_RUBY_CATCH
return Qnil;
@@ -427,9 +427,9 @@ IceRuby_Communicator_getProperties(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::PropertiesPtr props = p->getProperties();
- return createProperties(props);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::PropertiesPtr props = p->getProperties();
+ return createProperties(props);
}
ICE_RUBY_CATCH
return Qnil;
@@ -441,9 +441,9 @@ IceRuby_Communicator_getLogger(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::LoggerPtr logger = p->getLogger();
- return createLogger(logger);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::LoggerPtr logger = p->getLogger();
+ return createLogger(logger);
}
ICE_RUBY_CATCH
return Qnil;
@@ -455,14 +455,14 @@ IceRuby_Communicator_getDefaultRouter(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::RouterPrx router = p->getDefaultRouter();
- if(router)
- {
- volatile VALUE cls = callRuby(rb_path2class, "Ice::RouterPrx");
- assert(!NIL_P(cls));
- return createProxy(router, cls);
- }
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::RouterPrx router = p->getDefaultRouter();
+ if(router)
+ {
+ volatile VALUE cls = callRuby(rb_path2class, "Ice::RouterPrx");
+ assert(!NIL_P(cls));
+ return createProxy(router, cls);
+ }
}
ICE_RUBY_CATCH
return Qnil;
@@ -474,17 +474,17 @@ IceRuby_Communicator_setDefaultRouter(VALUE self, VALUE router)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::RouterPrx proxy;
- if(!NIL_P(router))
- {
- if(!checkProxy(router))
- {
- throw RubyException(rb_eTypeError, "argument must be a proxy");
- }
- proxy = Ice::RouterPrx::uncheckedCast(getProxy(router));
- }
- p->setDefaultRouter(proxy);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::RouterPrx proxy;
+ if(!NIL_P(router))
+ {
+ if(!checkProxy(router))
+ {
+ throw RubyException(rb_eTypeError, "argument must be a proxy");
+ }
+ proxy = Ice::RouterPrx::uncheckedCast(getProxy(router));
+ }
+ p->setDefaultRouter(proxy);
}
ICE_RUBY_CATCH
return Qnil;
@@ -496,14 +496,14 @@ IceRuby_Communicator_getDefaultLocator(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::LocatorPrx locator = p->getDefaultLocator();
- if(locator)
- {
- volatile VALUE cls = callRuby(rb_path2class, "Ice::LocatorPrx");
- assert(!NIL_P(cls));
- return createProxy(locator, cls);
- }
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::LocatorPrx locator = p->getDefaultLocator();
+ if(locator)
+ {
+ volatile VALUE cls = callRuby(rb_path2class, "Ice::LocatorPrx");
+ assert(!NIL_P(cls));
+ return createProxy(locator, cls);
+ }
}
ICE_RUBY_CATCH
return Qnil;
@@ -515,17 +515,17 @@ IceRuby_Communicator_setDefaultLocator(VALUE self, VALUE locator)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- Ice::LocatorPrx proxy;
- if(!NIL_P(locator))
- {
- if(!checkProxy(locator))
- {
- throw RubyException(rb_eTypeError, "argument must be a proxy");
- }
- proxy = Ice::LocatorPrx::uncheckedCast(getProxy(locator));
- }
- p->setDefaultLocator(proxy);
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ Ice::LocatorPrx proxy;
+ if(!NIL_P(locator))
+ {
+ if(!checkProxy(locator))
+ {
+ throw RubyException(rb_eTypeError, "argument must be a proxy");
+ }
+ proxy = Ice::LocatorPrx::uncheckedCast(getProxy(locator));
+ }
+ p->setDefaultLocator(proxy);
}
ICE_RUBY_CATCH
return Qnil;
@@ -537,8 +537,8 @@ IceRuby_Communicator_flushBatchRequests(VALUE self)
{
ICE_RUBY_TRY
{
- Ice::CommunicatorPtr p = getCommunicator(self);
- p->flushBatchRequests();
+ Ice::CommunicatorPtr p = getCommunicator(self);
+ p->flushBatchRequests();
}
ICE_RUBY_CATCH
return Qnil;
@@ -586,7 +586,7 @@ IceRuby::lookupCommunicator(const Ice::CommunicatorPtr& p)
CommunicatorMap::iterator q = _communicatorMap.find(p.get());
if(q != _communicatorMap.end())
{
- return q->second;
+ return q->second;
}
return Qnil;
}