Improve named event handling
This commit is contained in:
@@ -13,10 +13,12 @@ namespace openVulkanoCpp
|
||||
class NamedEventProcessor final : public INamedEventProcessor
|
||||
{
|
||||
std::vector<std::string> m_classNamePrefixes, m_classNameSuffixes;
|
||||
bool m_useClassNameAsEventName;
|
||||
public:
|
||||
NamedEventProcessor()
|
||||
NamedEventProcessor(bool classNameAsEventName = false)
|
||||
: m_classNamePrefixes({ "", "Event" })
|
||||
, m_classNameSuffixes({ "Event", "" })
|
||||
, m_useClassNameAsEventName(classNameAsEventName)
|
||||
{}
|
||||
|
||||
void RegisterClassNamePrefix(const std::string& prefix) { m_classNamePrefixes.push_back(prefix); }
|
||||
|
||||
@@ -122,11 +122,11 @@ namespace openVulkanoCpp
|
||||
|
||||
void NamedEventProcessor::Notify(const std::string& eventName, const std::vector<Parameters>& parameters) const
|
||||
{
|
||||
if (auto eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName))
|
||||
if (Class eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName))
|
||||
{
|
||||
if (auto init = GetInitForClass(eventClass, BuildTypeName(parameters)))
|
||||
if (SEL init = GetInitForClass(eventClass, BuildTypeName(parameters)))
|
||||
{
|
||||
auto event = [eventClass alloc];
|
||||
NSObject* event = [eventClass alloc];
|
||||
auto inv = [NSInvocation invocationWithMethodSignature:[event methodSignatureForSelector:init]];
|
||||
[inv setTarget:event];
|
||||
[inv setSelector:init];
|
||||
@@ -138,17 +138,20 @@ namespace openVulkanoCpp
|
||||
[inv invoke];
|
||||
for (Class clazz = eventClass; clazz && clazz != NSObject.class; clazz = class_getSuperclass(clazz))
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSStringFromClass(clazz) object:event userInfo:nil];
|
||||
NSString* notificationName;
|
||||
if (m_useClassNameAsEventName) notificationName = NSStringFromClass(clazz);
|
||||
else notificationName = [NSString stringWithUTF8String:eventName.c_str()];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:event userInfo:nil];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::MANAGER->error("Cannot find viable constructor for event %s", eventName.c_str());
|
||||
Logger::MANAGER->error("Cannot find constructor for named event %s", eventName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::MANAGER->debug("Cannot find implementation for event %s", eventName);
|
||||
Logger::MANAGER->debug("Cannot find implementation for named event %s", eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user