blob: 0f67a209bf29338f62be17a154d1b83e17669811 [file] [log] [blame]
Patrick Venture3ecb3502019-05-17 11:03:51 -07001#pragma once
2
3#include "config.h"
4
5#include "status.hpp"
6
7#include <memory>
8#include <string>
9
10#if HAVE_SDBUSPLUS
11#include <sdbusplus/bus.hpp>
12#else
13namespace sdbusplus
14{
15namespace bus
16{
17class bus
18{
19};
20} // namespace bus
21} // namespace sdbusplus
22#endif
23
24namespace blobs
25{
26
27class VerificationInterface
28{
29 public:
30 virtual ~VerificationInterface() = default;
31
32 /**
33 * Trigger verification service.
34 *
35 * @return true if successfully started, false otherwise.
36 */
37 virtual bool triggerVerification() = 0;
38
39 /** Abort the verification process. */
40 virtual void abortVerification() = 0;
41
42 /** Check the current state of the verification process. */
43 virtual VerifyCheckResponses checkVerificationState() = 0;
44};
45
46/**
47 * Representation of what is used for verification. Currently, this reduces the
48 * chance of error by using an object instead of two strings to control the
49 * verification step, however, it leaves room for a future possibility out
50 * something wholly configurable.
51 */
52class Verification : public VerificationInterface
53{
54 public:
55 /**
56 * Create a default Verification object that uses systemd to trigger the
57 * process.
58 *
59 * @param[in] bus - an sdbusplus handler for a bus to use.
60 * @param[in] path - the path to check for verification status.
61 * @param[in[ service - the systemd service to start to trigger
62 * verification.
63 */
64 static std::unique_ptr<VerificationInterface>
65 CreateDefaultVerification(sdbusplus::bus::bus&& bus,
66 const std::string& path,
67 const std::string& service);
68
69 Verification(sdbusplus::bus::bus&& bus, const std::string& path,
70 const std::string& service) :
71 bus(std::move(bus)),
72 checkPath(path), triggerService(service)
73 {
74 }
75
76 ~Verification() = default;
77 Verification(const Verification&) = delete;
78 Verification& operator=(const Verification&) = delete;
79 Verification(Verification&&) = default;
80 Verification& operator=(Verification&&) = default;
81
82 bool triggerVerification() override;
83 void abortVerification() override;
84 VerifyCheckResponses checkVerificationState() override;
85
86 private:
87 sdbusplus::bus::bus bus;
88 const std::string checkPath;
89 const std::string triggerService;
90};
91
92} // namespace blobs