• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_CONFIG_FACTORY_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_CONFIG_FACTORY_H
18 #include <cstdint>
19 #include <list>
20 #include <string>
21 #include "serializable.h"
22 #include "visibility.h"
23 namespace OHOS {
24 namespace DataShare {
25 
26 class DataShareConfig final : public Serializable {
27 public:
28     struct Bundle final : public Serializable {
29         std::string name;
30         std::string appIdentifier;
31         bool Marshal(Serializable::json &node) const override;
32         bool Unmarshal(const Serializable::json &node) override;
33     };
34     struct ConsumerProvider final : public Serializable {
35         std::vector<Bundle> consumer;
36         Bundle provider;
37         bool Marshal(Serializable::json &node) const override;
38         bool Unmarshal(const Serializable::json &node) override;
39     };
40     bool Marshal(Serializable::json &node) const override;
41     bool Unmarshal(const Serializable::json &node) override;
42     std::vector<std::string> dataShareExtNames;
43     std::vector<std::string> uriTrusts;
44     std::vector<ConsumerProvider> extensionObsTrusts;
45 };
46 
47 class GlobalConfig final : public Serializable {
48 public:
49     DataShareConfig *dataShare = nullptr;
50     ~GlobalConfig();
51     bool Marshal(json &node) const override;
52     bool Unmarshal(const json &node) override;
53 };
54 
55 class ConfigFactory {
56 public:
57     API_EXPORT static ConfigFactory &GetInstance();
58     API_EXPORT int32_t Initialize();
59     API_EXPORT DataShareConfig *GetDataShareConfig();
60 private:
61     static constexpr const char *CONF_PATH = "/system/etc/distributeddata/conf";
62     ConfigFactory();
63     ~ConfigFactory();
64 
65     std::string file_;
66     GlobalConfig config_;
67     bool isInited = false;
68 };
69 } // namespace DistributedData
70 } // namespace OHOS
71 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_CONFIG_FACTORY_H
72