PLCnext API Documentation 25.0.2.69
ComponentBase.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
7#ifndef ARP_USE_ARP_SYSTEM_ACF_COMMONS
8#include "Arp/Base/Acf/Commons/ComponentBase.hpp"
9namespace Arp::System::Acf
10{
12}
13#else
14#include "Arp/System/Core/Arp.h"
15#include "Arp/System/Acf/ILibrary.hpp"
16#include "Arp/System/Acf/IComponent.hpp"
17#include "Arp/Base/Rsc/Commons/Services/IRscServiceFactory.hpp"
18
19namespace Arp { namespace System { namespace Acf
20{
21
22using namespace Arp::Base::Rsc::Commons;
23
29class ComponentBase : public IComponent
30{
31public: // construction/destruction
40 IApplication& application,
41 ILibrary& library,
42 const String& fullName,
43 ComponentCategory category,
44 uint32 startOrder = GetDefaultStartOrder(),
45 bool isSingleton = false);
46
48 ~ComponentBase(void)override = default;
49
50public: // properties
51 IApplication& GetApplication(void)const final;
52 ILibrary& GetLibrary(void)const final;
53 String GetFullName(void)const final;
54 ArpVersion GetVersion(void)const final;
55 ComponentCategory GetComponentCategory(void)const final;
56 uint32 GetStartOrder(void)const final;
57 bool IsSingleton(void)const final;
58 bool IsRequired(void)const final;
59
60public: // static
61 static uint32 GetDefaultStartOrder(void);
62
63public: // IComponent operations
64 void Initialize(void)override;
65 void LoadSettings(const String& settingsPath)override;
66 void SetupSettings(void)override;
67 void SubscribeServices(void)override;
68 void PublishServices(void)override;
69 void LoadConfig(void)override;
70 void SetupConfig(void)override;
71 void ResetConfig(void)override;
72 void Dispose(void)override;
73 void PowerDown(void)override;
74
75protected: // service operations used by derived items
80 template<class TService, class TServiceFactory>
81 void PublishComponentService(void);
82
83private: // methods
84 void PublishComponentService(const char* serviceName, IRscServiceFactory* pServiceFactory);
85
86private: // deleted methods
87 ComponentBase(const ComponentBase& arg) = delete;
88 ComponentBase& operator=(const ComponentBase& arg) = delete;
89
90private: // fields
91 IApplication& application;
92 ILibrary& library;
93 String fullName;
94 ComponentCategory componentCategory = ComponentCategory::None;
95 uint32 startOrder = 0;
96 bool isSingleton = false;
97 bool isRequired = false;
98
99private: // static fields
100 static const uint32 maxComponentStartOrder;
101 static const uint32 customComponentStartOrderShift;
102};
103
105// inline methods of class ComponentBase
106
107inline IApplication& ComponentBase::GetApplication()const
108{
109 return this->application;
110}
111
113{
114 return this->library;
115}
116
118{
119 return this->fullName;
120}
121
122inline ArpVersion ComponentBase::GetVersion(void)const
123{
124 return this->library.GetBuildVersion();
125}
126
127inline ComponentCategory ComponentBase::GetComponentCategory(void)const
128{
129 return this->componentCategory;
130}
131
132inline uint32 ComponentBase::GetStartOrder(void)const
133{
134 return this->startOrder;
135}
136
137inline bool ComponentBase::IsSingleton()const
138{
139 return this->isSingleton;
140}
141
142inline bool ComponentBase::IsRequired()const
143{
144 return this->isRequired;
145}
146
147template<class TService, class TServiceFactory>
148inline void ComponentBase::PublishComponentService()
149{
150 this->PublishComponentService(TService::GetProxyFactory().GetServiceName(), TServiceFactory::Create(*this));
151}
152
153}}} // end of namesapce Arp::System::Acf
154#endif // ndef ARP_USE_ARP_SYSTEM_ACF_COMMONS
Use this class as base class of all Acf components.
Definition: ComponentBase.hpp:20
ILibrary & GetLibrary(void) const final
Gets the library instance of this component.
Definition: ComponentBase.cpp:70
~ComponentBase(void) override
The default destructor.
static uint32 GetDefaultStartOrder(void)
Gets the default start order of a component which is DomainsStartOrder::Custom.
Definition: ComponentBase.cpp:58
void Initialize(void) override
Initializes this component: creates singletons, makes any registrations, creates any resources not de...
Definition: ComponentBase.cpp:106
void SubscribeServices(void) override
Subscribes services required by this component.
Definition: ComponentBase.cpp:124
uint32 GetStartOrder(void) const final
Gets the start order of this component.
Definition: ComponentBase.cpp:88
void PublishServices(void) override
Publishes components services.
Definition: ComponentBase.cpp:130
void LoadSettings(const String &settingsPath) override
Loads components firmware settings.
Definition: ComponentBase.cpp:112
bool IsRequired(void) const override
Determines if this component is required.
Definition: ComponentBase.cpp:94
void LoadConfig(void) override
Loads components project configuration.
Definition: ComponentBase.cpp:136
void PowerDown(void) override
This operation is called on a power breakdown event and executes component specific actions when powe...
Definition: ComponentBase.cpp:160
void Dispose(void) override
Disposes this component.
Definition: ComponentBase.cpp:154
ComponentCategory GetComponentCategory(void) const final
Gets the ComponentCategory of this component.
Definition: ComponentBase.cpp:82
void SetupSettings(void) override
Sets up components settings which were loaded in LoadSettings.
Definition: ComponentBase.cpp:118
Application & GetApplication(void) const final
Gets the application instance of the actual process which loaded this component.
Definition: ComponentBase.cpp:64
ComponentBase(ILibrary &library, const String &fullName, ComponentCategory category, uint32 startOrder)
Constructs an ComponentBase instance.
Definition: ComponentBase.cpp:51
String GetFullName(void) const final
Gets the full qualified name of this component
Definition: ComponentBase.cpp:76
void SetupConfig(void) override
Sets up components configuration which was loaded in LoadConfig.
Definition: ComponentBase.cpp:142
void ResetConfig(void) override
Resets components project configuration.
Definition: ComponentBase.cpp:148
This is the most important basic interface of the Arp platform. Any component shall implement this in...
Definition: IComponent.hpp:79
Any Acf Library shall implement this interface.
Definition: ILibrary.hpp:20
This class compounds Arp build version and infos.
Definition: ArpVersion.hpp:21
const Version & GetBuildVersion(void) const
Gets the versions of this ArpVersion.
Definition: ArpVersion.cpp:141
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Interface for service factory classes to create instances of the service implementation,...
Definition: IRscServiceFactory.hpp:26
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:33
This is the namespace of the Application Component Framework.
Definition: ComponentBase.hpp:72
Root namespace for the PLCnext API