• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2024 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef TOOLS_GN_OHOS_COMPONENTS_H_
6 #define TOOLS_GN_OHOS_COMPONENTS_H_
7 
8 #include <map>
9 #include <mutex>
10 
11 #include "base/files/file_path.h"
12 #include "base/values.h"
13 #include "gn/err.h"
14 #include "gn/value.h"
15 
16 
17 class OhosComponent {
18 public:
19     OhosComponent();
20     OhosComponent(const char *name, const char *subsystem, const char *path);
21 
name()22     const std::string &name() const
23     {
24         return name_;
25     }
subsystem()26     const std::string &subsystem() const
27     {
28         return subsystem_;
29     }
path()30     const std::string &path() const
31     {
32         return path_;
33     }
34 
35     void addInnerApi(const std::string &name, const std::string &label);
36 
37     const std::string &getInnerApi(const std::string &innerapi) const;
38 
39     void addInnerApiVisibility(const std::string &name, const std::vector<base::Value> &list);
40 
41     const std::vector<std::string> getInnerApiVisibility(const std::string &label) const;
42 
43     bool isInnerApi(const std::string &label) const;
44 
45 private:
46     std::string name_;
47     std::string subsystem_;
48     std::string path_;
49 
50     // InnerApi name to label map
51     std::map<std::string, std::string> innerapi_names_;
52 
53     // InnerApi label to name map
54     std::map<std::string, std::string> innerapi_labels_;
55 
56     // InnerApi lable to visibility map
57     std::map<std::string, std::vector<std::string>> innerapi_visibility_;
58 
59     OhosComponent &operator = (const OhosComponent &) = delete;
60 };
61 
62 class OhosComponentsImpl;
63 
64 class OhosComponents {
65 public:
66     OhosComponents();
67 
68     bool LoadOhosComponents(const std::string &build_dir, const Value *enable, Err *err);
69     bool isOhosComponentsLoaded() const;
70 
71     bool GetExternalDepsLabel(const Value &external_dep, std::string &label, Err *err) const;
72     bool GetSubsystemName(const Value &part_name, std::string &label, Err *err) const;
73 
74     const OhosComponent *GetComponentByLabel(const std::string &label) const;
75 
76     void LoadOhosComponentsChecker(const std::string &build_dir, const Value *support, int checkType);
77 
78 private:
79     OhosComponentsImpl *mgr = nullptr;
80 
81     OhosComponents &operator = (const OhosComponents &) = delete;
82 };
83 
84 #endif // TOOLS_GN_OHOS_COMPONENTS_H_
85