~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-yakkety-landing-072

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/application-impl-base.h

Migrate starting and stopping applications to new classes

Approved by: Charles Kerr, unity-api-1-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
extern "C" {
23
23
#include "ubuntu-app-launch.h"
 
24
#include <gio/gio.h>
24
25
}
25
26
 
26
27
#pragma once
32
33
namespace app_impls
33
34
{
34
35
 
 
36
/** Provides some helper functions that can be used by all
 
37
    implementations of application. Stores the registry pointer
 
38
    which everyone wants anyway. */
35
39
class Base : public ubuntu::app_launch::Application
36
40
{
37
41
public:
40
44
    bool hasInstances() override;
41
45
 
42
46
protected:
 
47
    /** Pointer to the registry so we can ask it for things */
43
48
    std::shared_ptr<Registry> _registry;
 
49
 
 
50
    static std::list<std::pair<std::string, std::string>> confinedEnv(const std::string& package,
 
51
                                                                      const std::string& pkgdir);
44
52
};
45
53
 
 
54
/** An object that represents an instance of a job on Upstart. This
 
55
    then implements everything needed by the instance interface. Most
 
56
    applications tie into this today and use it as the backend for
 
57
    their instances. */
46
58
class UpstartInstance : public Application::Instance
47
59
{
48
60
public:
49
61
    explicit UpstartInstance(const AppID& appId,
50
62
                             const std::string& job,
51
63
                             const std::string& instance,
 
64
                             const std::vector<Application::URL>& urls,
52
65
                             const std::shared_ptr<Registry>& registry);
53
66
 
54
67
    /* Query lifecycle */
67
80
    void setOomAdjustment(const oom::Score score) override;
68
81
    const oom::Score getOomAdjustment() override;
69
82
 
70
 
    /* Creating by launch */
 
83
    /** Flag for whether we should include the testing environment variables */
71
84
    enum class launchMode
72
85
    {
73
 
        STANDARD,
74
 
        TEST
 
86
        STANDARD, /**< Standard variable set */
 
87
        TEST      /**< Include testing environment vars */
75
88
    };
76
 
    static std::shared_ptr<UpstartInstance> launch(const AppID& appId,
77
 
                                                   const std::string& job,
78
 
                                                   const std::string& instance,
79
 
                                                   const std::vector<Application::URL>& urls,
80
 
                                                   const std::shared_ptr<Registry>& registry,
81
 
                                                   launchMode mode);
 
89
    static std::shared_ptr<UpstartInstance> launch(
 
90
        const AppID& appId,
 
91
        const std::string& job,
 
92
        const std::string& instance,
 
93
        const std::vector<Application::URL>& urls,
 
94
        const std::shared_ptr<Registry>& registry,
 
95
        launchMode mode,
 
96
        std::function<std::list<std::pair<std::string, std::string>>(void)>& getenv);
82
97
 
83
98
private:
 
99
    /** Application ID */
84
100
    const AppID appId_;
 
101
    /** Upstart job name */
85
102
    const std::string job_;
 
103
    /** Instance ID environment value, empty if none */
86
104
    const std::string instance_;
 
105
    /** The URLs that this was launched for. Only valid on launched jobs, we
 
106
        should look at perhaps changing that. */
 
107
    std::vector<Application::URL> urls_;
 
108
    /** A link to the registry we're using for connections */
87
109
    std::shared_ptr<Registry> registry_;
88
110
 
89
111
    std::vector<pid_t> forAllPids(std::function<void(pid_t)> eachPid);
92
114
    void oomValueToPid(pid_t pid, const oom::Score oomvalue);
93
115
    void oomValueToPidHelper(pid_t pid, const oom::Score oomvalue);
94
116
    void pidListToDbus(const std::vector<pid_t>& pids, const std::string& signal);
 
117
 
 
118
    static std::shared_ptr<gchar*> urlsToStrv(const std::vector<Application::URL>& urls);
 
119
    static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data);
95
120
};
96
121
 
97
122
}  // namespace app_impls