18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci#include "base_object.h" 168bf80f4bSopenharmony_ci 178bf80f4bSopenharmony_ci#include <base/util/uid_util.h> 188bf80f4bSopenharmony_ci#include <core/plugin/intf_class_factory.h> 198bf80f4bSopenharmony_ci 208bf80f4bSopenharmony_ci#include <meta/interface/builtin_objects.h> 218bf80f4bSopenharmony_ci#include <meta/interface/intf_object_registry.h> 228bf80f4bSopenharmony_ci#include <meta/interface/intf_proxy_object.h> 238bf80f4bSopenharmony_ci#include <meta/interface/property/intf_property_internal.h> 248bf80f4bSopenharmony_ci 258bf80f4bSopenharmony_ci#include "ref_uri_util.h" 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 288bf80f4bSopenharmony_cinamespace Internal { 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ci// IObject 318bf80f4bSopenharmony_ciInstanceId BaseObject::GetInstanceId() const 328bf80f4bSopenharmony_ci{ 338bf80f4bSopenharmony_ci return instanceId_; 348bf80f4bSopenharmony_ci} 358bf80f4bSopenharmony_ci 368bf80f4bSopenharmony_ciBASE_NS::string BaseObject::GetName() const 378bf80f4bSopenharmony_ci{ 388bf80f4bSopenharmony_ci return GetInstanceId().ToString(); 398bf80f4bSopenharmony_ci} 408bf80f4bSopenharmony_ci 418bf80f4bSopenharmony_ciIObject::Ptr BaseObject::Resolve(const RefUri& uri) const 428bf80f4bSopenharmony_ci{ 438bf80f4bSopenharmony_ci return DefaultResolveObject(me_.lock(), uri); 448bf80f4bSopenharmony_ci} 458bf80f4bSopenharmony_ci 468bf80f4bSopenharmony_ciIObject::Ptr BaseObject::GetSelf() const 478bf80f4bSopenharmony_ci{ 488bf80f4bSopenharmony_ci return me_.lock(); 498bf80f4bSopenharmony_ci} 508bf80f4bSopenharmony_ci 518bf80f4bSopenharmony_ciBASE_NS::vector<BASE_NS::Uid> BaseObject::GetInterfaces() const 528bf80f4bSopenharmony_ci{ 538bf80f4bSopenharmony_ci return IntroduceInterfaces::GetInterfacesVector(); 548bf80f4bSopenharmony_ci} 558bf80f4bSopenharmony_ci 568bf80f4bSopenharmony_ciObjectFlagBitsValue BaseObject::GetObjectFlags() const 578bf80f4bSopenharmony_ci{ 588bf80f4bSopenharmony_ci return flags_; 598bf80f4bSopenharmony_ci} 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_civoid BaseObject::SetObjectFlags(const ObjectFlagBitsValue& value) 628bf80f4bSopenharmony_ci{ 638bf80f4bSopenharmony_ci flags_ = value; 648bf80f4bSopenharmony_ci} 658bf80f4bSopenharmony_ci 668bf80f4bSopenharmony_ciObjectFlagBitsValue BaseObject::GetObjectDefaultFlags() const 678bf80f4bSopenharmony_ci{ 688bf80f4bSopenharmony_ci return ObjectFlagBits::DEFAULT_FLAGS; 698bf80f4bSopenharmony_ci} 708bf80f4bSopenharmony_ci 718bf80f4bSopenharmony_ci// IDerived 728bf80f4bSopenharmony_civoid BaseObject::SetSuperInstance(const IObject::Ptr& aggr, const IObject::Ptr& super) 738bf80f4bSopenharmony_ci{ 748bf80f4bSopenharmony_ci me_ = interface_pointer_cast<IObjectInstance>(aggr); 758bf80f4bSopenharmony_ci} 768bf80f4bSopenharmony_ciBASE_NS::Uid BaseObject::GetSuperClassUid() const 778bf80f4bSopenharmony_ci{ 788bf80f4bSopenharmony_ci // empty uid is "invalid", which means do not create a sub object ... 798bf80f4bSopenharmony_ci return {}; 808bf80f4bSopenharmony_ci} 818bf80f4bSopenharmony_ci 828bf80f4bSopenharmony_ci// ILifecycle 838bf80f4bSopenharmony_cibool BaseObject::Build(const IMetadata::Ptr&) 848bf80f4bSopenharmony_ci{ 858bf80f4bSopenharmony_ci // Set object flags to class default. 868bf80f4bSopenharmony_ci SetObjectFlags(GetObjectDefaultFlags()); 878bf80f4bSopenharmony_ci return true; 888bf80f4bSopenharmony_ci} 898bf80f4bSopenharmony_civoid BaseObject::SetInstanceId(InstanceId uid) 908bf80f4bSopenharmony_ci{ 918bf80f4bSopenharmony_ci instanceId_ = uid; 928bf80f4bSopenharmony_ci} 938bf80f4bSopenharmony_civoid BaseObject::Destroy() 948bf80f4bSopenharmony_ci{ 958bf80f4bSopenharmony_ci GetObjectRegistry().DisposeObject(instanceId_); 968bf80f4bSopenharmony_ci} 978bf80f4bSopenharmony_ci 988bf80f4bSopenharmony_ciIObjectRegistry& BaseObject::GetObjectRegistry() const 998bf80f4bSopenharmony_ci{ 1008bf80f4bSopenharmony_ci return META_NS::GetObjectRegistry(); 1018bf80f4bSopenharmony_ci} 1028bf80f4bSopenharmony_ci 1038bf80f4bSopenharmony_ci} // namespace Internal 1048bf80f4bSopenharmony_ci 1058bf80f4bSopenharmony_ciMETA_END_NAMESPACE() 106