summaryrefslogtreecommitdiff
path: root/ruby/src/IceRuby
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2017-03-29 15:36:53 -0700
committerMark Spruiell <mes@zeroc.com>2017-03-29 15:36:53 -0700
commit949ea036642e4640cf09aed1b2e70ca739579504 (patch)
treefe646f06609f8496c132c9cad7e9cc4153d940c3 /ruby/src/IceRuby
parentOverride java.lang.AutoCloseable.close in Ice.Communicator to not throw any e... (diff)
downloadice-949ea036642e4640cf09aed1b2e70ca739579504.tar.bz2
ice-949ea036642e4640cf09aed1b2e70ca739579504.tar.xz
ice-949ea036642e4640cf09aed1b2e70ca739579504.zip
ICE-7716 - more scripting language fixes
Diffstat (limited to 'ruby/src/IceRuby')
-rw-r--r--ruby/src/IceRuby/Communicator.cpp97
1 files changed, 69 insertions, 28 deletions
diff --git a/ruby/src/IceRuby/Communicator.cpp b/ruby/src/IceRuby/Communicator.cpp
index 19d39267e44..efa32357b08 100644
--- a/ruby/src/IceRuby/Communicator.cpp
+++ b/ruby/src/IceRuby/Communicator.cpp
@@ -62,9 +62,26 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
{
ICE_RUBY_TRY
{
+ //
+ // The argument options are:
+ //
+ // Ice::initialize()
+ // Ice::initialize(args)
+ // Ice::initialize(initData)
+ // Ice::initialize(configFile)
+ // Ice::initialize(args, initData)
+ // Ice::initialize(args, configFile)
+ //
+
+ if(argc > 2)
+ {
+ throw RubyException(rb_eArgError, "invalid number of arguments to Ice::initialize");
+ }
+
volatile VALUE initDataCls = callRuby(rb_path2class, "Ice::InitializationData");
- volatile VALUE args = Qnil, initData = Qnil;
- if(argc == 1)
+ volatile VALUE args = Qnil, initData = Qnil, configFile = Qnil;
+
+ if(argc >= 1)
{
if(isArray(argv[0]))
{
@@ -74,23 +91,54 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
{
initData = argv[0];
}
+ else if(TYPE(argv[0]) == T_STRING)
+ {
+ configFile = argv[0];
+ }
else
{
- throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
+ throw RubyException(rb_eTypeError,
+ "initialize expects an argument list, InitializationData or a configuration filename");
}
}
- else if(argc == 2)
+
+ if(argc >= 2)
{
- if(!isArray(argv[0]) || callRuby(rb_obj_is_instance_of, argv[1], initDataCls) == Qfalse)
+ if(isArray(argv[1]))
+ {
+ if(!NIL_P(args))
+ {
+ throw RubyException(rb_eTypeError, "unexpected array argument to initialize");
+ }
+ args = argv[1];
+ }
+ else if(callRuby(rb_obj_is_instance_of, argv[1], initDataCls) == Qtrue)
+ {
+ if(!NIL_P(initData))
+ {
+ throw RubyException(rb_eTypeError, "unexpected InitializationData argument to initialize");
+ }
+ initData = argv[1];
+ }
+ else if(TYPE(argv[1]) == T_STRING)
+ {
+ if(!NIL_P(configFile))
+ {
+ throw RubyException(rb_eTypeError, "unexpected string argument to initialize");
+ }
+ configFile = argv[1];
+ }
+ else
{
- throw RubyException(rb_eTypeError, "invalid argument to Ice::initialize");
+ throw RubyException(rb_eTypeError,
+ "initialize expects an argument list, InitializationData or a configuration filename");
}
- args = argv[0];
- initData = argv[1];
}
- else if(argc > 0)
+
+ if(!NIL_P(initData) && !NIL_P(configFile))
{
- throw RubyException(rb_eArgError, "invalid number of arguments to Ice::initialize");
+ throw RubyException(rb_eTypeError,
+ "initialize accepts either Ice.InitializationData or a configuration filename");
}
Ice::StringSeq seq;
@@ -99,11 +147,6 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
throw RubyException(rb_eTypeError, "invalid array argument to Ice::initialize");
}
- //
- // Use the with-args or the without-args version of initialize()?
- //
- bool hasArgs = !NIL_P(args);
-
Ice::InitializationData data;
if(!NIL_P(initData))
{
@@ -131,22 +174,20 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
data.compactIdResolver = new IdResolver;
data.valueFactoryManager = new ValueFactoryManager;
- if(hasArgs)
+ if(!data.properties)
{
- data.properties = Ice::createProperties(seq, data.properties);
+ data.properties = Ice::createProperties();
+ }
+
+ if(!NIL_P(configFile))
+ {
+ data.properties->load(getString(configFile));
}
- else if(!data.properties)
+
+ if(!NIL_P(args))
{
- data.properties = Ice::createProperties();
+ 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
@@ -164,7 +205,7 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
Ice::CommunicatorPtr communicator;
try
{
- if(hasArgs)
+ if(!NIL_P(args))
{
communicator = Ice::initialize(ac, av, data);
}