Debian Codegraph @

liblomiri-app-launch/registry-impl.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 "app-store-base.h"
23 #include "glib-thread.h"
24 #include "info-watcher-zg.h"
25 #include "jobs-base.h"
26 #include "registry.h"
27 #include "snapd-info.h"
28 #include <click.h>
29 #include <gio/gio.h>
30 #include <json-glib/json-glib.h>
31 #include <map>
32 #include <mutex>
33 #include <unordered_map>
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
36 #include <zeitgeist.h>
37 #pragma GCC diagnostic pop
38
39 namespace lomiri
40 {
41 namespace app_launch
42 {
43
44 class IconFinder;
45 namespace app_store
46 {
47 class Base;
48 }
49
50 /** \private
51 \brief Private implementation of the Registry object
52
53 */
54 class Registry::Impl
55 {
56 public:
57 Impl();
58
59 virtual ~Impl()
60 {
61 thread.quit();
62 }
63
64 std::shared_ptr<JsonObject> getClickManifest(const std::string& package);
65 std::list<AppID::Package> getClickPackages();
66 std::string getClickDir(const std::string& package);
67
68 static void setManager(const std::shared_ptr<Registry::Manager>& manager,
69 const std::shared_ptr<Registry>& registry);
70 void clearManager();
71
72 /** Shared context thread for events and background tasks
73 that UAL subtasks are doing */
74 GLib::ContextThread thread;
75 /** DBus shared connection for the session bus */
76 std::shared_ptr<GDBusConnection> _dbus;
77
78 /** Snapd information object */
79 snapd::Info snapdInfo;
80
81 std::shared_ptr<IconFinder>& getIconFinder(std::string basePath);
82
83 virtual void zgSendEvent(AppID appid, const std::string& eventtype);
84
85 static std::string printJson(std::shared_ptr<JsonObject> jsonobj);
86 static std::string printJson(std::shared_ptr<JsonNode> jsonnode);
87
88 /* Signal Hints */
89 /* NOTE: Static because we don't have registry instances in the C
90 code right now. We want these to not be static in the future */
91 static void watchingAppStarting(bool rWatching);
92 static bool isWatchingAppStarting();
93
94 const std::string& oomHelper() const
95 {
96 return oomHelper_;
97 }
98
99 std::shared_ptr<info_watcher::Zeitgeist> getZgWatcher()
100 {
101 return zgWatcher_;
102 }
103
104 void setZgWatcher(const std::shared_ptr<info_watcher::Zeitgeist>& watcher)
105 {
106 zgWatcher_ = watcher;
107 }
108
109 core::Signal<const std::shared_ptr<Application>&>& appInfoUpdated();
110 core::Signal<const std::shared_ptr<Application>&>& appAdded();
111 core::Signal<const AppID&>& appRemoved();
112
113 const std::list<std::shared_ptr<app_store::Base>>& appStores()
114 {
115 return _appStores;
116 }
117
118 void setAppStores(const std::list<std::shared_ptr<app_store::Base>>& newlist)
119 {
120 _appStores = newlist;
121 }
122
123 const std::shared_ptr<jobs::manager::Base>& jobs()
124 {
125 if (G_UNLIKELY(!jobs_))
126 {
127 throw std::runtime_error{"Registry Implementation has no Jobs object"};
128 }
129 return jobs_;
130 }
131
132 void setJobs(const std::shared_ptr<jobs::manager::Base>& jobs)
133 {
134 jobs_ = jobs;
135 }
136
137 /* Create functions */
138 std::shared_ptr<Application> createApp(const AppID& appid);
139 std::shared_ptr<Helper> createHelper(const Helper::Type& type,
140 const AppID& appid,
141 const std::shared_ptr<Registry::Impl>& sharedimpl);
142
143 /* AppID functions */
144 AppID find(const std::string& sappid);
145 AppID discover(const std::string& package, const std::string& appname, const std::string& version);
146 AppID discover(const std::string& package,
147 AppID::ApplicationWildcard appwildcard,
148 AppID::VersionWildcard versionwildcard);
149 AppID discover(const std::string& package, const std::string& appname, AppID::VersionWildcard versionwildcard);
150
151 private:
152 /** The job creation engine */
153 std::shared_ptr<jobs::manager::Base> jobs_;
154
155 std::shared_ptr<ClickDB> _clickDB;
156 std::shared_ptr<ClickUser> _clickUser;
157
158 void initClick();
159
160 /** Shared instance of the Zeitgeist Log */
161 std::shared_ptr<ZeitgeistLog> zgLog_;
162
163 /** All of our icon finders based on the path that they're looking
164 into */
165 std::unordered_map<std::string, std::shared_ptr<IconFinder>> _iconFinders;
166 std::mutex _iconFindersMutex;
167
168 /** Path to the OOM Helper */
169 std::string oomHelper_;
170
171 /** Application stores */
172 std::list<std::shared_ptr<app_store::Base>> _appStores;
173
174 /** Signal for application info changing */
175 core::Signal<const std::shared_ptr<Application>&> sig_appInfoUpdated;
176 /** Signal for applications added */
177 core::Signal<const std::shared_ptr<Application>&> sig_appAdded;
178 /** Signal for applications removed */
179 core::Signal<const AppID&> sig_appRemoved;
180
181 void infoWatchersSetup(const std::shared_ptr<Registry>& reg);
182 /** Flag to see if we've initialized the info watcher list */
183 std::once_flag flag_infoWatchersSetup;
184 struct infoWatcherConnections
185 {
186 core::ScopedConnection infoUpdated;
187 core::ScopedConnection appAdded;
188 core::ScopedConnection appRemoved;
189 };
190 /** List of info watchers along with a signal handle to our connection to their update signal */
191 std::list<std::pair<std::shared_ptr<info_watcher::Base>, infoWatcherConnections>> infoWatchers_;
192 void infoWatchersSetup();
193
194 /** ZG Info Watcher */
195 std::shared_ptr<info_watcher::Zeitgeist> zgWatcher_;
196 };
197
198 } // namespace app_launch
199 } // namespace lomiri