• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 CORE_RESOURCES_RESOURCE_MANAGER_H
17 #define CORE_RESOURCES_RESOURCE_MANAGER_H
18 
19 #include <mutex>
20 
21 #include <base/containers/unordered_map.h>
22 #include <core/plugin/intf_interface_helper.h>
23 #include <core/resources/intf_resource_manager.h>
24 
25 CORE_BEGIN_NAMESPACE()
26 class IEngine;
27 
28 class ResourceManager final : public IInterfaceHelper<IResourceManager> {
29 public:
30     explicit ResourceManager(IEngine& engine);
31     ~ResourceManager();
32 
33     const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
34     IInterface* GetInterface(const BASE_NS::Uid& uid) override;
35 
36     // IResourceManager
37     Status Import(BASE_NS::string_view url) override;
38     BASE_NS::vector<BASE_NS::string> GetResourceUris(BASE_NS::string_view url) const override;
39     BASE_NS::vector<BASE_NS::string> GetResourceUris(
40         BASE_NS::string_view url, BASE_NS::Uid resourceType) const override;
41     IResource::Ptr GetResource(BASE_NS::string_view url) override;
42     IResource::Ptr GetResource(BASE_NS::string_view groupUri, BASE_NS::string_view uri) override;
43 
44     Status Export(BASE_NS::string_view groupUri, BASE_NS::string_view filePath) override;
45     void AddResource(BASE_NS::string_view groupUri, const IResource::Ptr& resource) override;
46     void RemoveResource(BASE_NS::string_view groupUri, const IResource::Ptr& resource) override;
47     void RemoveResources(BASE_NS::string_view groupUri) override;
48 
49 private:
50     struct ImportFile;
51     struct ExportData;
52     ExportData GatherExportData(BASE_NS::string_view groupUri) const;
53 
54     std::mutex mutex_;
55     IEngine& engine_;
56     // import url to file
57     BASE_NS::unordered_map<BASE_NS::string, ImportFile> importedFiles_;
58     // resource uri to resource
59     BASE_NS::unordered_map<BASE_NS::string, IResource::Ptr> importedResources_;
60 };
61 CORE_END_NAMESPACE()
62 #endif // CORE_RESOURCES_RESOURCE_MANAGER_H
63