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)
52 return OC::ServiceType::InProc;
54 return OC::ServiceType::OutOfProc;
56 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type");
57 return OC::ServiceType::OutOfProc;
61 static OC::ModeType getModeType(JNIEnv *env, int type)
65 return OC::ModeType::Server;
67 return OC::ModeType::Client;
69 return OC::ModeType::Both;
71 return OC::ModeType::Gateway;
73 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type");
74 return OC::ModeType::Both;
78 static OC::QualityOfService getQOS(JNIEnv *env, int type)
82 return OC::QualityOfService::LowQos;
84 return OC::QualityOfService::MidQos;
86 return OC::QualityOfService::HighQos;
88 return OC::QualityOfService::NaQos;
90 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service");
91 return OC::QualityOfService::NaQos;
95 static OC::ObserveType getObserveType(JNIEnv *env, int type)
99 return OC::ObserveType::Observe;
101 return OC::ObserveType::ObserveAll;
103 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type");
104 return OC::ObserveType::ObserveAll;
108 static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type)
112 return OCEntityHandlerResult::OC_EH_OK;
114 return OCEntityHandlerResult::OC_EH_ERROR;
116 return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED;
118 return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED;
120 return OCEntityHandlerResult::OC_EH_SLOW;
122 return OCEntityHandlerResult::OC_EH_FORBIDDEN;
124 ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult");
125 return OCEntityHandlerResult::OC_EH_ERROR;
129 static std::string stackResultToStr(const int result)
133 /** Success status code - START HERE.*/
136 case OC_STACK_RESOURCE_CREATED:
137 return "RESOURCE_CREATED";
138 case OC_STACK_RESOURCE_DELETED:
139 return "RESOURCE_DELETED";
140 case OC_STACK_CONTINUE:
142 /* Error status code - START HERE */
143 case OC_STACK_INVALID_URI:
144 return "INVALID_URI";
145 case OC_STACK_INVALID_QUERY:
146 return "INVALID_QUERY";
147 case OC_STACK_INVALID_IP:
149 case OC_STACK_INVALID_PORT:
150 return "INVALID_PORT";
151 case OC_STACK_INVALID_CALLBACK:
152 return "INVALID_CALLBACK";
153 case OC_STACK_INVALID_METHOD:
154 return "INVALID_METHOD";
155 /** Invalid parameter.*/
156 case OC_STACK_INVALID_PARAM:
157 return "INVALID_PARAM";
158 case OC_STACK_INVALID_OBSERVE_PARAM:
159 return "INVALID_OBSERVE_PARAM";
160 case OC_STACK_NO_MEMORY:
162 case OC_STACK_COMM_ERROR:
164 case OC_STACK_TIMEOUT:
166 case OC_STACK_ADAPTER_NOT_ENABLED:
167 return "ADAPTER_NOT_ENABLED";
168 case OC_STACK_NOTIMPL:
170 /** Resource not found.*/
171 case OC_STACK_NO_RESOURCE:
172 return "NO_RESOURCE";
173 /** e.g: not supported method or interface.*/
174 case OC_STACK_RESOURCE_ERROR:
175 return "RESOURCE_ERROR";
176 case OC_STACK_SLOW_RESOURCE:
177 return "SLOW_RESOURCE";
178 case OC_STACK_DUPLICATE_REQUEST:
179 return "DUPLICATE_REQUEST";
180 /** Resource has no registered observers.*/
181 case OC_STACK_NO_OBSERVERS:
182 return "NO_OBSERVERS";
183 case OC_STACK_OBSERVER_NOT_FOUND:
184 return "OBSERVER_NOT_FOUND";
185 case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
186 return "VIRTUAL_DO_NOT_HANDLE";
187 case OC_STACK_INVALID_OPTION:
188 return "INVALID_OPTION";
189 /** The remote reply contained malformed data.*/
190 case OC_STACK_MALFORMED_RESPONSE:
191 return "MALFORMED_RESPONSE";
192 case OC_STACK_PERSISTENT_BUFFER_REQUIRED:
193 return "PERSISTENT_BUFFER_REQUIRED";
194 case OC_STACK_INVALID_REQUEST_HANDLE:
195 return "INVALID_REQUEST_HANDLE";
196 case OC_STACK_INVALID_DEVICE_INFO:
197 return "INVALID_DEVICE_INFO";
198 case OC_STACK_INVALID_JSON:
199 return "INVALID_JSON";
200 /** Request is not authorized by Resource Server. */
201 case OC_STACK_UNAUTHORIZED_REQ:
202 return "UNAUTHORIZED_REQ";
203 /** Error code from PDM */
204 case OC_STACK_PDM_IS_NOT_INITIALIZED:
205 return "PDM_IS_NOT_INITIALIZED";
206 case OC_STACK_DUPLICATE_UUID:
207 return "DUPLICATE_UUID";
208 case OC_STACK_INCONSISTENT_DB:
209 return "INCONSISTENT_DB";
210 /** Insert all new error codes here!.*/
212 case OC_STACK_PRESENCE_STOPPED:
213 return "PRESENCE_STOPPED";
214 case OC_STACK_PRESENCE_TIMEOUT:
215 return "PRESENCE_TIMEOUT";
216 case OC_STACK_PRESENCE_DO_NOT_HANDLE:
217 return "PRESENCE_DO_NOT_HANDLE";
223 return "JNI_EXCEPTION";
224 case JNI_NO_NATIVE_POINTER:
225 return "JNI_NO_NATIVE_POINTER";
226 case JNI_INVALID_VALUE:
227 return "JNI_INVALID_VALUE";