2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "tzplatform_config.h"
23 extern bool __has_iot_privilege();
25 static bool handle_array[MAX_RRS_HANDLE] = {false};
28 #define RRS_SECURITY_FILEPATH tzplatform_mkpath(TZ_USER_SHARE, "rrs/rrs-svr-db.dat")
30 EXPORT_API int rrs_create(rrs_h *rrs)
35 /* Check if parameters are valid */
37 return RRS_ERROR_INVALID_PARAMETER;
39 /* Check if privileges enough */
40 if (!__has_iot_privilege())
41 return RRS_ERROR_PERMISSION_DENIED;
45 while (handle_array[value] == true)
49 handle_array[value] = true;
52 if (*rrs > MAX_RRS_HANDLE) {
53 ERR("Maximum limit for RRS handles reached");
54 return RRS_ERROR_SERVICE_NOT_AVAILABLE;
57 INFO("Path: %s", RRS_SECURITY_FILEPATH);
60 ret = iotcon_initialize(RRS_SECURITY_FILEPATH);
61 if (ret != IOTCON_ERROR_NONE) {
62 ERR("iotcon_initialize() Fail(%d)", ret);
63 return RRS_ERROR_SERVICE_NOT_AVAILABLE;
66 return RRS_ERROR_NONE;
69 EXPORT_API int rrs_destroy(const rrs_h rrs)
71 /* Check if RRS handle is valid */
72 if (rrs < 1 || rrs > MAX_RRS_HANDLE)
73 return RRS_ERROR_INVALID_PARAMETER;
75 /* Check if privileges enough */
76 if (!__has_iot_privilege())
77 return RRS_ERROR_PERMISSION_DENIED;
81 handle_array[rrs] = false;
84 /* disconnect iotcon */
85 iotcon_deinitialize();
87 return RRS_ERROR_NONE;