node_communication/include/context.h
2025-07-30 09:38:43 +08:00

31 lines
657 B
C++

#pragma once
#include "core.h"
#include <memory>
/**
* @brief
*
*/
class IpcRequestReplyContext {
private:
std::unique_ptr<IpcRequestReplyInterface> strategy;
public:
void setStrategy(std::unique_ptr<IpcRequestReplyInterface> newStrategy) {
strategy = std::move(newStrategy);
}
std::expected<void, std::string> send(const std::string& message) {
if (strategy) {
return strategy->send(message);
}
return std::unexpected("Not Found Strategy");
}
std::expected<std::string, std::string> receive() {
if (strategy) {
return strategy->receive();
}
return std::unexpected("Not Found Strategy");
}
};