Commit 092c4cb5 authored by George Nash's avatar George Nash Committed by Rick Bell

Expose oc_random_pin_cb_t to Java

Expose the oc_random_pin_cb_t as OCRandomPinHandler.
Also add the setRandomPinHandler function to Java.

Change-Id: Id95f43fa281d0a741cad1cbe1d1b4e637c89db99
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/29399Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: Larry Sachs's avatarLarry Sachs <larry.j.sachs@intel.com>
Reviewed-by: default avatarRick Bell <richard.s.bell@intel.com>
parent 679520bb
package org.iotivity;
public interface OCRandomPinHandler {
public void handler(String pin);
}
\ No newline at end of file
......@@ -47,6 +47,7 @@ static jclass cls_OCDiscoveryHandler;
static jclass cls_OCFactoryPresetsHandler;
static jclass cls_OCInitPlatformHandler;
static jclass cls_OCQueryValue;
static jclass cls_OCRandomPinHandler;
static jclass cls_OCRepresentation;
static jclass cls_OCRequest;
static jclass cls_OCRequestHandler;
......@@ -257,6 +258,12 @@ int jni_main_init(const oc_handler_t *handler)
cls_OCQueryValue = (jclass)(JCALL1(NewGlobalRef, jenv, ocQueryValueClass));
JCALL1(DeleteLocalRef, jenv, ocQueryValueClass);
jclass ocRandomPinHandler = JCALL1(FindClass, jenv, "org/iotivity/OCRandomPinHandler");
assert(ocRandomPinHandler);
cls_OCRandomPinHandler = (jclass)(JCALL1(NewGlobalRef, jenv, ocRandomPinHandler));
JCALL1(DeleteLocalRef, jenv, ocRandomPinHandler);
jclass ocRepresentationClass = JCALL1(FindClass, jenv, "org/iotivity/OCRepresentation");
assert(ocRepresentationClass);
cls_OCRepresentation = (jclass)(JCALL1(NewGlobalRef, jenv, ocRepresentationClass));
......@@ -476,6 +483,50 @@ int jni_oc_init_platform(const char *mfg_name) {
}
%}
/* Code and typemaps for mapping the oc_random_pin_cb_t to the OCRandomPinHandler */
%{
void jni_oc_random_pin_callback(const unsigned char *pin, size_t pin_len, void *user_data)
{
OC_DBG("JNI: %s\n", __func__);
jni_callback_data *data = (jni_callback_data *)user_data;
assert(cls_OCRandomPinHandler);
const jmethodID mid_handler = JCALL3(GetMethodID,
(data->jenv),
cls_OCRandomPinHandler,
"handler",
"(Ljava/lang/String;)V");
assert(mid_handler);
jstring jpin = JCALL1(NewStringUTF, (data->jenv), pin);
/* TODO convert pin to java string */
JCALL3(CallObjectMethod, (data->jenv), data->jcb_obj, mid_handler, jpin);
}
%}
%typemap(jni) oc_random_pin_cb_t cb "jobject";
%typemap(jtype) oc_random_pin_cb_t cb "OCRandomPinHandler";
%typemap(jstype) oc_random_pin_cb_t cb "OCRandomPinHandler";
%typemap(javain) oc_random_pin_cb_t cb "$javainput";
%typemap(in,numinputs=1) (oc_random_pin_cb_t cb, jni_callback_data *jcb) {
jni_callback_data *user_data = (jni_callback_data *)malloc(sizeof *user_data);
user_data->jenv = jenv;
user_data->jcb_obj = JCALL1(NewGlobalRef, jenv, $input);
jni_list_add(jni_callbacks, user_data);
$1 = jni_oc_random_pin_callback;
$2 = user_data;
}
%ignore oc_set_random_pin_callback;
%rename(setRandomPinHandler) jni_set_random_pin_callback;
%inline %{
void jni_set_random_pin_callback(oc_random_pin_cb_t cb, jni_callback_data *jcb) {
OC_DBG("JNI: %s\n", __func__);
oc_set_random_pin_callback(cb, jcb);
}
%}
%rename(getConResAnnounced) oc_get_con_res_announced;
%rename(setConResAnnounce) oc_set_con_res_announced;
......
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