PLCnext API Documentation  22.9.0.33
ProgramProviderBase.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/event.hxx"
9 #include "Arp/Plc/Commons/Esm/IProgramProvider.hpp"
10 #include <map>
11 
12 namespace Arp { namespace Plc { namespace Commons { namespace Esm
13 {
14 
16 {
17 public: // typedefs/usings
18  using Programs = std::map<String, IProgram::Ptr>; // [ProgramName, ProgramPtr]
19 
20 private: // typedefs/usings
21  using ProgramTypes = std::map<String, String>; // [ProgramName, ProgramTypeName]
22 
23 public: // construction/destruction
25  ProgramProviderBase(void) = default;
31  ~ProgramProviderBase(void) = default;
32 
33 public: // events
34  event<IProgram::Ptr> ProgramAdded;
35  event<IProgram::Ptr> ProgramRemoved;
36 
37 public: // setter/getter operations
38  Programs& GetPrograms(void);
39  const Programs& GetPrograms(void)const;
40 
41 public: // operations
42  bool RemoveProgram(IProgram& program);
43 
44 public: // IProgramProvider operations to override
45  IProgram::Ptr CreateProgram(const String& programName, const String& programType)override;
46  void Reset(void)override;
47 
48 protected: // abstract operations to override (templated method design pattern)
49  virtual IProgram::Ptr CreateProgramInternal(const String& programName, const String& programType) = 0;
50 
51 protected: // operations
52 
53 private: // methods
54 
55 private: // fields
56  Programs programs;
57  ProgramTypes programTypes;
58 };
59 
61 // inline methods of class ProgramProviderBase
62 inline ProgramProviderBase::Programs& ProgramProviderBase::GetPrograms()
63 {
64  return this->programs;
65 }
66 
67 inline const ProgramProviderBase::Programs& ProgramProviderBase::GetPrograms()const
68 {
69  return this->programs;
70 }
71 
72 }}}} // end of namespace Arp::Plc::Commons::Esm
Interface to realizes an program provider.
Definition: IProgramProvider.hpp:17
Interface to implement PLC program to be executed in realtime context.
Definition: IProgram.hpp:19
std::shared_ptr< IProgram > Ptr
Shared pointer type of IProgram.
Definition: IProgram.hpp:22
Definition: ProgramProviderBase.hpp:16
~ProgramProviderBase(void)=default
Destructs this instance and frees all resources.
IProgram::Ptr CreateProgram(const String &programName, const String &programType) override
Creates an instance of an program type.
ProgramProviderBase(const ProgramProviderBase &arg)=default
Copy constructor.
ProgramProviderBase(void)=default
Constructs an ProgramProviderBase instance.
ProgramProviderBase & operator=(const ProgramProviderBase &arg)=default
Assignment operator.
void Reset(void) override
Resets the program provider.
Root namespace for the PLCnext API