Properly defined URI & Resource Type values for Presence Advertisement.
[contrib/iotivity.git] / android / Base / app / jni / platformcfg-jni.cpp
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 #include "ocstack-jni.h"
22
23 static const char* TAG = "PLATFORMCFG-JNI";
24
25 OC::ServiceType getServiceType(int type)
26 {
27     switch (type) {
28         case 0:
29             return OC::ServiceType::InProc;
30         case 1:
31         default:
32             return OC::ServiceType::OutOfProc;
33     };
34 }
35
36 OC::ModeType getModeType(int type)
37 {
38     switch (type) {
39         case 0:
40             return OC::ModeType::Server;
41         case 1:
42             return OC::ModeType::Client;
43         case 2:
44         default:
45             return OC::ModeType::Both;
46     };
47 }
48
49 OC::QualityOfService getQOS(int type)
50 {
51     switch (type) {
52         case 0:
53             return OC::QualityOfService::LowQos;
54         case 1:
55             return OC::QualityOfService::MidQos;
56         case 2:
57             return OC::QualityOfService::HighQos;
58         case 3:
59         default:
60             return OC::QualityOfService::NaQos;
61     };
62 }
63
64 OC::PlatformConfig *g_cfg;
65
66 JNIEXPORT jlong JNICALL createNativeInstance
67   (JNIEnv *env, jobject obj, jint jServiceType, jint jModeType, jstring jIpAddress, jint port, jint jQOS)
68 {
69
70     g_cfg = new OC::PlatformConfig{getServiceType(jServiceType),
71                             getModeType(jModeType),
72                             env->GetStringUTFChars(jIpAddress, 0),
73                             (uint16_t) port,
74                             getQOS(jQOS)
75     };
76
77
78     jlong instptr = reinterpret_cast<jlong>(g_cfg);
79     return instptr;
80 }