33 #include "core/GpgFrontendCoreExport.h"
34 #include "core/function/basic/ChannelObject.h"
35 #include "core/function/basic/SingletonStorage.h"
36 #include "core/function/basic/SingletonStorageCollection.h"
37 #include "core/utils/MemoryUtils.h"
42 const std::type_info& type,
int channel) -> ChannelObject*;
44 auto GPGFRONTEND_CORE_EXPORT CreateChannelObjectInstance(
45 const std::type_info& type,
int channel,
46 SecureUniquePtr<ChannelObject> channel_object) -> ChannelObject*;
48 auto GPGFRONTEND_CORE_EXPORT
49 GetGlobalFunctionObjectTypeLock(
const std::type_info& type) -> std::mutex&;
79 static auto GetInstance(
int channel = GpgFrontend::kGpgFrontendDefaultChannel)
82 "T not derived from SingletonFunctionObject<T>");
84 const auto& type =
typeid(T);
85 std::lock_guard<std::mutex> guard(GetGlobalFunctionObjectTypeLock(type));
87 if (channel_object ==
nullptr) {
88 channel_object = CreateChannelObjectInstance(
90 ConvertToChannelObjectPtr(SecureCreateUniqueObject<T>(channel)));
92 return *
static_cast<T*
>(channel_object);
103 int channel,
const std::function<ChannelObjectPtr(
void)>& factory) -> T& {
105 "T not derived from SingletonFunctionObject<T>");
107 const auto& type =
typeid(T);
108 std::lock_guard<std::mutex> guard(GetGlobalFunctionObjectTypeLock(type));
109 return *
static_cast<T*
>(
110 CreateChannelObjectInstance(type, channel, factory()));
121 ->GetSingletonStorage(
typeid(T))
122 ->ReleaseChannel(channel);
150 ->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:57
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:184
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:139
auto operator=(const SingletonFunctionObject< T > &) -> SingletonFunctionObject &=delete
prohibit copy
static auto GetAllChannelId() -> std::vector< int >
Get all the channel ids.
Definition: GpgFunctionObject.h:148
SingletonFunctionObject(T &&)=delete
Construct a new Singleton Function Object object.
static void ReleaseChannel(int channel)
Definition: GpgFunctionObject.h:119
static auto GetInstance(int channel=GpgFrontend::kGpgFrontendDefaultChannel) -> T &
Get the Instance object.
Definition: GpgFunctionObject.h:79
static auto GetDefaultChannel() -> int
Get the Default Channel object.
Definition: GpgFunctionObject.h:130
static auto CreateInstance(int channel, const std::function< ChannelObjectPtr(void)> &factory) -> T &
Create a Instance object.
Definition: GpgFunctionObject.h:102
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