8 #include "Arp/System/Core/Singleton.hxx"    14 #ifdef ARP_PLATFORM_LINUX    22 namespace Arp { 
namespace System { 
namespace Acf
    36 #ifdef ARP_PLATFORM_LINUX    44     RdLockGuard(pthread_rwlock_t* rw_lock);
    47     RdLockGuard(
const RdLockGuard& arg) = 
delete;
    50     RdLockGuard& operator=(
const RdLockGuard& arg) = 
delete;
    56     pthread_rwlock_t* rw_lock;
    62 inline RdLockGuard::RdLockGuard(pthread_rwlock_t* rw_lockArg)
    65     pthread_rwlock_rdlock(rw_lock);
    68 inline RdLockGuard::~RdLockGuard()
    70     pthread_rwlock_unlock(rw_lock);
    81     WrLockGuard(pthread_rwlock_t* rw_lock);
    84     WrLockGuard(
const WrLockGuard& arg) = 
delete;
    87     WrLockGuard& operator=(
const WrLockGuard& arg) = 
delete;
    93     pthread_rwlock_t* rw_lock;
    99 inline WrLockGuard::WrLockGuard(pthread_rwlock_t* rw_lockArg)
   100     : rw_lock(rw_lockArg)
   102     pthread_rwlock_wrlock(rw_lock);
   105 inline WrLockGuard::~WrLockGuard()
   107     pthread_rwlock_unlock(rw_lock);
   109 #endif //ARP_PLATFORM_LINUX   127     typedef void(*SingletonDisposer)(void);
   129     typedef std::type_index                 TypeKey;
   130     typedef std::map<TypeKey, void*>        Singletons;
   136     AppDomain(
const AppDomain& arg) = 
delete;
   143     static bool IsCreated(
void);
   147     static AppDomain&   GetCurrent(
void);
   154     static TApp&        
Create(
void);
   166     static void         Dispose(
void);
   171     static void         Assign(AppDomain& other);
   182     template<
class TSingleton>
   183     void            AddSingleton(TSingleton* pSingleton);
   188     template<
class TSingleton>
   189     TSingleton&     GetSingleton(
void);
   194     template<
class TSingleton>
   195     TSingleton*     GetSingletonPtr(
void);
   200     template<
class TSingleton>
   201     bool            RemoveSingleton(
void);
   205     static TypeKey  GetTypeKey(
void);
   209     Singletons      singletons;
   211 #ifdef ARP_PLATFORM_LINUX   212     pthread_rwlock_t rw_lock;
   220 inline AppDomain::AppDomain()
   221     : pApplication(
nullptr)
   224 #ifdef ARP_PLATFORM_LINUX   225     pthread_rwlock_init(&this->rw_lock, NULL);
   231     return SingletonBase::IsCreated();
   236     return SingletonBase::GetInstance();
   240 inline AppDomain::TypeKey AppDomain::GetTypeKey(
void)
   242     return std::type_index(
typeid(T));
   249     SingletonBase::CreateInstance();
   251     TApp::CreateInstance();
   253     SingletonBase::GetInstance().pApplication = TApp::GetInstancePtr();
   255     return dynamic_cast<TApp&
>(TApp::GetInstance());
   262     SingletonBase::CreateInstance();
   264     TApp::CreateInstance(appName);
   266     SingletonBase::GetInstance().pApplication = TApp::GetInstancePtr();
   268     return dynamic_cast<TApp&
>(TApp::GetInstance());
   273     if (!SingletonBase::IsCreated())
   275         SingletonBase::AssignInstanceFrom(other);
   282     TApp::DisposeInstance();
   283     SingletonBase::DisposeInstance();
   288     return *(this->pApplication);
   291 template<
class TSingleton>
   294 #ifdef ARP_PLATFORM_LINUX   295     WrLockGuard lock(&this->rw_lock);
   297     std::lock_guard<std::mutex> lock(this->rw_lock);
   301     auto result = this->singletons.insert(make_pair(AppDomain::GetTypeKey<TSingleton>(), pSingleton));
   308 template<
class TSingleton>
   311     TSingleton* pResult = this->GetSingletonPtr<TSingleton>();
   312     if (pResult == 
nullptr)
   318 template<
class TSingleton>
   321 #ifdef ARP_PLATFORM_LINUX   322     RdLockGuard lock(&this->rw_lock);
   324     std::lock_guard<std::mutex> lock(this->rw_lock);
   327     auto i = this->singletons.find(AppDomain::GetTypeKey<TSingleton>());
   328     if (i == this->singletons.end())
   333     return (TSingleton*)(i->second); 
   336 template<
class TSingleton>
   339 #ifdef ARP_PLATFORM_LINUX   340     WrLockGuard lock(&this->rw_lock);
   342     std::lock_guard<std::mutex> lock(this->rw_lock);
   345     return this->singletons.erase(AppDomain::GetTypeKey<TSingleton>()) != 0;
 bool RemoveSingleton(void)
Removes the singleton pointer of the specified type from this AppDomain.
Definition: AppDomain.hpp:337
 
This (meta programming) class provides the C++ typename of the as template argument passed type...
Definition: TypeName.hxx:55
 
Namespace of the C++ standard library
 
static void Assign(AppDomain &other)
Assgins the current AppdDomain singleton from the as argument passed other.
Definition: AppDomain.hpp:271
 
TSingleton & GetSingleton(void)
Gets the singleton instance of the specified type.
Definition: AppDomain.hpp:309
 
void AddSingleton(TSingleton *pSingleton)
Adds a singleton instance to this AppDomain.
Definition: AppDomain.hpp:292
 
This interface shall be implemented by the application class.
Definition: IApplication.hpp:18
 
This class represents a single application domain for each process and is implemented as singleton...
Definition: AppDomain.hpp:122
 
This class implements the singleton pattern.
Definition: Singleton.hxx:24
 
static XmlWriter Create(const String &filename, bool indent, const char *encoding="UTF-8")
Creates a new Instance of the XmlWriter 
 
IApplication & GetApplication(void)
Gets the application instance of the current process.
Definition: AppDomain.hpp:286
 
Root namespace for the PLCnext API
 
static bool IsCreated(void)
Determines if the appdomain was created yet.
Definition: AppDomain.hpp:229
 
TSingleton * GetSingletonPtr(void)
Gets the singleton pointer of the specified type.
Definition: AppDomain.hpp:319
 
static AppDomain & GetCurrent(void)
Gets the current AppDomain instance.
Definition: AppDomain.hpp:234
 
static TApp & Create(void)
Creates the current AppDomain and application instances.
Definition: AppDomain.hpp:246
 
System components used by the System, Device, Plc or Io domains.
 
This is the base class of all Arp exception classes.
Definition: Exception.hpp:15
 
Namespace of the Application Component Framework (ACF)
 
static void Dispose(void)
Disposes the current AppDomain and destructs the application.
Definition: AppDomain.hpp:280