2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "JniOcStack.h"
24 #include "OCRepresentation.h"
29 static void convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap,
30 OC::QueryParamsMap &map);
31 static jobject convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryParamsMap &map);
33 static jobject convertStrVectorToJavaStrList(JNIEnv *env, std::vector<std::string> &vector);
34 static void convertJavaStrArrToStrVector(JNIEnv *env, jobjectArray jStrArr,
35 std::vector<std::string> &vector);
37 static void convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHeaderOptions,
38 OC::HeaderOptions& headerOptions);
39 static jobject convertHeaderOptionsVectorToJavaList(JNIEnv *env,
40 const OC::HeaderOptions& headerOptions);
42 static void convertJavaRepresentationArrToVector(JNIEnv *env,
43 jobjectArray jRepresentationArray,
44 std::vector<OC::OCRepresentation>& representationVector);
45 static jobjectArray convertRepresentationVectorToJavaArray(JNIEnv *env,
46 const std::vector<OC::OCRepresentation>& representationVector);
48 static OC::ServiceType getServiceType(JNIEnv *env, int type)
53 return OC::ServiceType::InProc;
55 return OC::ServiceType::OutOfProc;
57 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type");
58 return OC::ServiceType::OutOfProc;
62 static OC::ModeType getModeType(JNIEnv *env, int type)
67 return OC::ModeType::Server;
69 return OC::ModeType::Client;
71 return OC::ModeType::Both;
73 return OC::ModeType::Gateway;
75 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type");
76 return OC::ModeType::Both;
80 static OC::QualityOfService getQOS(JNIEnv *env, int type)
85 return OC::QualityOfService::LowQos;
87 return OC::QualityOfService::MidQos;
89 return OC::QualityOfService::HighQos;
91 return OC::QualityOfService::NaQos;
93 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service");
94 return OC::QualityOfService::NaQos;
98 static OC::ObserveType getObserveType(JNIEnv *env, int type)
103 return OC::ObserveType::Observe;
105 return OC::ObserveType::ObserveAll;
107 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type");
108 return OC::ObserveType::ObserveAll;
112 static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type)
117 return OCEntityHandlerResult::OC_EH_OK;
119 return OCEntityHandlerResult::OC_EH_ERROR;
121 return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED;
123 return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED;
125 return OCEntityHandlerResult::OC_EH_SLOW;
127 return OCEntityHandlerResult::OC_EH_FORBIDDEN;
129 return OCEntityHandlerResult::OC_EH_RESOURCE_NOT_FOUND;
131 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult");
132 return OCEntityHandlerResult::OC_EH_ERROR;
136 static std::string stackResultToStr(const int result)
140 /** Success status code - START HERE.*/
143 case OC_STACK_RESOURCE_CREATED:
144 return "RESOURCE_CREATED";
145 case OC_STACK_RESOURCE_DELETED:
146 return "RESOURCE_DELETED";
147 case OC_STACK_CONTINUE:
149 /* Error status code - START HERE */
150 case OC_STACK_INVALID_URI:
151 return "INVALID_URI";
152 case OC_STACK_INVALID_QUERY:
153 return "INVALID_QUERY";
154 case OC_STACK_INVALID_IP:
156 case OC_STACK_INVALID_PORT:
157 return "INVALID_PORT";
158 case OC_STACK_INVALID_CALLBACK:
159 return "INVALID_CALLBACK";
160 case OC_STACK_INVALID_METHOD:
161 return "INVALID_METHOD";
162 /** Invalid parameter.*/
163 case OC_STACK_INVALID_PARAM:
164 return "INVALID_PARAM";
165 case OC_STACK_INVALID_OBSERVE_PARAM:
166 return "INVALID_OBSERVE_PARAM";
167 case OC_STACK_NO_MEMORY:
169 case OC_STACK_COMM_ERROR:
171 case OC_STACK_TIMEOUT:
173 case OC_STACK_ADAPTER_NOT_ENABLED:
174 return "ADAPTER_NOT_ENABLED";
175 case OC_STACK_NOTIMPL:
177 /** Resource not found.*/
178 case OC_STACK_NO_RESOURCE:
179 return "NO_RESOURCE";
180 /** e.g: not supported method or interface.*/
181 case OC_STACK_RESOURCE_ERROR:
182 return "RESOURCE_ERROR";
183 case OC_STACK_SLOW_RESOURCE:
184 return "SLOW_RESOURCE";
185 case OC_STACK_DUPLICATE_REQUEST:
186 return "DUPLICATE_REQUEST";
187 /** Resource has no registered observers.*/
188 case OC_STACK_NO_OBSERVERS:
189 return "NO_OBSERVERS";
190 case OC_STACK_OBSERVER_NOT_FOUND:
191 return "OBSERVER_NOT_FOUND";
192 case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
193 return "VIRTUAL_DO_NOT_HANDLE";
194 case OC_STACK_INVALID_OPTION:
195 return "INVALID_OPTION";
196 /** The remote reply contained malformed data.*/
197 case OC_STACK_MALFORMED_RESPONSE:
198 return "MALFORMED_RESPONSE";
199 case OC_STACK_PERSISTENT_BUFFER_REQUIRED:
200 return "PERSISTENT_BUFFER_REQUIRED";
201 case OC_STACK_INVALID_REQUEST_HANDLE:
202 return "INVALID_REQUEST_HANDLE";
203 case OC_STACK_INVALID_DEVICE_INFO:
204 return "INVALID_DEVICE_INFO";
205 case OC_STACK_INVALID_JSON:
206 return "INVALID_JSON";
207 /** Request is not authorized by Resource Server. */
208 case OC_STACK_UNAUTHORIZED_REQ:
209 return "UNAUTHORIZED_REQ";
210 /** Error code from PDM */
211 case OC_STACK_PDM_IS_NOT_INITIALIZED:
212 return "PDM_IS_NOT_INITIALIZED";
213 case OC_STACK_DUPLICATE_UUID:
214 return "DUPLICATE_UUID";
215 case OC_STACK_INCONSISTENT_DB:
216 return "INCONSISTENT_DB";
217 /** Error code from OTM */
218 case OC_STACK_AUTHENTICATION_FAILURE:
219 return "AUTHENTICATION_FAILURE";
220 /** Insert all new error codes here!.*/
222 case OC_STACK_PRESENCE_STOPPED:
223 return "PRESENCE_STOPPED";
224 case OC_STACK_PRESENCE_TIMEOUT:
225 return "PRESENCE_TIMEOUT";
226 case OC_STACK_PRESENCE_DO_NOT_HANDLE:
227 return "PRESENCE_DO_NOT_HANDLE";
233 return "JNI_EXCEPTION";
234 case JNI_NO_NATIVE_POINTER:
235 return "JNI_NO_NATIVE_POINTER";
236 case JNI_INVALID_VALUE:
237 return "JNI_INVALID_VALUE";