Debian Codegraph @

liblomiri-app-launch/jobs-posix.h

raw
1 /*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Ted Gould <[email protected]>
18 */
19
20 #pragma once
21
22 #include "jobs-base.h"
23 #include <chrono>
24 #include <future>
25 #include <gio/gio.h>
26 #include <map>
27 #include <memory>
28 #include <mutex>
29 #include <signal-unsubscriber.h>
30 #include <lomiri/util/ResourcePtr.h>
31
32 namespace lomiri
33 {
34 namespace app_launch
35 {
36 namespace jobs
37 {
38 namespace manager
39 {
40
41 class POSIX : public Base
42 {
43 public:
44 POSIX(const std::shared_ptr<Registry::Impl>& registry);
45 virtual ~POSIX();
46
47 virtual std::shared_ptr<Application::Instance> launch(
48 const AppID& appId,
49 const std::string& job,
50 const std::string& instance,
51 const std::vector<Application::URL>& urls,
52 launchMode mode,
53 std::function<std::list<std::pair<std::string, std::string>>(void)>& getenv) override;
54 virtual std::shared_ptr<Application::Instance> existing(const AppID& appId,
55 const std::string& job,
56 const std::string& instance,
57 const std::vector<Application::URL>& urls) override;
58
59 virtual std::list<std::string> runningAppIds(const std::list<std::string>& jobs) override;
60
61 virtual std::vector<std::shared_ptr<instance::Base>> instances(const AppID& appID, const std::string& job) override;
62
63 virtual core::Signal<const std::string&, const std::string&, const std::string&>& jobStarted() override;
64 virtual core::Signal<const std::string&, const std::string&, const std::string&>& jobStopped() override;
65 virtual core::Signal<const std::string&, const std::string&, const std::string&, Registry::FailureType>& jobFailed()
66 override;
67
68 pid_t unitPrimaryPid(const AppID& appId, const std::string& job, const std::string& instance);
69 std::vector<pid_t> unitPids(const AppID& appId, const std::string& job, const std::string& instance);
70 void stopUnit(const AppID& appId, const std::string& job, const std::string& instance);
71
72 private:
73
74 std::vector<pid_t> launchedpids;
75 // std::string cgroup_root_;
76 //
77 // /** Connection to the User DBus bus */
78 // std::shared_ptr<GDBusConnection> userbus_;
79 // /** Setup the bus and all the details in it */
80 // void setupUserbus(const std::shared_ptr<Registry::Impl>& reg);
81 //
82 core::Signal<const std::string&, const std::string&, const std::string&> sig_jobStarted;
83 core::Signal<const std::string&, const std::string&, const std::string&> sig_jobStopped;
84 core::Signal<const std::string&, const std::string&, const std::string&, Registry::FailureType> sig_jobFailed;
85 //
86 // ManagedDBusSignalConnection handle_unitNew; /**< GDBus signal watcher handle for the unit new signal */
87 // ManagedDBusSignalConnection handle_unitRemoved; /**< GDBus signal watcher handle for the unit removed signal */
88 // ManagedDBusSignalConnection handle_appFailed; /**< GDBus signal watcher handle for app failed signal */
89 //
90 // bool noResetUnits_{false}; /**< Debug flag to avoid resetting the systemd units */
91 //
92 // std::once_flag
93 // flag_appFailed; /**< Variable to track to see if signal handlers are installed for application failed */
94 //
95 // struct UnitInfo
96 // {
97 // std::string appid;
98 // std::string job;
99 // std::string inst;
100 //
101 // bool operator<(const UnitInfo& b) const
102 // {
103 // if (job != b.job)
104 // return job < b.job;
105 //
106 // if (appid != b.appid)
107 // return appid < b.appid;
108 //
109 // return inst < b.inst;
110 // }
111 // };
112 //
113 // void getInitialUnits(const std::shared_ptr<GDBusConnection>& bus, const std::shared_ptr<GCancellable>& cancel);
114 //
115 // struct UnitData
116 // {
117 // std::string jobpath;
118 // std::string unitpath;
119 // };
120 //
121 // std::map<UnitInfo, std::shared_ptr<UnitData>> unitPaths;
122 // UnitInfo parseUnit(const std::string& unit) const;
123 // std::string unitName(const UnitInfo& info) const;
124 // std::string unitPath(const UnitInfo& info);
125 //
126 // UnitInfo unitNew(const std::string& name, const std::string& path, const std::shared_ptr<GDBusConnection>& bus);
127 // void unitRemoved(const std::string& name, const std::string& path);
128 //
129 static std::string findEnv(const std::string& value, std::list<std::pair<std::string, std::string>>& env);
130 static void removeEnv(const std::string& value, std::list<std::pair<std::string, std::string>>& env);
131 static void copyEnv(const std::string& envname, std::list<std::pair<std::string, std::string>>& env);
132 static void copyEnvByPrefix(const std::string& prefix, std::list<std::pair<std::string, std::string>>& env);
133 static int envSize(std::list<std::pair<std::string, std::string>>& env);
134
135 static std::vector<std::string> parseExec(std::list<std::pair<std::string, std::string>>& env);
136 // static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data);
137 //
138 // void resetUnit(const UnitInfo& info);
139 };
140
141 } // namespace manager
142 } // namespace jobs
143 } // namespace app_launch
144 } // namespace lomiri