34 #include "core/GpgFrontendCoreExport.h"
35 #include "core/function/basic/ChannelObject.h"
36 #include "core/function/basic/SingletonStorage.h"
37 #include "core/function/basic/SingletonStorageCollection.h"
38 #include "core/utils/MemoryUtils.h"
43 const std::type_info& type,
int channel) -> ChannelObject*;
45 auto GPGFRONTEND_CORE_EXPORT CreateChannelObjectInstance(
46 const std::type_info& type,
int channel,
47 SecureUniquePtr<ChannelObject> channel_object) -> ChannelObject*;
49 auto GPGFRONTEND_CORE_EXPORT
50 GetGlobalFunctionObjectTypeLock(
const std::type_info& type) -> std::mutex&;
80 static auto GetInstance(
int channel = GpgFrontend::kGpgFrontendDefaultChannel)
83 "T not derived from SingletonFunctionObject<T>");
85 const auto& type =
typeid(T);
86 std::lock_guard<std::mutex> guard(GetGlobalFunctionObjectTypeLock(type));
88 if (channel_object ==
nullptr) {
89 channel_object = CreateChannelObjectInstance(
91 ConvertToChannelObjectPtr(SecureCreateUniqueObject<T>(channel)));
93 return *
static_cast<T*
>(channel_object);
104 int channel,
const std::function<ChannelObjectPtr(
void)>& factory) -> T& {
106 "T not derived from SingletonFunctionObject<T>");
108 const auto& type =
typeid(T);
109 std::lock_guard<std::mutex> guard(GetGlobalFunctionObjectTypeLock(type));
110 return *
static_cast<T*
>(
111 CreateChannelObjectInstance(type, channel, factory()));
122 ->GetSingletonStorage(
typeid(T))
123 ->ReleaseChannel(channel);
151 ->GetSingletonStorage(
typeid(T))
object which in channel system is called "channel"
Definition: ChannelObject.h:39
auto GetChannel() const -> int
Get the Channel object.
Definition: ChannelObject.cpp:53
static auto GetDefaultChannel() -> int
Get the Default Channel object.
Definition: ChannelObject.cpp:55
Definition: GpgFunctionObject.h:58
SingletonFunctionObject()=default
Construct a new Singleton Function Object object.
SingletonFunctionObject(const SingletonFunctionObject< T > &)=delete
prohibit copy
SingletonFunctionObject(int channel)
Construct a new Singleton Function Object object.
Definition: GpgFunctionObject.h:185
SingletonFunctionObject(const T &)=delete
Construct a new Singleton Function Object object.
virtual ~SingletonFunctionObject()=default
Destroy the Singleton Function Object object.
auto GetChannel() const -> int
Get the Channel object.
Definition: GpgFunctionObject.h:140
auto operator=(const SingletonFunctionObject< T > &) -> SingletonFunctionObject &=delete
prohibit copy
static auto GetAllChannelId() -> std::vector< int >
Get all the channel ids.
Definition: GpgFunctionObject.h:149
SingletonFunctionObject(T &&)=delete
Construct a new Singleton Function Object object.
static void ReleaseChannel(int channel)
Definition: GpgFunctionObject.h:120
static auto GetInstance(int channel=GpgFrontend::kGpgFrontendDefaultChannel) -> T &
Get the Instance object.
Definition: GpgFunctionObject.h:80
static auto GetDefaultChannel() -> int
Get the Default Channel object.
Definition: GpgFunctionObject.h:131
static auto CreateInstance(int channel, const std::function< ChannelObjectPtr(void)> &factory) -> T &
Create a Instance object.
Definition: GpgFunctionObject.h:103
static auto GetInstance(bool force_refresh) -> SingletonStorageCollection *
Get the Instance object.
Definition: SingletonStorageCollection.cpp:107
auto GetChannelObjectInstance(const std::type_info &type, int channel) -> ChannelObject *
Get the Instance object.
Definition: GpgFunctionObject.cpp:67