M2-PT-DRP/source/events/search/SearchEvent.cpp

45 lines
1.1 KiB
C++

#include "SearchEvent.hpp"
#include <cerrno>
#include <sys/socket.h>
#include <cstring>
#include <iostream>
#include <ostream>
#include "../../tasks/types.hpp"
#include "../../events/types.hpp"
namespace drp {
void event::SearchEvent::handle(const packet::GenericPacketContent& content) {
packet::GenericPacket packet {};
packet::GenericPacketContent packetContent {};
Information information {};
information.status = task::TaskType::UNDEFINED;
packet.channel = 0;
packet.securityMode = static_cast<std::uint8_t>(packet::SecurityMode::PLAIN);
packetContent.eventType = static_cast<std::uint8_t>(EventType::INFO);
std::memcpy(&packetContent.data, &information, sizeof(Information));
packet.setContent(packetContent);
if (sendto(
clientSocket,
&packet,
sizeof(packet),
0,
serverAddress,
serverAddressLength
) == -1)
std::cerr << "[Receiver] Could not send information: " << strerror(errno) << std::endl;
std::cout << "[Receiver] Sent information." << std::endl;
}
}