1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PROCESS_SYSTEM_API_ADAPTER_H
17 #define PROCESS_SYSTEM_API_ADAPTER_H
18 
19 #include <string>
20 #include <map>
21 #include <mutex>
22 
23 #include "iprocess_system_api_adapter.h"
24 #include "store_types.h"
25 
26 namespace DistributedDB {
27 class ProcessSystemApiAdapterImpl : public IProcessSystemApiAdapter {
28 public:
29     ProcessSystemApiAdapterImpl();
30     ~ProcessSystemApiAdapterImpl() override;
31     DBStatus RegOnAccessControlledEvent(const OnAccessControlledEvent &callback) override;
32     bool IsAccessControlled() const override;
33     DBStatus SetSecurityOption(const std::string &filePath, const SecurityOption &option) override;
34     DBStatus GetSecurityOption(const std::string &filePath, SecurityOption &option) const override;
35     bool CheckDeviceSecurityAbility(const std::string &devId, const SecurityOption &option) const override;
36     void SetLockStatus(bool isLock);
37     void SetNeedCreateDb(bool isCreate);
38     void ResetSecOptDic();
39     void ResetAdapter();
40 
41     void ForkGetSecurityOption(std::function<DBStatus (const std::string &, SecurityOption &)> callBack);
42     void ForkCheckDeviceSecurityAbility(std::function<bool (const std::string &, const SecurityOption &)> callBack);
43 
44     std::map<const std::string, SecurityOption> GetExistSecOpt() const;
45 private:
46     mutable std::mutex adapterlock_;
47     OnAccessControlledEvent callback_;
48     std::map<const std::string, SecurityOption> pathSecOptDic_;
49     bool isLocked_;
50     bool createDb_;
51     std::function<DBStatus (const std::string &, SecurityOption &)> getSecurityOptionCallBack_;
52     std::function<bool (const std::string &, const SecurityOption &)> checkDeviceCallBack_;
53 };
54 } // namespace DistributedDB
55 
56 #endif
57