Debian Codegraph @

liblomiri-app-launch/snapd-info.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 <list>
23 #include <memory>
24 #include <set>
25 #include <functional>
26
27 #include <json-glib/json-glib.h>
28
29 #include "appid.h"
30
31 namespace lomiri
32 {
33 namespace app_launch
34 {
35 namespace snapd
36 {
37
38 /** Class that implements the connection to Snapd allowing us to get info
39 from it in a C++ friendly way. */
40 class Info
41 {
42 public:
43 Info();
44 virtual ~Info() = default;
45
46 /** Information that we can get from snapd about a package */
47 struct PkgInfo
48 {
49 std::string name; /**< Name of the package */
50 std::string version; /**< Version string provided by the package */
51 std::string revision; /**< Numerical always incrementing revision of the package */
52 std::string directory; /**< Directory that the snap is uncompressed into */
53 std::set<std::string> appnames; /**< List of appnames in the snap */
54 };
55 std::shared_ptr<PkgInfo> pkgInfo(const AppID::Package &package) const;
56
57 std::set<AppID> appsForInterface(const std::string &interface) const;
58
59 std::set<std::string> interfacesForAppId(const AppID &appid) const;
60
61 private:
62 /** Path to the socket of snapd */
63 std::string snapdSocket;
64 /** Directory to use as the base for all snap packages when making paths. This
65 can be overridden with LOMIRI_APP_LAUNCH_SNAP_BASEDIR */
66 std::string snapBasedir;
67 /** Result of a check at init to see if the socket is available. If
68 not all functions will return null results. */
69 bool snapdExists = false;
70
71 std::shared_ptr<JsonNode> snapdJson(const std::string &endpoint) const;
72 void forAllPlugs(std::function<void(JsonObject *plugobj)> plugfunc) const;
73 };
74
75 } // namespace snapd
76 } // namespace app_launch
77 } // namespace lomiri