summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/app_launch/device_apps_launcher.h
blob: f27e4569fc657c6ab51f86b4a65bdfc42c59834f (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
#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APP_LAUNCH_DEVICE_APPS_LAUNCHER_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APP_LAUNCH_DEVICE_APPS_LAUNCHER_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "application_manager/app_launch/app_launch_data.h"
#include "application_manager/app_launch_settings.h"
#include "application_manager/application_manager.h"

namespace app_launch {
class AppLaunchCtrlImpl;
class DeviceAppsLauncher;
class AppsLauncher;
class AppLaunchSettings;
class Launcher;
class LauncherGenerator;

// impl class must be defined for unique_ptr in DeviceAppsLauncher
class DeviceAppsLauncherImpl {
 public:
  DeviceAppsLauncherImpl(DeviceAppsLauncher& interface,
                         AppsLauncher& apps_launcher);

  bool LaunchAppsOnDevice(
      const std::string& device_mac,
      const std::vector<ApplicationDataPtr>& applications_to_launch);

  struct LauncherFinder {
    LauncherFinder(const std::string& device_mac) : device_mac_(device_mac) {}

    bool operator()(const std::shared_ptr<Launcher>& launcher) const;

    std::string device_mac_;
  };

  bool StopLaunchingAppsOnDevice(const std::string& device_mac);

 private:
  sync_primitives::Lock launchers_lock_;
  std::vector<std::shared_ptr<Launcher> > free_launchers_;
  std::vector<std::shared_ptr<Launcher> > works_launchers_;
  DeviceAppsLauncher& interface_;
};

/**
 * @brief The MultipleAppsLauncher struct
 * should manage launching applications and gaps between launching application
 * on one device
 * When all apps launched it will notify AppLaunchCtrlImpl that all apps
 * launched
 */
class DeviceAppsLauncher {
 public:
  DeviceAppsLauncher(application_manager::ApplicationManager& app_mngr,
                     app_launch::AppsLauncher& apps_launcher,
                     const AppLaunchSettings& settings);

  bool LaunchAppsOnDevice(
      const std::string& device_mac,
      const std::vector<ApplicationDataPtr>& applications_to_launch);
  bool StopLaunchingAppsOnDevice(const std::string& device_mac);

  const AppLaunchSettings& settings() const;

 private:
  application_manager::ApplicationManager& app_mngr_;
  const AppLaunchSettings& settings_;
  std::unique_ptr<DeviceAppsLauncherImpl> impl_;
  friend class DeviceAppsLauncherImpl;
  DISALLOW_COPY_AND_ASSIGN(DeviceAppsLauncher);
};

}  // namespace app_launch

#endif  // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_APP_LAUNCH_DEVICE_APPS_LAUNCHER_H_