summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2016-03-01 14:33:27 +0100
committerJose <jose@zeroc.com>2016-03-01 14:33:27 +0100
commite283494c906ffac2be14f38422934921ea6ae307 (patch)
treec4b9274845482abd89f84555675d8486a41a71e3
parentRework previous fix for 3.6 compatibility (diff)
downloadice-e283494c906ffac2be14f38422934921ea6ae307.tar.bz2
ice-e283494c906ffac2be14f38422934921ea6ae307.tar.xz
ice-e283494c906ffac2be14f38422934921ea6ae307.zip
Ice::identityToString/Ice::stringToIdentity php/ruby/python implementations
-rw-r--r--cpp/test/Ice/proxy/AllTests.cpp5
-rw-r--r--php/src/IcePHP/Communicator.cpp52
-rw-r--r--php/src/IcePHP/Communicator.h2
-rw-r--r--php/src/IcePHP/Init.cpp8
-rw-r--r--php/test/Ice/proxy/Client.php4
-rw-r--r--python/modules/IcePy/Communicator.cpp49
-rw-r--r--python/modules/IcePy/Communicator.h3
-rw-r--r--python/modules/IcePy/Init.cpp4
-rw-r--r--python/python/Ice.py12
-rw-r--r--python/test/Ice/proxy/AllTests.py2
-rw-r--r--ruby/src/IceRuby/Communicator.cpp30
-rw-r--r--ruby/test/Ice/proxy/AllTests.rb1
12 files changed, 170 insertions, 2 deletions
diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp
index 545dc04037d..2eb3ef3bc5d 100644
--- a/cpp/test/Ice/proxy/AllTests.cpp
+++ b/cpp/test/Ice/proxy/AllTests.cpp
@@ -259,11 +259,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
Ice::Identity id = { "test", ",X2QNUAzSBcJ_e$AV;E\\" };
Ice::Identity id2 = communicator->stringToIdentity(communicator->identityToString(id));
test(id == id2);
+ id2 = Ice::stringToIdentity(Ice::identityToString(id));
+ test(id == id2);
id.name = "test";
id.category = ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\";
id2 = communicator->stringToIdentity(communicator->identityToString(id));
test(id == id2);
+ id2 = Ice::stringToIdentity(Ice::identityToString(id));
+ test(id == id2);
cout << "ok" << endl;
@@ -445,6 +449,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
cout << "testing proxy methods... " << flush;
test(communicator->identityToString(base->ice_identity(communicator->stringToIdentity("other"))->ice_getIdentity())
== "other");
+ test(Ice::identityToString(base->ice_identity(Ice::stringToIdentity("other"))->ice_getIdentity()) == "other");
test(base->ice_facet("facet")->ice_getFacet() == "facet");
test(base->ice_adapterId("id")->ice_getAdapterId() == "id");
test(base->ice_twoway()->ice_isTwoway());
diff --git a/php/src/IcePHP/Communicator.cpp b/php/src/IcePHP/Communicator.cpp
index e0c7394a73b..d57e8ef40e6 100644
--- a/php/src/IcePHP/Communicator.cpp
+++ b/php/src/IcePHP/Communicator.cpp
@@ -1109,6 +1109,58 @@ ZEND_FUNCTION(Ice_getProperties)
}
}
+ZEND_FUNCTION(Ice_identityToString)
+{
+ zend_class_entry* identityClass = idToClass("::Ice::Identity" TSRMLS_CC);
+ assert(identityClass);
+
+ zval* zv;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("O"), &zv, identityClass) != SUCCESS)
+ {
+ RETURN_NULL();
+ }
+ Ice::Identity id;
+ if(!extractIdentity(zv, id TSRMLS_CC))
+ {
+ RETURN_NULL();
+ }
+
+ try
+ {
+ string str = Ice::identityToString(id);
+ RETURN_STRINGL(STRCAST(str.c_str()), static_cast<int>(str.length()), 1);
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ throwException(ex TSRMLS_CC);
+ RETURN_NULL();
+ }
+}
+
+ZEND_FUNCTION(Ice_stringToIdentity)
+{
+ char* str;
+ int strLen;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, const_cast<char*>("s"), &str, &strLen) != SUCCESS)
+ {
+ RETURN_NULL();
+ }
+ string s(str, strLen);
+
+ try
+ {
+ Ice::Identity id = Ice::stringToIdentity(s);
+ if(!createIdentity(return_value, id TSRMLS_CC))
+ {
+ RETURN_NULL();
+ }
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ throwException(ex TSRMLS_CC);
+ RETURN_NULL();
+ }
+}
//
// Necessary to suppress warnings from zend_function_entry in php-5.2
diff --git a/php/src/IcePHP/Communicator.h b/php/src/IcePHP/Communicator.h
index e29e390e183..7ace90c7747 100644
--- a/php/src/IcePHP/Communicator.h
+++ b/php/src/IcePHP/Communicator.h
@@ -23,6 +23,8 @@ ZEND_FUNCTION(Ice_register);
ZEND_FUNCTION(Ice_unregister);
ZEND_FUNCTION(Ice_find);
ZEND_FUNCTION(Ice_getProperties);
+ZEND_FUNCTION(Ice_identityToString);
+ZEND_FUNCTION(Ice_stringToIdentity);
}
namespace IcePHP
diff --git a/php/src/IcePHP/Init.cpp b/php/src/IcePHP/Init.cpp
index 782d644b6d7..3732b3d09b5 100644
--- a/php/src/IcePHP/Init.cpp
+++ b/php/src/IcePHP/Init.cpp
@@ -33,7 +33,9 @@ ZEND_END_ARG_INFO()
ZEND_FE(Ice_register, NULL) \
ZEND_FE(Ice_unregister, NULL) \
ZEND_FE(Ice_find, NULL) \
- ZEND_FE(Ice_getProperties, NULL)
+ ZEND_FE(Ice_getProperties, NULL) \
+ ZEND_FE(Ice_identityToString, NULL) \
+ ZEND_FE(Ice_stringToIdentity, NULL) \
#ifdef ICEPHP_USE_NAMESPACES
# define ICEPHP_COMMUNICATOR_NS_FUNCTIONS \
@@ -41,7 +43,9 @@ ZEND_END_ARG_INFO()
ZEND_NS_FALIAS("Ice", register, Ice_register, NULL) \
ZEND_NS_FALIAS("Ice", unregister, Ice_unregister, NULL) \
ZEND_NS_FALIAS("Ice", find, Ice_find, NULL) \
- ZEND_NS_FALIAS("Ice", getProperties, Ice_getProperties, NULL)
+ ZEND_NS_FALIAS("Ice", getProperties, Ice_getProperties, NULL) \
+ ZEND_NS_FALIAS("Ice", identityToString, Ice_identityToString, NULL) \
+ ZEND_NS_FALIAS("Ice", stringToIdentity, Ice_stringToIdentity, NULL)
#else
# define ICEPHP_COMMUNICATOR_NS_FUNCTIONS
#endif
diff --git a/php/test/Ice/proxy/Client.php b/php/test/Ice/proxy/Client.php
index 20783d006d4..ac186cd15d4 100644
--- a/php/test/Ice/proxy/Client.php
+++ b/php/test/Ice/proxy/Client.php
@@ -38,6 +38,9 @@ function allTests($communicator)
$random = $NS ? constant("Ice\\EndpointSelectionType::Random") : constant("Ice_EndpointSelectionType::Random");
$ordered = $NS ? constant("Ice\\EndpointSelectionType::Ordered") : constant("Ice_EndpointSelectionType::Ordered");
$encodingVersion = $NS ? "Ice\\EncodingVersion" : "Ice_EncodingVersion";
+
+ $identityToString = $NS ? "Ice\\identityToString" : "Ice_identityToString";
+ $stringToIdentity = $NS ? "Ice\\stringToIdentity" : "Ice_stringToIdentity";
echo "testing stringToProxy... ";
flush();
@@ -435,6 +438,7 @@ function allTests($communicator)
echo "testing proxy methods... ";
flush();
test($communicator->identityToString($base->ice_identity($communicator->stringToIdentity("other"))->ice_getIdentity()) == "other");
+ test($identityToString($base->ice_identity($stringToIdentity("other"))->ice_getIdentity()) == "other");
test($base->ice_facet("facet")->ice_getFacet() == "facet");
test($base->ice_adapterId("id")->ice_getAdapterId() == "id");
test($base->ice_twoway()->ice_isTwoway());
diff --git a/python/modules/IcePy/Communicator.cpp b/python/modules/IcePy/Communicator.cpp
index 919086d9ae8..550b0fef0ff 100644
--- a/python/modules/IcePy/Communicator.cpp
+++ b/python/modules/IcePy/Communicator.cpp
@@ -1715,3 +1715,52 @@ IcePy::getCommunicatorWrapper(const Ice::CommunicatorPtr& communicator)
Py_INCREF(obj->wrapper);
return obj->wrapper;
}
+
+extern "C"
+PyObject*
+IcePy_identityToString(PyObject* /*self*/, PyObject* obj)
+{
+ Ice::Identity id;
+ if(!getIdentity(obj, id))
+ {
+ return 0;
+ }
+
+ string str;
+
+ try
+ {
+ str = Ice::identityToString(id);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+
+ return createString(str);
+}
+
+extern "C"
+PyObject*
+IcePy_stringToIdentity(PyObject* /*self*/, PyObject* obj)
+{
+ string str;
+ if(!getStringArg(obj, "str", str))
+ {
+ return 0;
+ }
+
+ Ice::Identity id;
+ try
+ {
+ id = Ice::stringToIdentity(str);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+
+ return createIdentity(id);
+}
diff --git a/python/modules/IcePy/Communicator.h b/python/modules/IcePy/Communicator.h
index 3f2ac0452c3..c83c2898aae 100644
--- a/python/modules/IcePy/Communicator.h
+++ b/python/modules/IcePy/Communicator.h
@@ -32,4 +32,7 @@ extern "C" PyObject* IcePy_initializeWithProperties(PyObject*, PyObject*);
extern "C" PyObject* IcePy_initializeWithLogger(PyObject*, PyObject*);
extern "C" PyObject* IcePy_initializeWithPropertiesAndLogger(PyObject*, PyObject*);
+extern "C" PyObject* IcePy_identityToString(PyObject*, PyObject*);
+extern "C" PyObject* IcePy_stringToIdentity(PyObject*, PyObject*);
+
#endif
diff --git a/python/modules/IcePy/Init.cpp b/python/modules/IcePy/Init.cpp
index 0a594104b61..4494d7f11b8 100644
--- a/python/modules/IcePy/Init.cpp
+++ b/python/modules/IcePy/Init.cpp
@@ -57,6 +57,10 @@ static PyMethodDef methods[] =
PyDoc_STR(STRCAST("generateUUID() -> string")) },
{ STRCAST("createProperties"), reinterpret_cast<PyCFunction>(IcePy_createProperties), METH_VARARGS,
PyDoc_STR(STRCAST("createProperties([args]) -> Ice.Properties")) },
+ { STRCAST("stringToIdentity"), reinterpret_cast<PyCFunction>(IcePy_stringToIdentity), METH_O,
+ PyDoc_STR(STRCAST("stringToIdentity(string) -> Ice.Identity")) },
+ { STRCAST("identityToString"), reinterpret_cast<PyCFunction>(IcePy_identityToString), METH_O,
+ PyDoc_STR(STRCAST("identityToString(Ice.Identity) -> string")) },
{ STRCAST("getProcessLogger"), reinterpret_cast<PyCFunction>(IcePy_getProcessLogger), METH_NOARGS,
PyDoc_STR(STRCAST("getProcessLogger() -> Ice.Logger")) },
{ STRCAST("setProcessLogger"), reinterpret_cast<PyCFunction>(IcePy_setProcessLogger), METH_VARARGS,
diff --git a/python/python/Ice.py b/python/python/Ice.py
index feb060efa54..88b5b90f220 100644
--- a/python/python/Ice.py
+++ b/python/python/Ice.py
@@ -706,6 +706,18 @@ the list that were recognized by the Ice run time.
return CommunicatorI(communicator)
#
+# Ice.identityToString
+#
+def identityToString(id):
+ return IcePy.identityToString(id)
+
+#
+# Ice.stringToIdentity
+#
+def stringToIdentity(str):
+ return IcePy.stringToIdentity(str)
+
+#
# ObjectAdapter wrapper.
#
class ObjectAdapterI(ObjectAdapter):
diff --git a/python/test/Ice/proxy/AllTests.py b/python/test/Ice/proxy/AllTests.py
index fb606824b30..170b0448fe1 100644
--- a/python/test/Ice/proxy/AllTests.py
+++ b/python/test/Ice/proxy/AllTests.py
@@ -360,6 +360,8 @@ def allTests(communicator, collocated):
sys.stdout.flush()
test(communicator.identityToString(base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()) \
== "other")
+ test(Ice.identityToString(base.ice_identity(Ice.stringToIdentity("other")).ice_getIdentity()) == "other")
+
test(base.ice_facet("facet").ice_getFacet() == "facet")
test(base.ice_adapterId("id").ice_getAdapterId() == "id")
test(base.ice_twoway().ice_isTwoway())
diff --git a/ruby/src/IceRuby/Communicator.cpp b/ruby/src/IceRuby/Communicator.cpp
index 24d9629a847..16bd58cb90f 100644
--- a/ruby/src/IceRuby/Communicator.cpp
+++ b/ruby/src/IceRuby/Communicator.cpp
@@ -226,6 +226,34 @@ IceRuby_initialize(int argc, VALUE* argv, VALUE self)
extern "C"
VALUE
+IceRuby_stringToIdentity(VALUE self, VALUE str)
+{
+ ICE_RUBY_TRY
+ {
+ string s = getString(str);
+ Ice::Identity ident = Ice::stringToIdentity(s);
+ return createIdentity(ident);
+ }
+ ICE_RUBY_CATCH
+ return Qnil;
+}
+
+extern "C"
+VALUE
+IceRuby_identityToString(VALUE self, VALUE id)
+{
+ ICE_RUBY_TRY
+ {
+ Ice::Identity ident = getIdentity(id);
+ string str = Ice::identityToString(ident);
+ return createString(str);
+ }
+ ICE_RUBY_CATCH
+ return Qnil;
+}
+
+extern "C"
+VALUE
IceRuby_Communicator_destroy(VALUE self)
{
ICE_RUBY_TRY
@@ -553,6 +581,8 @@ 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, "stringToIdentity", CAST_METHOD(IceRuby_stringToIdentity), 1);
_communicatorClass = rb_define_class_under(iceModule, "CommunicatorI", rb_cObject);
rb_define_method(_communicatorClass, "destroy", CAST_METHOD(IceRuby_Communicator_destroy), 0);
diff --git a/ruby/test/Ice/proxy/AllTests.rb b/ruby/test/Ice/proxy/AllTests.rb
index 35131cda679..1de60ec0539 100644
--- a/ruby/test/Ice/proxy/AllTests.rb
+++ b/ruby/test/Ice/proxy/AllTests.rb
@@ -355,6 +355,7 @@ def allTests(communicator)
print "testing proxy methods... "
STDOUT.flush
test(communicator.identityToString(base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()) == "other")
+ test(Ice::identityToString(base.ice_identity(Ice::stringToIdentity("other")).ice_getIdentity()) == "other")
test(base.ice_facet("facet").ice_getFacet() == "facet")
test(base.ice_adapterId("id").ice_getAdapterId() == "id")
test(base.ice_twoway().ice_isTwoway())