summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc
blob: ebe687d67a0c5c09144413ca592d3423fa7e9363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "application_manager/application_manager.h"
#include "application_manager/commands/mobile/unsubscribe_way_points_request.h"

namespace application_manager {

namespace commands {

UnSubscribeWayPointsRequest::UnSubscribeWayPointsRequest(
    const MessageSharedPtr& message, ApplicationManager& application_manager)
    : CommandRequestImpl(message, application_manager) {}

UnSubscribeWayPointsRequest::~UnSubscribeWayPointsRequest() {}

void UnSubscribeWayPointsRequest::Run() {
  LOGGER_AUTO_TRACE(logger_);

  ApplicationSharedPtr app = application_manager_.application(connection_key());

  if (!app) {
    LOGGER_ERROR(logger_,
                 "An application with connection key "
                     << connection_key() << " is not registered.");
    SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED);
    return;
  }

  if (!application_manager_.IsAppSubscribedForWayPoints(app->app_id())) {
    SendResponse(false, mobile_apis::Result::IGNORED);
    return;
  }

  SendHMIRequest(
      hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints, NULL, true);
}

void UnSubscribeWayPointsRequest::on_event(const event_engine::Event& event) {
  LOGGER_AUTO_TRACE(logger_);
  ApplicationSharedPtr app = application_manager_.application(connection_key());
  const smart_objects::SmartObject& message = event.smart_object();
  switch (event.id()) {
    case hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints: {
      LOGGER_INFO(logger_, "Received Navigation_UnSubscribeWayPoints event");
      mobile_apis::Result::eType result_code =
          GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>(
              message[strings::params][hmi_response::code].asUInt()));
      bool result = mobile_apis::Result::SUCCESS == result_code;
      if (result) {
        application_manager_.UnsubscribeAppFromWayPoints(app->app_id());
      }
      SendResponse(result, result_code, NULL, &(message[strings::msg_params]));
      break;
    }
    default: {
      LOGGER_ERROR(logger_, "Received unknown event" << event.id());
      break;
    }
  }
}

}  // namespace commands

}  // namespace application_manager