ACF $AcfVersion:0$
CCompositeComponent.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7#include <QtCore/QMap>
8#include <QtCore/QReadWriteLock>
9#include <QtCore/QRecursiveMutex>
10#include <QtCore/QWaitCondition>
11
12// ACF includes
13#include <istd/CClassInfo.h>
14#include <istd/TSmartPtr.h>
16#include <icomp/IRegistry.h>
19
20
21namespace icomp
22{
23
24
25class IMetaInfoManager;
26
27
30 virtual public ICompositeComponent
31{
32public:
33 CCompositeComponent(bool manualAutoInit);
35
39 template <class InterfaceType>
40 InterfaceType* GetComponentInterface(const QByteArray& subId = "");
41
47
48 // reimplemented (icomp::ICompositeComponent)
49 virtual IComponentSharedPtr GetSubcomponent(const QByteArray& componentId) const override;
50 virtual IComponentContextSharedPtr GetSubcomponentContext(const QByteArray& componentId) const override;
51 virtual IComponentUniquePtr CreateSubcomponent(const QByteArray& componentId) const override;
52 virtual void OnSubcomponentDeleted(const IComponent* subcomponentPtr) override;
53
54 // reimplemented (icomp::IComponent)
55 virtual const icomp::IComponent* GetParentComponent(bool ownerOnly = false) const override;
56 virtual void* GetInterface(const istd::CClassInfo& interfaceType, const QByteArray& subId = "") override;
58 virtual void SetComponentContext(
59 const IComponentContextSharedPtr& contextPtr,
60 const icomp::IComponent* parentPtr,
61 bool isParentOwner) override;
62
63protected:
73 const QByteArray& componentId,
74 IComponentContextSharedPtr& subContextPtr,
75 IComponentUniquePtr* subComponentPtr,
76 bool isOwned) const;
77
78private:
79 struct ComponentInfo;
80
81 bool InitializeSubcomponentInfo(
82 const QByteArray& componentId,
83 ComponentInfo& componentInfo,
84 bool isOwned) const;
85
86
87private:
88 enum ComponentState
89 {
90 CS_NONE,
91 CS_INIT,
92 CS_READY,
93 CS_DESTROYED
94 };
95
96 struct ComponentInfo
97 {
98 ComponentInfo()
99 :componentState(CS_NONE),
100 isContextInitialized(false)
101 {
102 }
103
107 IComponentSharedPtr componentPtr;
108
113 ComponentState componentState = CS_NONE;
114
123 bool isContextInitialized;
124 };
125
126 typedef QMap<QByteArray, ComponentInfo> ComponentMap;
127
128 mutable ComponentMap m_componentMap;
129
130 IComponentContextSharedPtr m_contextPtr;
131 const icomp::ICompositeComponent* m_parentPtr;
132 bool m_isParentOwner;
133
134 bool m_manualAutoInit;
135
136 mutable bool m_autoInitialized;
137 mutable IRegistry::Ids m_autoInitComponentIds;
138
139#if QT_VERSION >= 0x060000
140 mutable QRecursiveMutex m_mutex;
141#else
142 mutable QMutex m_mutex;
143#endif
144};
145
146
147// inline methods
148
149template <class InterfaceType>
150inline InterfaceType* CCompositeComponent::GetComponentInterface(const QByteArray& subId)
151{
152 static istd::CClassInfo info(typeid(InterfaceType));
153
154 return static_cast<InterfaceType*>(GetInterface(info, subId));
155}
156
157
158} // namespace icomp
159
160
161
162
virtual IComponentContextSharedPtr GetSubcomponentContext(const QByteArray &componentId) const override
Get access to context of subcomponent using its ID.
virtual IComponentSharedPtr GetSubcomponent(const QByteArray &componentId) const override
Get access to subcomponent using its ID.
CCompositeComponent(bool manualAutoInit)
bool EnsureAutoInitComponentsCreated() const
Make sure, all components with flag 'AutoInit' are initialized.
bool CreateSubcomponentInfo(const QByteArray &componentId, IComponentContextSharedPtr &subContextPtr, IComponentUniquePtr *subComponentPtr, bool isOwned) const
Create information objects and subcomponent.
virtual IComponentUniquePtr CreateSubcomponent(const QByteArray &componentId) const override
Create instance of subcomponent using its ID.
InterfaceType * GetComponentInterface(const QByteArray &subId="")
Get interface implemented by this composite component.
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="") override
Get access to specified component interface.
virtual void OnSubcomponentDeleted(const IComponent *subcomponentPtr) override
Called if subcomponent is removed from memory.
virtual const icomp::IComponent * GetParentComponent(bool ownerOnly=false) const override
Get parent of this component.
virtual void SetComponentContext(const IComponentContextSharedPtr &contextPtr, const icomp::IComponent *parentPtr, bool isParentOwner) override
Set component context of this component.
virtual IComponentContextSharedPtr GetComponentContext() const override
Get access to component context describing all application-specified component information loaded fro...
Main component interface.
Definition IComponent.h:32
Composite component interface.
QSet< QByteArray > Ids
Definition IRegistry.h:50
Represents platform independent type info and provide set of static class manipulation functions.
Definition CClassInfo.h:23
Package with interfaces and class used for components concept.
std::unique_ptr< IComponent > IComponentUniquePtr
Definition IComponent.h:72
std::shared_ptr< icomp::IComponentContext > IComponentContextSharedPtr
std::shared_ptr< IComponent > IComponentSharedPtr
Definition IComponent.h:71