2 * //******************************************************************
\r
4 * // Copyright 2015 Intel Corporation.
\r
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
8 * // Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * // you may not use this file except in compliance with the License.
\r
10 * // You may obtain a copy of the License at
\r
12 * // http://www.apache.org/licenses/LICENSE-2.0
\r
14 * // Unless required by applicable law or agreed to in writing, software
\r
15 * // distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * // See the License for the specific language governing permissions and
\r
18 * // limitations under the License.
\r
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
23 #include "JniOcStack.h"
\r
24 #include "OCRepresentation.h"
\r
29 static void convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap,
\r
30 OC::QueryParamsMap &map);
\r
31 static jobject convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryParamsMap &map);
\r
33 static jobject convertStrVectorToJavaStrList(JNIEnv *env, std::vector<std::string> &vector);
\r
34 static void convertJavaStrArrToStrVector(JNIEnv *env, jobjectArray jStrArr,
\r
35 std::vector<std::string> &vector);
\r
37 static void convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHeaderOptions,
\r
38 OC::HeaderOptions& headerOptions);
\r
39 static jobject convertHeaderOptionsVectorToJavaList(JNIEnv *env,
\r
40 const OC::HeaderOptions& headerOptions);
\r
42 static void convertJavaRepresentationArrToVector(JNIEnv *env,
\r
43 jobjectArray jRepresentationArray,
\r
44 std::vector<OC::OCRepresentation>& representationVector);
\r
45 static jobjectArray convertRepresentationVectorToJavaArray(JNIEnv *env,
\r
46 const std::vector<OC::OCRepresentation>& representationVector);
\r
48 static OC::ServiceType getServiceType(JNIEnv *env, int type)
\r
52 return OC::ServiceType::InProc;
\r
54 return OC::ServiceType::OutOfProc;
\r
56 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type");
\r
57 return OC::ServiceType::OutOfProc;
\r
61 static OC::ModeType getModeType(JNIEnv *env, int type)
\r
65 return OC::ModeType::Server;
\r
67 return OC::ModeType::Client;
\r
69 return OC::ModeType::Both;
\r
71 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type");
\r
72 return OC::ModeType::Both;
\r
76 static OC::QualityOfService getQOS(JNIEnv *env, int type)
\r
80 return OC::QualityOfService::LowQos;
\r
82 return OC::QualityOfService::MidQos;
\r
84 return OC::QualityOfService::HighQos;
\r
86 return OC::QualityOfService::NaQos;
\r
88 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service");
\r
89 return OC::QualityOfService::NaQos;
\r
93 static OC::ObserveType getObserveType(JNIEnv *env, int type)
\r
97 return OC::ObserveType::Observe;
\r
99 return OC::ObserveType::ObserveAll;
\r
101 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type");
\r
102 return OC::ObserveType::ObserveAll;
\r
106 static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type)
\r
110 return OCEntityHandlerResult::OC_EH_OK;
\r
112 return OCEntityHandlerResult::OC_EH_ERROR;
\r
114 return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED;
\r
116 return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED;
\r
118 return OCEntityHandlerResult::OC_EH_SLOW;
\r
120 return OCEntityHandlerResult::OC_EH_FORBIDDEN;
\r
122 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult");
\r
123 return OCEntityHandlerResult::OC_EH_ERROR;
\r
127 static OCConnectivityType getConnectivityType(JNIEnv *env, int type)
\r
131 return OCConnectivityType::CT_DEFAULT;
\r
133 return OCConnectivityType::CT_ADAPTER_IP;
\r
135 return OCConnectivityType::CT_ADAPTER_RFCOMM_BTEDR;
\r
137 return OCConnectivityType::CT_ADAPTER_GATT_BTLE;
\r
139 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected connectivity type");
\r
140 return OCConnectivityType::CT_DEFAULT;
\r
144 static std::string stackResultToStr(const int result)
\r
150 case OC_STACK_RESOURCE_CREATED:
\r
151 return "RESOURCE_CREATED";
\r
152 case OC_STACK_RESOURCE_DELETED:
\r
153 return "RESOURCE_DELETED";
\r
154 case OC_STACK_CONTINUE:
\r
156 /* Success status code - END HERE */
\r
157 /* Error status code - START HERE */
\r
158 case OC_STACK_INVALID_URI:
\r
159 return "INVALID_URI";
\r
160 case OC_STACK_INVALID_QUERY:
\r
161 return "INVALID_QUERY";
\r
162 case OC_STACK_INVALID_IP:
\r
163 return "INVALID_IP";
\r
165 case OC_STACK_INVALID_PORT:
\r
166 return "INVALID_PORT";
\r
167 case OC_STACK_INVALID_CALLBACK:
\r
168 return "INVALID_CALLBACK";
\r
169 case OC_STACK_INVALID_METHOD:
\r
170 return "INVALID_METHOD";
\r
171 case OC_STACK_INVALID_PARAM:
\r
172 return "INVALID_PARAM";
\r
173 case OC_STACK_INVALID_OBSERVE_PARAM:
\r
174 return "INVALID_OBSERVE_PARAM";
\r
175 case OC_STACK_NO_MEMORY:
\r
176 return "NO_MEMORY";
\r
177 case OC_STACK_COMM_ERROR:
\r
178 return "COMM_ERROR";
\r
179 case OC_STACK_NOTIMPL:
\r
181 case OC_STACK_NO_RESOURCE:
\r
182 return "NO_RESOURCE";
\r
183 case OC_STACK_RESOURCE_ERROR:
\r
184 return "RESOURCE_ERROR";
\r
185 case OC_STACK_SLOW_RESOURCE:
\r
186 return "SLOW_RESOURCE";
\r
187 //case OC_STACK_DUPLICATE_REQUEST:
\r
188 // return "DUPLICATE_REQUEST";
\r
189 case OC_STACK_NO_OBSERVERS:
\r
190 return "NO_OBSERVERS";
\r
191 case OC_STACK_OBSERVER_NOT_FOUND:
\r
192 return "OBSERVER_NOT_FOUND";
\r
193 case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
\r
194 return "VIRTUAL_DO_NOT_HANDLE";
\r
195 case OC_STACK_INVALID_OPTION:
\r
196 return "INVALID_OPTION";
\r
197 case OC_STACK_MALFORMED_RESPONSE:
\r
198 return "MALFORMED_RESPONSE";
\r
199 case OC_STACK_PERSISTENT_BUFFER_REQUIRED:
\r
200 return "PERSISTENT_BUFFER_REQUIRED";
\r
201 case OC_STACK_INVALID_REQUEST_HANDLE:
\r
202 return "INVALID_REQUEST_HANDLE";
\r
203 case OC_STACK_INVALID_DEVICE_INFO:
\r
204 return "INVALID_DEVICE_INFO";
\r
205 //case OC_STACK_INVALID_JSON:
\r
206 // return "INVALID_JSON";
\r
208 case OC_STACK_PRESENCE_STOPPED:
\r
209 return "PRESENCE_STOPPED";
\r
210 case OC_STACK_PRESENCE_TIMEOUT:
\r
211 return "PRESENCE_TIMEOUT";
\r
212 case OC_STACK_PRESENCE_DO_NOT_HANDLE:
\r
213 return "PRESENCE_DO_NOT_HANDLE";
\r
215 case OC_STACK_ERROR:
\r
218 case JNI_EXCEPTION:
\r
219 return "JNI_EXCEPTION";
\r
220 case JNI_NO_NATIVE_POINTER:
\r
221 return "JNI_NO_NATIVE_POINTER";
\r
222 case JNI_INVALID_VALUE:
\r
223 return "JNI_INVALID_VALUE";
\r