Merge branch 'master' into simulator
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniOcResource.cpp
1 /*
2 * //******************************************************************
3 * //
4 * // Copyright 2015 Intel Corporation.
5 * //
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 * //
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
11 * //
12 * //      http://www.apache.org/licenses/LICENSE-2.0
13 * //
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
19 * //
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 */
22
23 #include "JniOcResource.h"
24 #include "JniOcRepresentation.h"
25 #include "JniUtils.h"
26
27 JniOcResource::JniOcResource(std::shared_ptr<OCResource> resource)
28     : m_sharedResource(resource)
29 {}
30
31 JniOcResource::~JniOcResource()
32 {
33     LOGD("~JniOcResource()");
34     m_sharedResource = NULL;
35
36     jint envRet;
37     JNIEnv *env = GetJNIEnv(envRet);
38     if (NULL == env) return;
39
40     m_onGetManager.removeAllListeners(env);
41     m_onPutManager.removeAllListeners(env);
42     m_onPostManager.removeAllListeners(env);
43     m_onDeleteManager.removeAllListeners(env);
44     m_onObserveManager.removeAllListeners(env);
45
46     if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
47 }
48
49 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener)
50 {
51     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
52
53     GetCallback getCallback = [onGetListener](
54         const HeaderOptions& opts,
55         const OCRepresentation& rep,
56         const int eCode)
57     {
58         onGetListener->onGetCallback(opts, rep, eCode);
59     };
60
61     return m_sharedResource->get(queryParametersMap, getCallback);
62 }
63
64 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
65     QualityOfService QoS)
66 {
67     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
68
69     GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep,
70         const int eCode)
71     {
72         onGetListener->onGetCallback(opts, rep, eCode);
73     };
74
75     return m_sharedResource->get(queryParametersMap, getCallback, QoS);
76 }
77
78 OCStackResult JniOcResource::get(
79     JNIEnv* env,
80     const std::string &resourceType,
81     const std::string &resourceInterface,
82     const QueryParamsMap &queryParametersMap,
83     jobject jListener)
84 {
85     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
86
87     GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
88         const OCRepresentation& rep, const int eCode)
89     {
90         onGetListener->onGetCallback(opts, rep, eCode);
91     };
92
93     return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
94         getCallback);
95 }
96
97 OCStackResult JniOcResource::get(JNIEnv* env, const std::string &resourceType,
98     const std::string &resourceInterface, const QueryParamsMap &queryParametersMap,
99     jobject jListener, QualityOfService QoS)
100 {
101     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
102
103     GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
104         const OCRepresentation& rep, const int eCode)
105     {
106         onGetListener->onGetCallback(opts, rep, eCode);
107     };
108
109     return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
110         getCallback, QoS);
111 }
112
113 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
114     const QueryParamsMap &queryParametersMap, jobject jListener)
115 {
116     JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
117
118     PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
119         const OCRepresentation& rep, const int eCode)
120     {
121         onPutListener->onPutCallback(opts, rep, eCode);
122     };
123
124     return m_sharedResource->put(representation, queryParametersMap, putCallback);
125 }
126
127 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
128     const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
129 {
130     JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
131
132     PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
133         const OCRepresentation& rep, const int eCode)
134     {
135         onPutListener->onPutCallback(opts, rep, eCode);
136     };
137
138     return m_sharedResource->put(representation, queryParametersMap, putCallback, QoS);
139 }
140
141 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
142     const std::string &resourceInterface, const OCRepresentation &representation,
143     const QueryParamsMap &queryParametersMap, jobject jListener)
144 {
145     JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
146
147     PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
148         const OCRepresentation& rep, const int eCode)
149     {
150         onPutListener->onPutCallback(opts, rep, eCode);
151     };
152
153     return m_sharedResource->put(resourceType, resourceInterface, representation,
154         queryParametersMap, putCallback);
155 }
156
157 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
158     const std::string &resourceInterface, const OCRepresentation &representation,
159     const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
160 {
161     JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
162
163     PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
164         const OCRepresentation& rep, const int eCode)
165     {
166         onPutListener->onPutCallback(opts, rep, eCode);
167     };
168
169     return m_sharedResource->put(resourceType, resourceInterface, representation,
170         queryParametersMap, putCallback, QoS);
171 }
172
173 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
174     const QueryParamsMap &queryParametersMap, jobject jListener)
175 {
176     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
177
178     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
179         const OCRepresentation& rep, const int eCode)
180     {
181         onPostListener->onPostCallback(opts, rep, eCode);
182     };
183
184     return m_sharedResource->post(representation, queryParametersMap, postCallback);
185 }
186
187 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
188     const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
189 {
190     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
191
192     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
193         const OCRepresentation& rep, const int eCode)
194     {
195         onPostListener->onPostCallback(opts, rep, eCode);
196     };
197
198     return m_sharedResource->post(representation, queryParametersMap, postCallback, QoS);
199 }
200
201 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
202     const std::string &resourceInterface, const OCRepresentation &representation,
203     const QueryParamsMap &queryParametersMap, jobject jListener)
204 {
205     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
206
207     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
208         const OCRepresentation& rep, const int eCode)
209     {
210         onPostListener->onPostCallback(opts, rep, eCode);
211     };
212
213     return m_sharedResource->post(resourceType, resourceInterface, representation,
214         queryParametersMap, postCallback);
215 }
216
217 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
218     const std::string &resourceInterface, const OCRepresentation &representation,
219     const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
220 {
221     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
222
223     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
224         const OCRepresentation& rep, const int eCode)
225     {
226         onPostListener->onPostCallback(opts, rep, eCode);
227     };
228
229     return m_sharedResource->post(resourceType, resourceInterface, representation,
230         queryParametersMap, postCallback, QoS);
231 }
232
233 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener)
234 {
235     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
236
237     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
238         const int eCode)
239     {
240         onDeleteListener->onDeleteCallback(opts, eCode);
241     };
242
243     return m_sharedResource->deleteResource(deleteCallback);
244 }
245
246 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS)
247 {
248     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
249
250     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode)
251     {
252         onDeleteListener->onDeleteCallback(opts, eCode);
253     };
254
255     return m_sharedResource->deleteResource(deleteCallback, QoS);
256 }
257
258 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
259     const QueryParamsMap &queryParametersMap, jobject jListener)
260 {
261     JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
262
263     ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
264         const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
265     {
266         onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
267     };
268
269     return m_sharedResource->observe(observeType, queryParametersMap, observeCallback);
270 }
271
272 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
273     const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
274 {
275     JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
276
277     ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
278         const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
279     {
280         onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
281     };
282
283     return m_sharedResource->observe(observeType, queryParametersMap, observeCallback, QoS);
284 }
285
286 OCStackResult JniOcResource::cancelObserve(JNIEnv* env)
287 {
288     this->m_onObserveManager.removeAllListeners(env);
289     return m_sharedResource->cancelObserve();
290 }
291
292 OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos)
293 {
294     //TODO confirm behavior
295     //add removal of java listeners by qos
296     this->m_onObserveManager.removeAllListeners(env);
297     return m_sharedResource->cancelObserve(qos);
298 }
299
300 void JniOcResource::setHeaderOptions(const HeaderOptions &headerOptions)
301 {
302     m_sharedResource->setHeaderOptions(headerOptions);
303 }
304
305 void JniOcResource::unsetHeaderOptions()
306 {
307     m_sharedResource->unsetHeaderOptions();
308 }
309
310 std::string JniOcResource::host()
311 {
312     return m_sharedResource->host();
313 }
314
315 std::string JniOcResource::uri()
316 {
317     return m_sharedResource->uri();
318 }
319
320 OCConnectivityType JniOcResource::connectivityType() const
321 {
322     return m_sharedResource->connectivityType();
323 }
324
325 bool JniOcResource::isObservable()
326 {
327     return m_sharedResource->isObservable();
328 }
329
330 std::vector< std::string > JniOcResource::getResourceTypes() const
331 {
332     return m_sharedResource->getResourceTypes();
333 }
334
335 std::vector< std::string > JniOcResource::getResourceInterfaces(void) const
336 {
337     return m_sharedResource->getResourceInterfaces();
338 }
339
340 OCResourceIdentifier JniOcResource::uniqueIdentifier() const
341 {
342     return m_sharedResource->uniqueIdentifier();
343 }
344
345 std::string JniOcResource::sid() const
346 {
347     return m_sharedResource->sid();
348 }
349
350 JniOnGetListener* JniOcResource::addOnGetListener(JNIEnv* env, jobject jListener)
351 {
352     return this->m_onGetManager.addListener(env, jListener, this);
353 }
354
355 JniOnPutListener* JniOcResource::addOnPutListener(JNIEnv* env, jobject jListener)
356 {
357     return this->m_onPutManager.addListener(env, jListener, this);
358 }
359
360 JniOnPostListener* JniOcResource::addOnPostListener(JNIEnv* env, jobject jListener)
361 {
362     return this->m_onPostManager.addListener(env, jListener, this);
363 }
364
365 JniOnDeleteListener* JniOcResource::addOnDeleteListener(JNIEnv* env, jobject jListener)
366 {
367     return this->m_onDeleteManager.addListener(env, jListener, this);
368 }
369
370 JniOnObserveListener* JniOcResource::addOnObserveListener(JNIEnv* env, jobject jListener)
371 {
372     return this->m_onObserveManager.addListener(env, jListener, this);
373 }
374
375 void JniOcResource::removeOnGetListener(JNIEnv* env, jobject jListener)
376 {
377     this->m_onGetManager.removeListener(env, jListener);
378 }
379
380 void JniOcResource::removeOnPutListener(JNIEnv* env, jobject jListener)
381 {
382     this->m_onPutManager.removeListener(env, jListener);
383 }
384
385 void JniOcResource::removeOnPostListener(JNIEnv* env, jobject jListener)
386 {
387     this->m_onPostManager.removeListener(env, jListener);
388 }
389
390 void JniOcResource::removeOnDeleteListener(JNIEnv* env, jobject jListener)
391 {
392     this->m_onDeleteManager.removeListener(env, jListener);
393 }
394
395 void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener)
396 {
397     this->m_onObserveManager.removeListener(env, jListener);
398 }
399
400 std::shared_ptr<OCResource> JniOcResource::getOCResource()
401 {
402     return this->m_sharedResource;
403 }
404
405 JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz)
406 {
407     JniOcResource *resource = GetHandle<JniOcResource>(env, thiz);
408     if (env->ExceptionCheck())
409     {
410         LOGE("Failed to get native handle from OcResource");
411     }
412     if (!resource)
413     {
414         ThrowOcException(JNI_NO_NATIVE_POINTER, "");
415     }
416     return resource;
417 }
418
419 /*
420 * Class:     org_iotivity_base_OcResource
421 * Method:    get
422 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;)V
423 */
424 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
425 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener)
426 {
427     LOGD("OcResource_get");
428     if (!jQueryParamsMap)
429     {
430         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
431         return;
432     }
433     if (!jListener)
434     {
435         ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
436         return;
437     }
438     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
439     if (!resource) return;
440
441     QueryParamsMap qpm;
442     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
443
444     try
445     {
446         OCStackResult result = resource->get(
447             env,
448             qpm,
449             jListener);
450
451         if (OC_STACK_OK != result)
452         {
453             ThrowOcException(result, "OcResource_get");
454         }
455     }
456     catch (OCException& e)
457     {
458         LOGE("%s", e.reason().c_str());
459         ThrowOcException(e.code(), e.reason().c_str());
460     }
461 }
462
463 /*
464 * Class:     org_iotivity_base_OcResource
465 * Method:    get1
466 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;I)V
467 */
468 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
469 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
470 {
471     LOGD("OcResource_get");
472     if (!jQueryParamsMap)
473     {
474         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
475         return;
476     }
477     if (!jListener)
478     {
479         ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
480         return;
481     }
482     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
483     if (!resource) return;
484
485     QueryParamsMap qpm;
486     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
487
488     try
489     {
490         OCStackResult result = resource->get(
491             env,
492             qpm,
493             jListener,
494             JniUtils::getQOS(env, static_cast<int>(jQoS)));
495
496         if (OC_STACK_OK != result)
497         {
498             ThrowOcException(result, "OcResource_get");
499         }
500     }
501     catch (OCException& e)
502     {
503         LOGE("%s", e.reason().c_str());
504         ThrowOcException(e.code(), e.reason().c_str());
505     }
506 }
507
508 /*
509 * Class:     org_iotivity_base_OcResource
510 * Method:    get2
511 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
512 Lorg/iotivity/base/OcResource/OnGetListener;)V
513 */
514 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get2
515 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
516 jobject jQueryParamsMap, jobject jListener)
517 {
518     LOGD("OcResource_get");
519     std::string resourceType;
520     if (jResourceType)
521     {
522         resourceType = env->GetStringUTFChars(jResourceType, NULL);
523     }
524     std::string resourceInterface;
525     if (jResourceInterface)
526     {
527         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
528     }
529     if (!jQueryParamsMap)
530     {
531         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
532         return;
533     }
534     if (!jListener)
535     {
536         ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
537         return;
538     }
539     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
540     if (!resource) return;
541
542     QueryParamsMap qpm;
543     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
544     try
545     {
546         OCStackResult result = resource->get(
547             env,
548             resourceType,
549             resourceInterface,
550             qpm,
551             jListener);
552
553         if (OC_STACK_OK != result)
554         {
555             ThrowOcException(result, "OcResource_get");
556         }
557     }
558     catch (OCException& e)
559     {
560         LOGE("%s", e.reason().c_str());
561         ThrowOcException(e.code(), e.reason().c_str());
562     }
563 }
564
565 /*
566 * Class:     org_iotivity_base_OcResource
567 * Method:    get3
568 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
569 Lorg/iotivity/base/OcResource/OnGetListener;I)V
570 */
571 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get3
572 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
573 jobject jQueryParamsMap, jobject jListener, jint jQoS)
574 {
575     LOGD("OcResource_get");
576     if (!jQueryParamsMap)
577     {
578         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
579         return;
580     }
581     if (!jListener)
582     {
583         ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
584         return;
585     }
586     std::string resourceType;
587     if (jResourceType)
588     {
589         resourceType = env->GetStringUTFChars(jResourceType, NULL);
590     }
591     std::string resourceInterface;
592     if (jResourceInterface)
593     {
594         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
595     }
596     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
597     if (!resource) return;
598
599     QueryParamsMap qpm;
600     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
601
602     try
603     {
604         OCStackResult result = resource->get(
605             env,
606             resourceType,
607             resourceInterface,
608             qpm,
609             jListener,
610             JniUtils::getQOS(env, static_cast<int>(jQoS)));
611
612         if (OC_STACK_OK != result)
613         {
614             ThrowOcException(result, "OcResource_get");
615         }
616     }
617     catch (OCException& e)
618     {
619         LOGE("%s", e.reason().c_str());
620         ThrowOcException(e.code(), e.reason().c_str());
621     }
622 }
623
624 /*
625 * Class:     org_iotivity_base_OcResource
626 * Method:    put
627 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
628 Lorg/iotivity/base/OcResource/OnPutListener;)V
629 */
630 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
631 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
632 {
633     LOGD("OcResource_put");
634     if (!jRepresentation)
635     {
636         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
637         return;
638     }
639     if (!jQueryParamsMap)
640     {
641         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
642         return;
643     }
644     if (!jListener)
645     {
646         ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
647         return;
648     }
649     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
650     if (!resource) return;
651
652     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
653     if (!representation) return;
654
655     QueryParamsMap qpm;
656     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
657
658     try
659     {
660         OCStackResult result = resource->put(
661             env,
662             *representation,
663             qpm,
664             jListener);
665
666         if (OC_STACK_OK != result)
667         {
668             ThrowOcException(result, "OcResource_put");
669         }
670     }
671     catch (OCException& e)
672     {
673         LOGE("%s", e.reason().c_str());
674         ThrowOcException(e.code(), e.reason().c_str());
675     }
676 }
677
678 /*
679 * Class:     org_iotivity_base_OcResource
680 * Method:    put1
681 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
682 Lorg/iotivity/base/OcResource/OnPutListener;I)V
683 */
684 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put1
685 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
686 jobject jListener, jint jQoS)
687 {
688     LOGD("OcResource_put");
689     if (!jRepresentation)
690     {
691         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
692         return;
693     }
694     if (!jQueryParamsMap)
695     {
696         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
697         return;
698     }
699     if (!jListener)
700     {
701         ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
702         return;
703     }
704     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
705     if (!resource) return;
706
707     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
708     if (!representation) return;
709
710     QueryParamsMap qpm;
711     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
712
713     try
714     {
715         OCStackResult result = resource->put(
716             env,
717             *representation,
718             qpm,
719             jListener,
720             JniUtils::getQOS(env, static_cast<int>(jQoS)));
721
722         if (OC_STACK_OK != result)
723         {
724             ThrowOcException(result, "OcResource_put");
725         }
726     }
727     catch (OCException& e)
728     {
729         LOGE("%s", e.reason().c_str());
730         ThrowOcException(e.code(), e.reason().c_str());
731     }
732 }
733
734 /*
735 * Class:     org_iotivity_base_OcResource
736 * Method:    put2
737 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
738 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;)V
739 */
740 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put2
741 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
742 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
743 {
744     LOGD("OcResource_put");
745     std::string resourceType;
746     if (jResourceType)
747     {
748         resourceType = env->GetStringUTFChars(jResourceType, NULL);
749     }
750     std::string resourceInterface;
751     if (jResourceInterface)
752     {
753         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
754     }
755     if (!jRepresentation)
756     {
757         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
758         return;
759     }
760     if (!jQueryParamsMap)
761     {
762         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
763         return;
764     }
765     if (!jListener)
766     {
767         ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
768         return;
769     }
770     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
771     if (!resource) return;
772
773     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
774     if (!representation) return;
775
776     QueryParamsMap qpm;
777     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
778
779     try
780     {
781         OCStackResult result = resource->put(
782             env,
783             resourceType,
784             resourceInterface,
785             *representation,
786             qpm,
787             jListener);
788
789         if (OC_STACK_OK != result)
790         {
791             ThrowOcException(result, "OcResource_put");
792         }
793     }
794     catch (OCException& e)
795     {
796         LOGE("%s", e.reason().c_str());
797         ThrowOcException(e.code(), e.reason().c_str());
798     }
799 }
800
801 /*
802 * Class:     org_iotivity_base_OcResource
803 * Method:    put3
804 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
805 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;I)V
806 */
807 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put3
808 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface, jobject jRepresentation,
809 jobject jQueryParamsMap, jobject jListener, jint jQoS)
810 {
811     LOGD("OcResource_put");
812     if (!jRepresentation)
813     {
814         ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
815         return;
816     }
817     if (!jQueryParamsMap)
818     {
819         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
820         return;
821     }
822     if (!jListener)
823     {
824         ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
825         return;
826     }
827     std::string resourceType;
828     if (jResourceType)
829     {
830         resourceType = env->GetStringUTFChars(jResourceType, NULL);
831     }
832     std::string resourceInterface;
833     if (jResourceInterface)
834     {
835         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
836     }
837
838     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
839     if (!resource) return;
840
841     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
842     if (!representation) return;
843
844     QueryParamsMap qpm;
845     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
846
847     try
848     {
849         OCStackResult result = resource->put(
850             env,
851             resourceType,
852             resourceInterface,
853             *representation,
854             qpm,
855             jListener,
856             JniUtils::getQOS(env, static_cast<int>(jQoS)));
857
858         if (OC_STACK_OK != result)
859         {
860             ThrowOcException(result, "OcResource_put");
861         }
862     }
863     catch (OCException& e)
864     {
865         LOGE("%s", e.reason().c_str());
866         ThrowOcException(e.code(), e.reason().c_str());
867     }
868 }
869
870 /*
871 * Class:     org_iotivity_base_OcResource
872 * Method:    post
873 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
874 */
875 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
876 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
877 {
878     LOGD("OcResource_post");
879     if (!jRepresentation)
880     {
881         ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
882         return;
883     }
884     if (!jQueryParamsMap)
885     {
886         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
887         return;
888     }
889     if (!jListener)
890     {
891         ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
892         return;
893     }
894     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
895     if (!resource) return;
896
897     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
898     if (!representation) return;
899
900     QueryParamsMap qpm;
901     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
902
903     try
904     {
905         OCStackResult result = resource->post(
906             env,
907             *representation,
908             qpm,
909             jListener);
910
911         if (OC_STACK_OK != result)
912         {
913             ThrowOcException(result, "OcResource_post");
914         }
915     }
916     catch (OCException& e)
917     {
918         LOGE("%s", e.reason().c_str());
919         ThrowOcException(e.code(), e.reason().c_str());
920     }
921 }
922
923 /*
924 * Class:     org_iotivity_base_OcResource
925 * Method:    post1
926 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
927 */
928 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
929 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
930 {
931     LOGD("OcResource_post");
932     if (!jRepresentation)
933     {
934         ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
935         return;
936     }
937     if (!jQueryParamsMap)
938     {
939         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
940         return;
941     }
942     if (!jListener)
943     {
944         ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
945         return;
946     }
947     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
948     if (!resource) return;
949
950     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
951     if (!representation) return;
952
953     QueryParamsMap qpm;
954     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
955
956     try
957     {
958         OCStackResult result = resource->post(
959             env,
960             *representation,
961             qpm,
962             jListener,
963             JniUtils::getQOS(env, static_cast<int>(jQoS)));
964
965         if (OC_STACK_OK != result)
966         {
967             ThrowOcException(result, "OcResource_post");
968         }
969     }
970     catch (OCException& e)
971     {
972         LOGE("%s", e.reason().c_str());
973         ThrowOcException(e.code(), e.reason().c_str());
974     }
975 }
976
977 /*
978 * Class:     org_iotivity_base_OcResource
979 * Method:    post2
980 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
981 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
982 */
983 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post2
984 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
985 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
986 {
987     LOGD("OcResource_post");
988     if (!jRepresentation)
989     {
990         ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
991         return;
992     }
993     if (!jQueryParamsMap)
994     {
995         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
996         return;
997     }
998     if (!jListener)
999     {
1000         ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1001         return;
1002     }
1003     std::string resourceType;
1004     if (jResourceType)
1005     {
1006         resourceType = env->GetStringUTFChars(jResourceType, NULL);
1007     }
1008     std::string resourceInterface;
1009     if (jResourceInterface)
1010     {
1011         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
1012     }
1013
1014     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1015     if (!resource) return;
1016
1017     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1018     if (!representation) return;
1019
1020     QueryParamsMap qpm;
1021     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1022
1023     try
1024     {
1025         OCStackResult result = resource->post(
1026             env,
1027             resourceType,
1028             resourceInterface,
1029             *representation,
1030             qpm,
1031             jListener);
1032
1033         if (OC_STACK_OK != result)
1034         {
1035             ThrowOcException(result, "OcResource_post");
1036         }
1037     }
1038     catch (OCException& e)
1039     {
1040         LOGE("%s", e.reason().c_str());
1041         ThrowOcException(e.code(), e.reason().c_str());
1042     }
1043 }
1044
1045 /*
1046 * Class:     org_iotivity_base_OcResource
1047 * Method:    post3
1048 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1049 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1050 */
1051 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post3
1052 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1053 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1054 {
1055     LOGD("OcResource_post");
1056     if (!jRepresentation)
1057     {
1058         ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1059         return;
1060     }
1061     if (!jQueryParamsMap)
1062     {
1063         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1064         return;
1065     }
1066     if (!jListener)
1067     {
1068         ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1069         return;
1070     }
1071     std::string resourceType;
1072     if (jResourceType)
1073     {
1074         resourceType = env->GetStringUTFChars(jResourceType, NULL);
1075     }
1076     std::string resourceInterface;
1077     if (jResourceInterface)
1078     {
1079         resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL);
1080     }
1081
1082     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1083     if (!resource) return;
1084
1085     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1086     if (!representation) return;
1087
1088     QueryParamsMap qpm;
1089     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1090
1091     try
1092     {
1093         OCStackResult result = resource->post(
1094             env,
1095             resourceType,
1096             resourceInterface,
1097             *representation,
1098             qpm,
1099             jListener,
1100             JniUtils::getQOS(env, static_cast<int>(jQoS)));
1101
1102         if (OC_STACK_OK != result)
1103         {
1104             ThrowOcException(result, "OcResource_post");
1105         }
1106     }
1107     catch (OCException& e)
1108     {
1109         LOGE("%s", e.reason().c_str());
1110         ThrowOcException(e.code(), e.reason().c_str());
1111     }
1112 }
1113
1114 /*
1115 * Class:     org_iotivity_base_OcResource
1116 * Method:    deleteResource
1117 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;)V
1118 */
1119 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
1120 (JNIEnv *env, jobject thiz, jobject jListener)
1121 {
1122     LOGD("OcResource_deleteResource");
1123     if (!jListener)
1124     {
1125         ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1126         return;
1127     }
1128     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1129     if (!resource) return;
1130
1131     try
1132     {
1133         OCStackResult result = resource->deleteResource(
1134             env,
1135             jListener);
1136
1137         if (OC_STACK_OK != result)
1138         {
1139             ThrowOcException(result, "OcResource_deleteResource");
1140         }
1141     }
1142     catch (OCException& e)
1143     {
1144         LOGE("%s", e.reason().c_str());
1145         ThrowOcException(e.code(), e.reason().c_str());
1146     }
1147 }
1148
1149 /*
1150 * Class:     org_iotivity_base_OcResource
1151 * Method:    deleteResource1
1152 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;I)V
1153 */
1154 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
1155 (JNIEnv *env, jobject thiz, jobject jListener, jint jQoS)
1156 {
1157     LOGD("OcResource_deleteResource");
1158     if (!jListener)
1159     {
1160         ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1161         return;
1162     }
1163     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1164     if (!resource) return;
1165
1166     try
1167     {
1168         OCStackResult result = resource->deleteResource(
1169             env,
1170             jListener,
1171             JniUtils::getQOS(env, static_cast<int>(jQoS)));
1172
1173         if (OC_STACK_OK != result)
1174         {
1175             ThrowOcException(result, "OcResource_deleteResource");
1176         }
1177     }
1178     catch (OCException& e)
1179     {
1180         LOGE("%s", e.reason().c_str());
1181         ThrowOcException(e.code(), e.reason().c_str());
1182     }
1183 }
1184
1185 /*
1186 * Class:     org_iotivity_base_OcResource
1187 * Method:    observe
1188 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1189 Lorg/iotivity/base/OcResource/OnObserveListener;)V
1190 */
1191 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
1192 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
1193 {
1194     LOGD("OcResource_observe");
1195     if (!jQueryParamsMap)
1196     {
1197         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1198         return;
1199     }
1200     if (!jListener)
1201     {
1202         ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1203         return;
1204     }
1205     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1206     if (!resource) return;
1207
1208     QueryParamsMap qpm;
1209     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1210
1211     try
1212     {
1213         OCStackResult result = resource->observe(
1214             env,
1215             JniUtils::getObserveType(env, static_cast<int>(observeType)),
1216             qpm,
1217             jListener);
1218
1219         if (OC_STACK_OK != result)
1220         {
1221             ThrowOcException(result, "OcResource_observe");
1222         }
1223     }
1224     catch (OCException& e)
1225     {
1226         LOGE("%s", e.reason().c_str());
1227         ThrowOcException(e.code(), e.reason().c_str());
1228     }
1229 }
1230
1231 /*
1232 * Class:     org_iotivity_base_OcResource
1233 * Method:    observe1
1234 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1235 Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1236 */
1237 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe1
1238 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap,
1239 jobject jListener, jint jQoS)
1240 {
1241     LOGD("OcResource_observe");
1242     if (!jQueryParamsMap)
1243     {
1244         ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1245         return;
1246     }
1247     if (!jListener)
1248     {
1249         ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1250         return;
1251     }
1252     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1253     if (!resource) return;
1254
1255     QueryParamsMap qpm;
1256     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1257
1258     try
1259     {
1260         OCStackResult result = resource->observe(
1261             env,
1262             JniUtils::getObserveType(env, static_cast<int>(observeType)),
1263             qpm,
1264             jListener,
1265             JniUtils::getQOS(env, static_cast<int>(jQoS)));
1266
1267         if (OC_STACK_OK != result)
1268         {
1269             ThrowOcException(result, "OcResource_observe");
1270         }
1271     }
1272     catch (OCException& e)
1273     {
1274         LOGE("%s", e.reason().c_str());
1275         ThrowOcException(e.code(), e.reason().c_str());
1276     }
1277 }
1278
1279 /*
1280 * Class:     org_iotivity_base_OcResource
1281 * Method:    cancelObserve
1282 * Signature: ()V
1283 */
1284 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve
1285 (JNIEnv *env, jobject thiz)
1286 {
1287     LOGD("OcResource_cancelObserve");
1288     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1289     if (!resource) return;
1290
1291     try
1292     {
1293         OCStackResult result = resource->cancelObserve(env);
1294
1295         if (OC_STACK_OK != result)
1296         {
1297             ThrowOcException(result, "OcResource_cancelObserve");
1298         }
1299     }
1300     catch (OCException& e)
1301     {
1302         LOGE("%s", e.reason().c_str());
1303         ThrowOcException(e.code(), e.reason().c_str());
1304     }
1305 }
1306
1307 /*
1308 * Class:     org_iotivity_base_OcResource
1309 * Method:    cancelObserve1
1310 * Signature: I)V
1311 */
1312 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
1313 (JNIEnv *env, jobject thiz, jint jQoS)
1314 {
1315     LOGD("OcResource_cancelObserve1");
1316     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1317     if (!resource) return;
1318
1319     try
1320     {
1321         OCStackResult result = resource->cancelObserve(
1322             env,
1323             JniUtils::getQOS(env, static_cast<int>(jQoS)));
1324
1325         if (OC_STACK_OK != result)
1326         {
1327             ThrowOcException(result, "OcResource_cancelObserve");
1328         }
1329     }
1330     catch (OCException& e)
1331     {
1332         LOGE("%s", e.reason().c_str());
1333         ThrowOcException(e.code(), e.reason().c_str());
1334     }
1335 }
1336
1337 /*
1338 * Class:     org_iotivity_base_OcResource
1339 * Method:    setHeaderOptions
1340 * Signature: ([Lorg/iotivity/OcHeaderOption;)V
1341 */
1342 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
1343 (JNIEnv *env, jobject thiz, jobjectArray jheaderOptionArr)
1344 {
1345     LOGD("OcResource_setHeaderOptions");
1346     if (!jheaderOptionArr)
1347     {
1348         ThrowOcException(OC_STACK_INVALID_PARAM, "headerOptionList cannot be null");
1349         return;
1350     }
1351     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1352     if (!resource) return;
1353
1354     HeaderOptions headerOptions;
1355     JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
1356
1357     resource->setHeaderOptions(headerOptions);
1358 }
1359
1360 /*
1361 * Class:     org_iotivity_base_OcResource
1362 * Method:    unsetHeaderOptions
1363 * Signature: ()V
1364 */
1365 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
1366 (JNIEnv *env, jobject thiz)
1367 {
1368     LOGD("OcResource_unsetHeaderOptions");
1369     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1370     if (!resource) return;
1371
1372     resource->unsetHeaderOptions();
1373 }
1374
1375 /*
1376 * Class:     org_iotivity_base_OcResource
1377 * Method:    getHost
1378 * Signature: ()Ljava/lang/String;
1379 */
1380 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
1381 (JNIEnv *env, jobject thiz)
1382 {
1383     LOGD("OcResource_getHost");
1384     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1385     if (!resource) return nullptr;
1386
1387     return env->NewStringUTF(resource->host().c_str());
1388 }
1389
1390 /*
1391 * Class:     org_iotivity_base_OcResource
1392 * Method:    getUri
1393 * Signature: ()Ljava/lang/String;
1394 */
1395 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
1396 (JNIEnv *env, jobject thiz)
1397 {
1398     LOGD("OcResource_getUri");
1399     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1400     if (!resource) return nullptr;
1401
1402     return env->NewStringUTF(resource->uri().c_str());
1403 }
1404
1405 /*
1406 * Class:     org_iotivity_base_OcResource
1407 * Method:    getConnectivityTypeN
1408 * Signature: ()I
1409 */
1410 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
1411 (JNIEnv *env, jobject thiz)
1412 {
1413     LOGD("OcResource_getConnectivityType");
1414     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1415     if (!resource) return -1;
1416
1417     OCConnectivityType connectivityType = resource->connectivityType();
1418     return static_cast<jint>(connectivityType);
1419 }
1420
1421 /*
1422 * Class:     org_iotivity_base_OcResource
1423 * Method:    isObservable
1424 * Signature: ()Z
1425 */
1426 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
1427 (JNIEnv *env, jobject thiz)
1428 {
1429     LOGD("OcResource_isObservable");
1430     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1431     return (jboolean)resource->isObservable();
1432 }
1433
1434 /*
1435 * Class:     org_iotivity_base_OcResource
1436 * Method:    getResourceTypes
1437 * Signature: ()Ljava/util/List;
1438 */
1439 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
1440 (JNIEnv *env, jobject thiz)
1441 {
1442     LOGD("OcResource_getResourceTypes");
1443     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1444     if (!resource) return nullptr;
1445
1446     std::vector<std::string> resourceTypes = resource->getResourceTypes();
1447
1448     return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
1449 }
1450
1451 /*
1452 * Class:     org_iotivity_base_OcResource
1453 * Method:    getResourceInterfaces
1454 * Signature: ()Ljava/util/List;
1455 */
1456 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterfaces
1457 (JNIEnv *env, jobject thiz)
1458 {
1459     LOGD("OcResource_getResourceInterfaces");
1460     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1461     if (!resource) return nullptr;
1462
1463     std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
1464
1465     return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
1466 }
1467
1468 /*
1469 * Class:     org_iotivity_base_OcResource
1470 * Method:    getUniqueIdentifier
1471 * Signature: ()Lorg/iotivity/base/OcResourceIdentifier;
1472 */
1473 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
1474 (JNIEnv *env, jobject thiz)
1475 {
1476     LOGD("OcResource_getUniqueIdentifier");
1477     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1478     if (!resource) return nullptr;
1479
1480     JniOcResourceIdentifier *jniResourceIdentifier =
1481         new JniOcResourceIdentifier(resource->uniqueIdentifier());
1482     if (!jniResourceIdentifier) return nullptr;
1483
1484     jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
1485     jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
1486         g_mid_OcResourceIdentifier_N_ctor, handle);
1487     if (!jResourceIdentifier)
1488     {
1489         delete jniResourceIdentifier;
1490     }
1491     return jResourceIdentifier;
1492 }
1493
1494 /*
1495 * Class:     org_iotivity_base_OcResource
1496 * Method:    getServerId
1497 * Signature: ()Ljava/lang/String;
1498 */
1499 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
1500 (JNIEnv *env, jobject thiz)
1501 {
1502     LOGD("OcResource_getServerId");
1503     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1504     if (!resource) return nullptr;
1505
1506     return env->NewStringUTF(resource->sid().c_str());
1507 }
1508
1509 /*
1510 * Class:     org_iotivity_base_OcResource
1511 * Method:    dispose
1512 * Signature: ()V
1513 */
1514 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
1515 (JNIEnv *env, jobject thiz)
1516 {
1517     LOGD("OcResource_dispose");
1518     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1519     delete resource;
1520 }