Commit 492817f0 authored by George Nash's avatar George Nash Committed by Kishen Maloor

Add APIs to Java

This exposes oc_endpoint_string_parse_path to Java
under OCEndpointUtil.endpointStringParsePath

Ignore oc_ri_is_client_cb_valid this function is not
expected to be used in Java.

With oc_endpoint_string_parse_path exposed to Java we are
able to update the OCEndpointUtil.stringToEndpoint method so
it can take only one parameter. Since developers are already
using the stringToEndpoint method that takes two parameters
we need to still provide that method.

The stringToEndpoint that takes two parameters has a return
value in one of the parameters.  Although this works it is
very unsual in Java to use code this way. Now users can call
the single parameter version of stringToEndpoint and if they
need the path from that endpoint they can call
endpointStringParsePath using the same endpoint string. More
method call but much closer to what a Java developer would
Signed-off-by: George Nash's avatarGeorge Nash <>
parent 839d6689
Pipeline #770 passed with stage
in 6 minutes and 38 seconds
......@@ -1786,6 +1786,7 @@ void jni_oc_remove_delayed_callback(jobject callback) {
%ignore oc_ri_alloc_client_cb;
%ignore oc_ri_get_client_cb;
%ignore oc_ri_find_client_cb_by_token;
%ignore oc_ri_is_client_cb_valid;
%ignore oc_ri_find_client_cb_by_mid;
%ignore oc_ri_remove_client_cb_by_mid;
%ignore oc_ri_free_client_cbs_by_endpoint;
......@@ -57,7 +57,7 @@
%ignore oc_free_endpoint;
// tell swig to use our JNI code not to generate its own.
%native (freeEndpoint) void freeEndpoint(oc_endpoint_t *endpoint);
%inline %{
void jni_free_endpoint(oc_endpoint_t *endpoint) {
endpoint = NULL;
......@@ -199,6 +199,62 @@ oc_endpoint_t * jni_string_to_endpoint(oc_string_t *endpoint_str, oc_string_t *u
return ep;
%javaexception("OCEndpointParseException") jni_string_to_endpoint_a {
if (!jarg1) {
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
JCALL2(ThrowNew, jenv, cls_OCEndpointParseException, "The (null) string cannot be parsed.");
return $null;
if(!result) {
OC_DBG("JNI: String can not be parsed.");
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
oc_string_t exception_message_part1;
oc_concat_strings(&exception_message_part1, "The \"", oc_string(*arg1));
oc_string_t exception_message;
oc_concat_strings(&exception_message, oc_string(exception_message_part1), "\" string cannot be parsed.");
JCALL2(ThrowNew, jenv, cls_OCEndpointParseException, ((char *)oc_string(exception_message)));
%newobject jni_string_to_endpoint_a;
%rename(stringToEndpoint) jni_string_to_endpoint_a;
%inline %{
oc_endpoint_t * jni_string_to_endpoint_a(oc_string_t *endpoint_str) {
OC_DBG("JNI: %s\n", __func__);
oc_endpoint_t *ep = oc_new_endpoint();
if(oc_string_to_endpoint(endpoint_str, ep, NULL) < 0) {
OC_DBG("JNI: oc_string_to_endpoint failed to parse %s\n", oc_string(*endpoint_str));
return NULL;
return ep;
%ignore oc_endpoint_string_parse_path;
%newobject jni_endpoint_string_parse_path;
%rename (endpointStringParsePath) jni_endpoint_string_parse_path;
%inline %{
* Convert the input parameter to a return parameter
char *jni_endpoint_string_parse_path(oc_string_t *endpoint_str)
oc_string_t path;
if (oc_endpoint_string_parse_path(endpoint_str, &path) == 0 ){
char * ret_path = (char *)malloc((path.size) * sizeof(char));
strcpy(ret_path, oc_string(path));
return ret_path;
return NULL;
%rename(ipv6EndpointIsLinkLocal) oc_ipv6_endpoint_is_link_local;
%rename(compare) oc_endpoint_compare;
%rename(compareAddress) oc_endpoint_compare_address;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment