summaryrefslogtreecommitdiff
path: root/src/components/remote_control/include/remote_control/resource_allocation_manager.h
blob: 9e5d5fdd9838a4ed9a207b95190bc351eaa23561 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef SRC_COMPONENTS_REMOTE_CONTROL_INCLUDE_REMOTE_CONTROL_RESOURCE_ALLOCATION_H
#define SRC_COMPONENTS_REMOTE_CONTROL_INCLUDE_REMOTE_CONTROL_RESOURCE_ALLOCATION_H
#include <string>
#include "utils/macro.h"
#include "utils/shared_ptr_helpers.h"
#include "interfaces/HMI_API.h"
#include "remote_control/event_engine/event.h"
#include "functional_module/generic_module.h"

namespace remote_control {

/**
 * Enum for list of results of allocation resources
 */
namespace AcquireResult {
enum eType { ALLOWED = 0, IN_USE, ASK_DRIVER, REJECTED };
}

/**
 * Defines states of acquired resource
 */
namespace ResourceState {
enum eType { FREE = 0, BUSY };
}

/**
 * @brief Resources defines list of resources
 */
typedef std::vector<std::string> Resources;

class ResourceAllocationManager {
 public:
  /**
   * @brief AcquireResource acquires resource by application
   * @param module_type resource to acquire
   * @param app_id application that acquire resource
   * @return ALLOWED if resource acquired \
   *         IN_USE  if subscription is not allowed
   *         ASK_DRIVER if driver confirmation is required
   */
  virtual AcquireResult::eType AcquireResource(const std::string& module_type,
                                               const uint32_t app_id) = 0;

  /**
   * @brief SetResourceState changes resource state. Resource must be acquired
   * beforehand.
   * @param module_type Resource to change its state
   * @param app_id Application aquired resource before
   * @param state State to set for resource
   */
  virtual void SetResourceState(const std::string& module_type,
                                const uint32_t app_id,
                                const ResourceState::eType state) = 0;

  /**
   * @brief IsResourceFree check resource state
   * @param module_type Resource name
   * @return True if free, otherwise - false
   */
  virtual bool IsResourceFree(const std::string& module_type) const = 0;

  /**
   * @brief AcquireResource forces acquiring resource by application
   * @param module_type resource to acquire
   * @param app_id application that acquire resource
   */
  virtual void ForceAcquireResource(const std::string& module_type,
                                    const uint32_t app_id) = 0;

  /**
   * @brief OnDriverDisallowed callback for rejecting acquiring resource
   * @param module_type resource type
   * @param app_id application id
   */
  virtual void OnDriverDisallowed(const std::string& module_type,
                                  const uint32_t app_id) = 0;

  /**
   * @brief OnApplicationEvent Processes application related events
   * @param event Event
   * @param application Pointer to application struct
   */
  virtual void OnApplicationEvent(
      functional_modules::ApplicationEvent event,
      application_manager::ApplicationSharedPtr application) = 0;

  /**
   * @brief OnPolicyEvent Processes policy related events
   * @param event Policy event
   */
  virtual void OnPolicyEvent(functional_modules::PolicyEvent event) = 0;

  /**
   * @brief Set current access mode for acquiring resource
   * @param access_mode
   */
  virtual void SetAccessMode(
      const hmi_apis::Common_RCAccessMode::eType access_mode) = 0;

  /**
   * @brief Get last set access mode for acquiring resource
   * @param access_mode
   */
  virtual hmi_apis::Common_RCAccessMode::eType GetAccessMode() const = 0;

  /**
   * @brief Remove all information about all allocations
   */
  virtual void ResetAllAllocations() = 0;

  virtual ~ResourceAllocationManager() {}
};

}  // namespace remote_control
#endif  // SRC_COMPONENTS_REMOTE_CONTROL_INCLUDE_REMOTE_CONTROL_RESOURCE_ALLOCATION_H