oc_endpoint.i 2.9 KB
Newer Older
1 2 3
/* File oc_endpoint.i */
%module OCEndpointUtil

George Nash's avatar
George Nash committed
4 5
%include "stdint.i"
%include "arrays_java.i"
6 7
%include "iotivity.swg"

George Nash's avatar
George Nash committed
8 9
%import "oc_uuid.i"

10 11 12 13 14 15 16 17 18 19 20 21 22
%pragma(java) jniclasscode=%{
  static {
    try {
        System.loadLibrary("iotivity-lite-jni");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load. \n" + e);
      System.exit(1);
    }
  }
%}

%{
#include "oc_endpoint.h"
George Nash's avatar
George Nash committed
23
#include "oc_iotivity_lite_jni.h"
24 25 26 27
%}

/*******************Begin oc_endpoint.h*********************/
%rename(OCEndpoint) oc_endpoint_t;
George Nash's avatar
George Nash committed
28 29
// must use the oc_endpoint_set_di function to set di.
%immutable oc_endpoint_t::di;
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// transport flags are pulled from hand generated class as `int` not `enum`
%ignore transport_flags;
//%rename (OCTransportFlags) transport_flags;
%rename(DevAddr) dev_addr;
//if uncommented the following apply lines will cause the output to be byte[] vs short[]
//%apply signed char[ANY] { uint8_t address[4] };
//%apply signed char[ANY] { uint8_t address[16] };
%rename(OCIPv6Addr) oc_ipv6_addr_t;
%rename(OCIPv4Addr) oc_ipv4_addr_t;
%rename(OCLEAddr) oc_le_addr_t;
%rename(addrLocal) addr_local;
%rename(OCFVersion) ocf_version_t;
%rename(interfaceIndex) interface_index;
// look into exposing oc_make_ipv4_endpoint and oc_make_ipv6_endpoint
%rename(newEndpoint) oc_new_endpoint;
%rename(freeEndpoint) oc_free_endpoint;
%rename(setDi) oc_endpoint_set_di;
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
%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;
}
%}


88 89
%apply oc_string_t *INPUT { oc_string_t *endpoint_str };
%apply oc_string_t *OUTPUT { oc_string_t *uri };
George Nash's avatar
George Nash committed
90
/* TODO check the string_to_endpoint function output */
91 92 93 94 95 96
%rename(stringToEndpoint) oc_string_to_endpoint;
%rename(ipv6EndpointIsLinkLocal) oc_ipv6_endpoint_is_link_local;
%rename(compare) oc_endpoint_compare;
%rename(compareAddress) oc_endpoint_compare_address;
%include "oc_endpoint.h"
/*******************End oc_endpoint.h***********************/