Debian Codegraph @

liblomiri-app-launch/registry.cpp

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 #include <algorithm>
21 #include <numeric>
22 #include <regex>
23
24 #include "info-watcher-zg.h"
25 #include "jobs-base.h"
26 #include "registry-impl.h"
27 #include "registry.h"
28
29 namespace lomiri
30 {
31 namespace app_launch
32 {
33
34 Registry::Registry()
35 : impl{std::make_shared<Impl>()}
36 {
37 impl->setJobs(jobs::manager::Base::determineFactory(impl));
38 impl->setAppStores(app_store::Base::allAppStores(impl));
39 impl->setZgWatcher(std::make_shared<info_watcher::Zeitgeist>(impl));
40 }
41
42 Registry::Registry(const std::shared_ptr<Impl>& inimpl)
43 : impl{inimpl}
44 {
45 /* We're assuming the impl has been setup */
46 }
47
48 Registry::~Registry()
49 {
50 }
51
52 std::list<std::shared_ptr<Application>> Registry::runningApps(std::shared_ptr<Registry> registry)
53 {
54 return registry->impl->jobs()->runningApps();
55 }
56
57 std::list<std::shared_ptr<Application>> Registry::installedApps(std::shared_ptr<Registry> connection)
58 {
59 std::list<std::shared_ptr<Application>> list;
60
61 for (const auto& appStore : connection->impl->appStores())
62 {
63 list.splice(list.begin(), appStore->list());
64 }
65
66 return list;
67 }
68
69 std::list<std::shared_ptr<Helper>> Registry::runningHelpers(Helper::Type type, std::shared_ptr<Registry> registry)
70 {
71 return registry->impl->jobs()->runningHelpers(type);
72 }
73
74 void Registry::setManager(const std::shared_ptr<Manager>& manager, const std::shared_ptr<Registry>& registry)
75 {
76 registry->impl->jobs()->setManager(manager);
77 }
78
79 void Registry::clearManager()
80 {
81 impl->jobs()->clearManager();
82 }
83
84 std::shared_ptr<Registry> defaultRegistry;
85 std::shared_ptr<Registry> Registry::getDefault()
86 {
87 if (!defaultRegistry)
88 {
89 defaultRegistry = std::make_shared<Registry>();
90 }
91
92 return defaultRegistry;
93 }
94
95 void Registry::clearDefault()
96 {
97 defaultRegistry.reset();
98 }
99
100 core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&>& Registry::appStarted(
101 const std::shared_ptr<Registry>& reg)
102 {
103 return reg->impl->jobs()->appStarted();
104 }
105
106 core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&>& Registry::appStopped(
107 const std::shared_ptr<Registry>& reg)
108 {
109 return reg->impl->jobs()->appStopped();
110 }
111
112 core::Signal<const std::shared_ptr<Application>&, const std::shared_ptr<Application::Instance>&, Registry::FailureType>&
113 Registry::appFailed(const std::shared_ptr<Registry>& reg)
114 {
115 return reg->impl->jobs()->appFailed();
116 }
117
118 core::Signal<const std::shared_ptr<Application>&,
119 const std::shared_ptr<Application::Instance>&,
120 const std::vector<pid_t>&>&
121 Registry::appPaused(const std::shared_ptr<Registry>& reg)
122 {
123 return reg->impl->jobs()->appPaused();
124 }
125
126 core::Signal<const std::shared_ptr<Application>&,
127 const std::shared_ptr<Application::Instance>&,
128 const std::vector<pid_t>&>&
129 Registry::appResumed(const std::shared_ptr<Registry>& reg)
130 {
131 return reg->impl->jobs()->appResumed();
132 }
133
134 core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&>& Registry::helperStarted(
135 Helper::Type type, const std::shared_ptr<Registry>& reg)
136 {
137 return reg->impl->jobs()->helperStarted(type);
138 }
139
140 core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&>& Registry::helperStopped(
141 Helper::Type type, const std::shared_ptr<Registry>& reg)
142 {
143 return reg->impl->jobs()->helperStopped(type);
144 }
145
146 core::Signal<const std::shared_ptr<Helper>&, const std::shared_ptr<Helper::Instance>&, Registry::FailureType>&
147 Registry::helperFailed(Helper::Type type, const std::shared_ptr<Registry>& reg)
148 {
149 return reg->impl->jobs()->helperFailed(type);
150 }
151
152 core::Signal<const std::shared_ptr<Application>&>& Registry::appInfoUpdated(const std::shared_ptr<Registry>& reg)
153 {
154 return reg->impl->appInfoUpdated();
155 }
156
157 core::Signal<const std::shared_ptr<Application>&>& Registry::appAdded(const std::shared_ptr<Registry>& reg)
158 {
159 return reg->impl->appAdded();
160 }
161
162 core::Signal<const AppID&>& Registry::appRemoved(const std::shared_ptr<Registry>& reg)
163 {
164 return reg->impl->appRemoved();
165 }
166
167 } // namespace app_launch
168 } // namespace lomiri