Commit af4154b9 authored by George Nash's avatar George Nash Committed by Rick Bell

The EndpointUtil.toString updated

The toString function now returns a String instead
of having to pass in an array of size 1 which is
unusual for Java.

Change-Id: I30ddd6796277f1bd0cdb29174072d83c7437b246
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent f8a8f20c
......@@ -98,9 +98,8 @@ public class MyDiscoveryHandler implements OCDiscoveryHandler {
System.out.println("\tResource " + Light.serverUri + " hosted at endpoint(s):");
OCEndpoint ep = endpoint;
while (ep != null) {
String[] endpointStr = new String[1];
OCEndpointUtil.toString(ep, endpointStr);
System.out.println("\t\tendpoint: " + endpointStr[0]);
String endpointStr = OCEndpointUtil.toString(ep);
System.out.println("\t\tendpoint: " + endpointStr);
System.out.println("\t\t\tendpoint.device " + ep.getDevice());
System.out.println("\t\t\tendpoint.flags " + ep.getFlags());
System.out.println("\t\t\tendpoint.interfaceIndex " + ep.getInterfaceIndex());
......
......@@ -14,9 +14,8 @@ public class OwnedDeviceHandler implements OCObtDiscoveryHandler {
String deviceId = OCUuidUtil.uuidToString(uuid);
System.out.println("\nDiscovered owned device: "+ deviceId + " at:");
while (endpoints != null) {
String[] endpointStr = new String[1];
OCEndpointUtil.toString(endpoints, endpointStr);
System.out.println(endpointStr[0]);
String endpointStr = OCEndpointUtil.toString(endpoints);
System.out.println(endpointStr);
endpoints = endpoints.getNext();
}
......
......@@ -14,9 +14,8 @@ public class UnownedDeviceHandler implements OCObtDiscoveryHandler {
String deviceId = OCUuidUtil.uuidToString(uuid);
System.out.println("\nDiscovered unowned device: "+ deviceId + " at:");
while (endpoints != null) {
String[] endpointStr = new String[1];
OCEndpointUtil.toString(endpoints, endpointStr);
System.out.println(endpointStr[0]);
String endpointStr = OCEndpointUtil.toString(endpoints);
System.out.println(endpointStr);
endpoints = endpoints.getNext();
}
......
......@@ -111,9 +111,7 @@ public class OcUtils {
}
public static String endpointToString(OCEndpoint endpoint) {
String[] endpointString = new String[1];
OCEndpointUtil.toString(endpoint, endpointString);
return endpointString[0];
return OCEndpointUtil.toString(endpoint);
}
public static void closeSession(OCEndpoint endpoint) {
......
......@@ -43,10 +43,47 @@
%rename(newEndpoint) oc_new_endpoint;
%rename(freeEndpoint) oc_free_endpoint;
%rename(setDi) oc_endpoint_set_di;
/* TODO check the to_string function output */
%apply oc_string_t *OUTPUT { oc_string_t *endpointStrOut };
%rename(toString) oc_endpoint_to_string;
int oc_endpoint_to_string(oc_endpoint_t *endpoint, oc_string_t *endpointStrOut);
%ignore oc_endpoint_to_string;
%typemap(jni) jobject toString "jobject";
%typemap(jtype) jobject toString "String";
%typemap(jstype) jobject toString "String";
%typemap(javain) jobject toString "$javainput";
%pragma(java) jniclassimports="import java.lang.String;"
%native (toString) jobject toString(oc_endpoint_t *endpoint);
%{
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT jobject JNICALL Java_org_iotivity_OCEndpointUtilJNI_toString(JNIEnv *jenv,
jclass jcls,
jlong jendpoint,
jobject jendpoint_)
{
jobject jresult = 0;
oc_endpoint_t *endpoint = (oc_endpoint_t *)0;
jobject result;
(void)jenv;
(void)jcls;
(void)jendpoint_;
endpoint = *(oc_endpoint_t **)&jendpoint;
oc_string_t ep;
int r = oc_endpoint_to_string(endpoint, &ep);
if(r < 0) {
return NULL;
}
result = JCALL1(NewStringUTF, jenv, oc_string(ep));
oc_free_string(&ep);
jresult = result;
return jresult;
}
%}
%apply oc_string_t *INPUT { oc_string_t *endpoint_str };
%apply oc_string_t *OUTPUT { oc_string_t *uri };
/* TODO check the string_to_endpoint function output */
......
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