mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-08 18:56:41 +08:00
fix(log): use constructor template instead of class template for initiator
- src/libipc/platform/win/get_sa.h: * Change from class template to constructor template * Keep 'struct initiator' as a regular class (not template) * Make constructor a function template: template <typename Logger> initiator(Logger const &log) * Instantiate as: static initiator handle(log); * This is valid C++ as function templates can be defined inside functions * Fixes the issue that class templates cannot be defined inside functions The constructor template approach allows proper logger passing while maintaining valid C++ syntax for local struct definitions.
This commit is contained in:
parent
afd1467e03
commit
72eedeb6c4
@ -8,12 +8,12 @@ namespace detail {
|
|||||||
inline LPSECURITY_ATTRIBUTES get_sa() {
|
inline LPSECURITY_ATTRIBUTES get_sa() {
|
||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
|
|
||||||
template <typename Logger>
|
|
||||||
struct initiator {
|
struct initiator {
|
||||||
SECURITY_DESCRIPTOR sd_;
|
SECURITY_DESCRIPTOR sd_;
|
||||||
SECURITY_ATTRIBUTES sa_;
|
SECURITY_ATTRIBUTES sa_;
|
||||||
bool succ_ = false;
|
bool succ_ = false;
|
||||||
|
|
||||||
|
template <typename Logger>
|
||||||
initiator(Logger const &log) {
|
initiator(Logger const &log) {
|
||||||
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
||||||
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
||||||
@ -30,7 +30,7 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static initiator<decltype(log)> handle(log);
|
static initiator handle(log);
|
||||||
return handle.succ_ ? &handle.sa_ : nullptr;
|
return handle.succ_ ? &handle.sa_ : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user