Skip to content

Commit

Permalink
improve: remove qodana and fix eventcallback error (opentibiabr#2958)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Oct 9, 2024
1 parent aff5014 commit 95dbe28
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/lua/callbacks/events_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,8 @@ class EventsCallbacks {
void executeCallback(EventCallback_t eventType, CallbackFunc callbackFunc, Args &&... args) {
for (const auto &[name, callback] : getCallbacksByType(eventType)) {
if (callback && callback->isLoadedCallback()) {
auto argsCopy = std::make_tuple(args...);
std::apply(
[callback, &callbackFunc](auto &&... args) {
((*callback).*callbackFunc)(std::forward<decltype(args)>(args)...);
},
argsCopy
);
g_logger().trace("Executed callback: {}", name);
std::invoke(callbackFunc, *callback, std::forward<Args>(args)...);
// g_logger().trace("Executed callback: {}", name);
}
}
}
Expand All @@ -111,22 +105,15 @@ class EventsCallbacks {
*/
template <typename CallbackFunc, typename... Args>
ReturnValue checkCallbackWithReturnValue(EventCallback_t eventType, CallbackFunc callbackFunc, Args &&... args) {
ReturnValue res = RETURNVALUE_NOERROR;
for (const auto &[name, callback] : getCallbacksByType(eventType)) {
auto argsCopy = std::make_tuple(args...);
if (callback && callback->isLoadedCallback()) {
ReturnValue callbackResult = std::apply(
[&callback, &callbackFunc](auto &&... args) {
return ((*callback).*callbackFunc)(std::forward<decltype(args)>(args)...);
},
argsCopy
);
ReturnValue callbackResult = std::invoke(callbackFunc, *callback, std::forward<Args>(args)...);
if (callbackResult != RETURNVALUE_NOERROR) {
return callbackResult;
}
}
}
return res;
return RETURNVALUE_NOERROR;
}

/**
Expand All @@ -139,17 +126,10 @@ class EventsCallbacks {
template <typename CallbackFunc, typename... Args>
bool checkCallback(EventCallback_t eventType, CallbackFunc callbackFunc, Args &&... args) {
bool allCallbacksSucceeded = true;

for (const auto &[name, callback] : getCallbacksByType(eventType)) {
if (callback && callback->isLoadedCallback()) {
auto argsCopy = std::make_tuple(args...);
bool callbackResult = std::apply(
[callback, &callbackFunc](auto &&... args) {
return ((*callback).*callbackFunc)(std::forward<decltype(args)>(args)...);
},
argsCopy
);
allCallbacksSucceeded = allCallbacksSucceeded && callbackResult;
bool callbackResult = std::invoke(callbackFunc, *callback, std::forward<Args>(args)...);
allCallbacksSucceeded &= callbackResult;
}
}
return allCallbacksSucceeded;
Expand Down

0 comments on commit 95dbe28

Please sign in to comment.