• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 951615729

pending completion
951615729

push

gitlab-ci

larsewi
fix: Add 'build/' to '.gitignore'

Ticket: None
Changelog: None
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>

4199 of 5286 relevant lines covered (79.44%)

166.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/mender-update/deployments.hpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#ifndef MENDER_UPDATE_DEPLOYMENTS_HPP
16
#define MENDER_UPDATE_DEPLOYMENTS_HPP
17

18
#include <string>
19
#include <vector>
20

21
#include <common/error.hpp>
22
#include <common/events.hpp>
23
#include <common/expected.hpp>
24
#include <common/http.hpp>
25
#include <common/io.hpp>
26
#include <common/json.hpp>
27
#include <common/optional.hpp>
28
#include <mender-update/context.hpp>
29

30
namespace mender {
31
namespace update {
32
namespace deployments {
33

34
using namespace std;
35

36
namespace context = mender::update::context;
37
namespace error = mender::common::error;
38
namespace events = mender::common::events;
39
namespace expected = mender::common::expected;
40
namespace io = mender::common::io;
41
namespace json = mender::common::json;
42
namespace optional = mender::common::optional;
43

44
enum DeploymentsErrorCode {
45
        NoError = 0,
46
        InvalidDataError,
47
        BadResponseError,
48
};
49

50
class DeploymentsErrorCategoryClass : public std::error_category {
51
public:
52
        const char *name() const noexcept override;
53
        string message(int code) const override;
54
};
55
extern const DeploymentsErrorCategoryClass DeploymentsErrorCategory;
56

57
error::Error MakeError(DeploymentsErrorCode code, const string &msg);
58

59
using CheckUpdatesAPIResponse = expected::expected<optional::optional<json::Json>, error::Error>;
60
using CheckUpdatesAPIResponseHandler = function<void(CheckUpdatesAPIResponse)>;
61

62
error::Error CheckNewDeployments(
63
        context::MenderContext &ctx,
64
        const string &server_url,
65
        http::Client &client,
66
        CheckUpdatesAPIResponseHandler api_handler);
67

68
enum class DeploymentStatus {
69
        Installing = 0,
70
        PauseBeforeInstalling,
71
        Downloading,
72
        PauseBeforeRebooting,
73
        Rebooting,
74
        PauseBeforeCommitting,
75
        Success,
76
        Failure,
77
        AlreadyInstalled,
78

79
        // Not a valid status, just used as an int representing the number of values
80
        // above
81
        End_
82
};
83

84
using StatusAPIResponse = error::Error;
85
using StatusAPIResponseHandler = function<void(StatusAPIResponse)>;
86

87
error::Error PushStatus(
88
        const string &deployment_id,
89
        DeploymentStatus status,
90
        const string &substate,
91
        const string &server_url,
92
        http::Client &client,
93
        StatusAPIResponseHandler api_handler);
94

95
using LogsAPIResponse = error::Error;
96
using LogsAPIResponseHandler = function<void(LogsAPIResponse)>;
97

98
error::Error PushLogs(
99
        const string &deployment_id,
100
        const string &log_file_path,
101
        const string &server_url,
102
        http::Client &client,
103
        LogsAPIResponseHandler api_handler);
104

105
/**
106
 * A helper class only declared here because of testing. Not to be used
107
 * separately outside of PushLogs().
108
 */
109
class JsonLogMessagesReader : virtual public io::Reader {
110
public:
111
        /**
112
         * @see GetLogFileDataSize() for details about #data_size
113
         */
114
        JsonLogMessagesReader(shared_ptr<io::FileReader> raw_data_reader, size_t data_size) :
×
115
                reader_ {raw_data_reader},
116
                raw_data_size_ {data_size},
117
                rem_raw_data_size_ {data_size} {};
×
118

119
        expected::ExpectedSize Read(
120
                vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) override;
121

122
        error::Error Rewind() {
×
123
                header_rem_ = header_.size();
×
124
                closing_rem_ = closing_.size();
×
125
                rem_raw_data_size_ = raw_data_size_;
×
126
                return reader_->Rewind();
×
127
        }
128

129
        static size_t TotalDataSize(size_t raw_data_size) {
×
130
                return raw_data_size + header_.size() + closing_.size();
×
131
        }
132

133
private:
134
        shared_ptr<io::FileReader> reader_;
135
        size_t raw_data_size_;
136
        size_t rem_raw_data_size_;
137
        static const vector<uint8_t> header_;
138
        static const vector<uint8_t> closing_;
139
        io::Vsize header_rem_ = header_.size();
140
        io::Vsize closing_rem_ = closing_.size();
141
};
142

143
} // namespace deployments
144
} // namespace update
145
} // namespace mender
146

147
#endif // MENDER_UPDATE_DEPLOYMENTS_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc