1
0
mirror of synced 2024-11-28 09:30:51 +01:00
ImHex/main/source/messaging/common.cpp
iTrooz 1ed658bcdc
feat: Added command line interface support (#1172)
System design has been discussed on discord

Should fix #948

---------

Co-authored-by: WerWolv <werwolv98@gmail.com>
2023-07-13 14:08:23 +02:00

34 lines
1.1 KiB
C++

#include <optional>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/logger.hpp>
#include "messaging.hpp"
namespace hex::messaging {
void messageReceived(const std::string &eventName, const std::vector<u8> &eventData) {
log::debug("Received event '{}' with size {}", eventName, eventData.size());
ImHexApi::Messaging::impl::runHandler(eventName, eventData);
}
void setupEvents() {
EventManager::subscribe<SendMessageToMainInstance>([](const std::string eventName, const std::vector<u8> &eventData) {
log::debug("Forwarding message {} (maybe to us)", eventName);
if (ImHexApi::System::isMainInstance()) {
EventManager::subscribe<EventImHexStartupFinished>([eventName, eventData](){
ImHexApi::Messaging::impl::runHandler(eventName, eventData);
});
} else {
sendToOtherInstance(eventName, eventData);
}
});
}
void setupMessaging() {
ImHexApi::System::impl::setMainInstanceStatus(setupNative());
setupEvents();
}
}