Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
msg_handler.cc
1 #include "msg_handler.h"
2 
3 #include "logging/logging.h"
4 
5 void MsgDispatcher::clearHandlers() { handler_map_.clear(); }
6 
7 void MsgDispatcher::registerHandler(AKIpUptaneMes_PR msg_id, Handler handler) {
8  handler_map_[msg_id] = std::move(handler);
9 }
10 
11 MsgHandler::ReturnCode MsgDispatcher::handleMsg(const Asn1Message::Ptr& in_msg, Asn1Message::Ptr& out_msg) {
12  auto find_res_it = handler_map_.find(in_msg->present());
13  if (find_res_it == handler_map_.end()) {
14  return MsgHandler::kUnkownMsg;
15  }
16  LOG_TRACE << "Found a handler for the request, processing it...";
17  auto handle_status_code = find_res_it->second(*in_msg, *out_msg);
18  LOG_TRACE << "Request handler returned a response: " << out_msg->toStr();
19 
20  // Track the last message to help cut down on repetitive logging. Ignore the
21  // version messages since they just get in the way.
22  if (in_msg->present() != AKIpUptaneMes_PR_versionReq) {
23  last_msg_ = in_msg->present();
24  }
25  return handle_status_code;
26 }