1 //******************************************************************
3 // Copyright 2014 MediaTek All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef _Included_org_iotivity_base_ocstack
22 #define _Included_org_iotivity_base_ocstack
25 #include <android/log.h>
27 #include "OCPlatform.h"
29 class JNICallBackContext {
32 std::shared_ptr<OC::OCResource> m_resource;
33 jobject m_callBackFunction;
35 JNICallBackContext(jobject callback) {
37 m_callBackFunction = callback;
40 JNICallBackContext(std::shared_ptr<OC::OCResource> rsrc,
43 m_callBackFunction = callback;
47 extern std::map<string, JNICallBackContext*> gJNICallBackContextList;
49 extern JavaVM* g_JavaVM;
51 extern jclass g_ocplatform_clazz;
52 extern jclass g_ocresource_clazz;
53 extern jclass g_ocheaderoption_clazz;
54 extern jclass g_ocrepresentation_clazz;
55 extern jclass g_platformcfg_clazz;
58 T *getHandle(JNIEnv *env, jobject obj)
60 jclass cls = env->GetObjectClass(obj);
61 jfieldID fid = env->GetFieldID(cls, "nativeHandle", "J");
62 jlong handle = env->GetLongField(obj, fid);
63 return reinterpret_cast<T *>(handle);
67 extern JNIEXPORT void JNICALL configure(JNIEnv *env, jobject obj, jobject jcfg);
68 extern JNIEXPORT jint JNICALL findResource(JNIEnv* env, jobject obj, jstring jhost, jstring juri, jobject found);
71 extern JNIEXPORT jlong JNICALL createNativeInstance
72 (JNIEnv *env, jobject obj, jint jServiceType, jint jModeType, jstring jIpAddress, jint port, jint jQOS);
75 extern JNIEXPORT jint JNICALL getOptionID(JNIEnv *env, jobject jobj);
76 extern JNIEXPORT jstring JNICALL getOptionData(JNIEnv *env, jobject jobj);
77 extern JNIEXPORT jlong JNICALL OCHeaderOptionConstructor(JNIEnv *env, jobject jobj, jint joption, jstring jdata);
79 // ocrepresentation-jni
80 extern JNIEXPORT jlong JNICALL OCRepresentationConstructor(JNIEnv *env, jobject jobj);
81 extern JNIEXPORT jstring JNICALL getUri(JNIEnv *env, jobject jobj);
82 extern JNIEXPORT jint JNICALL getValueInt(JNIEnv *env, jobject jobj, jstring jstr);
83 extern JNIEXPORT jboolean JNICALL getValueBool(JNIEnv *env, jobject jobj, jstring jstr);
84 extern JNIEXPORT jstring JNICALL getValueString(JNIEnv *env, jobject jobj, jstring jstr);
85 extern JNIEXPORT void JNICALL setValueInt(JNIEnv *env, jobject jobj, jstring jstr, jint jval);
86 extern JNIEXPORT void JNICALL setValueBool(JNIEnv *env, jobject jobj, jstring jstr, jboolean jval);
87 extern JNIEXPORT void JNICALL setValueString(JNIEnv *env, jobject jobj, jstring jstr, jstring jval);
88 extern JNIEXPORT jboolean JNICALL hasAttribute(JNIEnv *env, jobject jobj, jstring jstr);
91 extern JNIEXPORT jobject JNICALL jniOicGet(JNIEnv *env, jobject jobj, jobject jattributeHandler);
92 extern JNIEXPORT jobject JNICALL jniOicPut(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler);
93 extern JNIEXPORT jobject JNICALL jniOicPost(JNIEnv *env, jobject jobj, jobject jocrepresentation, jobject jattributeHandler);
94 extern JNIEXPORT jobject JNICALL jniOicObserve(JNIEnv *env, jobject jobj, jint jobservetype, jobject jattributeHandler);
95 extern JNIEXPORT jobject JNICALL jniOicCancelObserve(JNIEnv *env, jobject jobj);
96 extern JNIEXPORT jstring JNICALL uri(JNIEnv *env, jobject jobj);
97 extern JNIEXPORT jstring JNICALL host(JNIEnv *env, jobject jobj);
98 extern JNIEXPORT jobjectArray JNICALL getResourceTypes(JNIEnv *env, jobject jobj);
99 extern JNIEXPORT jobjectArray JNICALL getResourceInterfaces(JNIEnv *env, jobject jobj);