rad 6.2.0
Loading...
Searching...
No Matches
msgHandler.hpp
Go to the documentation of this file.
1
9#ifndef RAD_MSG_HANDLER_HPP
10#define RAD_MSG_HANDLER_HPP
11
12#include <rad/exceptions.hpp>
13
14#include <memory>
15#include <string>
16#include <unordered_map>
17
18namespace rad {
19
24 public:
25 virtual ~MsgHandler() {}
36 virtual void Handle(const std::string& identity, const std::string& msg_type_id,
37 const void* data, size_t data_size) = 0;
38};
39
48template <typename EventType>
49EventType ParseRequestAndCreateEvent(const std::string& identity, const std::string& request_name,
50 const void* msg, size_t msg_size) {
51 // Check that requestId matches the event)
52#if 0
53 if (strcmp(request_name.c_str(), EventType::id) != 0) {
54 throw rad::Exception("Error request_name <" + request_name +
55 "> payload type, does not match eventId <" + EventType::id + ">.");
56 }
57#endif
58
59 // EventType = rad::MsgRequest<ProtoBuf_Type>
60 // msg_payload_t = ProtoBuf_Type
61 using msg_payload_t = typename EventType::payload_t::payload_t;
62 msg_payload_t req_payload;
63
64 if (req_payload.ParseFromArray(msg, msg_size) == false) {
65 throw rad::Exception("Error parsing <" + request_name + "> payload.");
66 }
67
68 return EventType(identity.c_str(), req_payload);
69}
70
71} // namespace rad
72
73#endif /* #ifndef RAD_MSG_HANDLER_HPP */
Base class for the exceptions thrown by RAD and its users.
Definition exceptions.hpp:53
Definition msgHandler.hpp:23
virtual void Handle(const std::string &identity, const std::string &msg_type_id, const void *data, size_t data_size)=0
virtual ~MsgHandler()
Definition msgHandler.hpp:25
Exception classes header file.
Definition actionsApp.cpp:23
EventType ParseRequestAndCreateEvent(const std::string &identity, const std::string &request_name, const void *msg, size_t msg_size)
Definition msgHandler.hpp:49