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 #include "resource_container.h"
16
17 #include <scene_plugin/api/resource_container_uid.h>
18 #include <scene_plugin/interface/intf_resource_container.h>
19
20 #include <meta/ext/attachment/attachment.h>
21 #include <meta/ext/concrete_base_object.h>
22
23 using namespace SCENE_NS;
24
25 namespace {
26 class ResourceContainer
27 : public META_NS::AttachmentFwd<ResourceContainer, ClassId::ResourceContainer, IResourceContainer> {
28 using Super = META_NS::AttachmentFwd<ResourceContainer, ClassId::ResourceContainer, IResourceContainer>;
29 using Super::Super;
30
Build(const IMetadata::Ptr & data)31 bool Build(const IMetadata::Ptr& data) override
32 {
33 if (auto p = META_NS::ConstructProperty<META_NS::IContainer::Ptr>("Resources")) {
34 auto container = META_NS::GetObjectRegistry().Create<META_NS::IContainer>(META_NS::ClassId::ObjectFlatContainer);
35 p->SetValue(container);
36 AddProperty(p);
37 }
38
39 return true;
40 }
41
GetResources()42 META_NS::IContainer::Ptr GetResources() override
43 {
44 auto property = GetPropertyByName("Resources");
45 if (META_NS::Property<META_NS::IContainer::Ptr> cp { property }) {
46 return GetValue(cp);
47 }
48 return {};
49 }
50
AttachTo(const META_NS::IAttach::Ptr & target,const IObject::Ptr & dataContext)51 bool AttachTo(const META_NS::IAttach::Ptr& target, const IObject::Ptr& dataContext) override
52 {
53 return true;
54 }
55
DetachFrom(const META_NS::IAttach::Ptr & target)56 bool DetachFrom(const META_NS::IAttach::Ptr& target) override
57 {
58 return true;
59 }
60
61 private:
62 META_NS::IContainer::Ptr container_;
63 };
64
65 } // namespace
SCENE_BEGIN_NAMESPACE()66 SCENE_BEGIN_NAMESPACE()
67 void RegisterResourceContainerImpl()
68 {
69 META_NS::GetObjectRegistry().RegisterObjectType<ResourceContainer>();
70 }
UnregisterResourceContainerImpl()71 void UnregisterResourceContainerImpl()
72 {
73 META_NS::GetObjectRegistry().UnregisterObjectType<ResourceContainer>();
74 }
75 SCENE_END_NAMESPACE()
76