Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniOcSecurity.cpp
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  *
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  ******************************************************************/
21 #include "JniOcSecurity.h"
22 #include "JniOcStack.h"
23
24 /*
25  * TODO: Persistant Storage Handling should be done by App.
26  * For 0.9.2 , Handling is done at JNI. As of now Plaform Config only
27  * SVR Database fileName(fullpath) is passed.
28  */
29 using namespace std;
30 namespace PH = std::placeholders;
31 namespace OC {
32
33     string& JniOcSecurity::store_path()
34     {
35         static string s_dbPath;
36         return s_dbPath;
37     }
38
39     void JniOcSecurity::StoreDbPath(const string &path)
40     {
41         store_path() = path;
42     }
43
44     OCPersistentStorage* JniOcSecurity::getOCPersistentStorage()
45     {
46         if (store_path().empty())
47         {
48             return nullptr;
49         }
50         static OCPersistentStorage s_ps { &JniOcSecurity::client_open, fread,
51             fwrite, fclose, unlink };
52         return &s_ps;
53     }
54
55     FILE* JniOcSecurity::client_open(const char *path, const char *mode)
56     {
57         LOGI("Opening SVR Database file '%s' with mode '%s'\n", store_path().c_str(), mode);
58         return fopen(store_path().c_str(), mode);
59     }
60 }