Properly defined URI & Resource Type values for Presence Advertisement.
[contrib/iotivity.git] / android / Base / app / jni / ocstack-jni.h
1 //******************************************************************
2 //
3 // Copyright 2014 MediaTek All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef _Included_org_iotivity_base_ocstack
22 #define _Included_org_iotivity_base_ocstack
23
24 #include <jni.h>
25 #include <android/log.h>
26 #include "OCApi.h"
27 #include "OCPlatform.h"
28
29 class JNICallBackContext {
30     public:
31
32     std::shared_ptr<OC::OCResource> m_resource;
33     jobject m_callBackFunction;
34
35     JNICallBackContext(jobject callback) {
36         m_resource = NULL;
37         m_callBackFunction = callback;
38     }
39
40     JNICallBackContext(std::shared_ptr<OC::OCResource> rsrc,
41         jobject callback) {
42         m_resource = rsrc;
43         m_callBackFunction = callback;
44     }
45 };
46
47 extern std::map<string, JNICallBackContext*> gJNICallBackContextList;
48
49 extern JavaVM* g_JavaVM;
50
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;
56
57 template <typename T>
58 T *getHandle(JNIEnv *env, jobject obj)
59 {
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);
64 }
65
66 // ocplatform-jni
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);
69
70 // platformcfg-jni
71 extern JNIEXPORT jlong JNICALL createNativeInstance
72   (JNIEnv *env, jobject obj, jint jServiceType, jint jModeType, jstring jIpAddress, jint port, jint jQOS);
73
74 // ocheaderoption-jni
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);
78
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);
89
90 // ocresource-jni
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);
100
101 #endif