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

mendersoftware / mender / 950545443

pending completion
950545443

push

gitlab-ci

vpodzime
feat: Introduce deployments::DeploymentLog

A simple class that can scope logging of a specific deployment.

Ticket: MEN-6578
Changelog: none
Signed-off-by: Vratislav Podzimek <v.podzimek@mykolab.com>

93 of 93 new or added lines in 1 file covered. (100.0%)

4283 of 5387 relevant lines covered (79.51%)

159.37 hits per line

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

70.37
/common/events/events_io.cpp
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
#include <common/events_io.hpp>
16

17
namespace mender {
18
namespace common {
19
namespace events {
20
namespace io {
21

22
AsyncReaderFromReader::AsyncReaderFromReader(EventLoop &loop, mio::ReaderPtr reader) :
×
23
        reader_(reader),
24
        loop_(loop) {
×
25
}
×
26

27
AsyncReaderFromReader::~AsyncReaderFromReader() {
×
28
        Cancel();
×
29
}
×
30

31
error::Error AsyncReaderFromReader::AsyncRead(
512✔
32
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end, mio::AsyncIoHandler handler) {
33
        // Simple, "cheating" implementation, we just do it synchronously.
34
        in_progress_ = true;
512✔
35
        loop_.Post([this, start, end, handler]() {
512✔
36
                auto result = reader_->Read(start, end);
512✔
37
                in_progress_ = false;
512✔
38
                handler(result);
512✔
39
        });
1,536✔
40

41
        return error::NoError;
512✔
42
}
43

44
void AsyncReaderFromReader::Cancel() {
41✔
45
        // Cancel() is not allowed on normal Readers.
46
        assert(!in_progress_);
41✔
47
}
41✔
48

49
AsyncWriterFromWriter::AsyncWriterFromWriter(EventLoop &loop, mio::WriterPtr writer) :
×
50
        writer_(writer),
51
        loop_(loop) {
×
52
}
×
53

54
AsyncWriterFromWriter::~AsyncWriterFromWriter() {
×
55
        Cancel();
×
56
}
×
57

58
error::Error AsyncWriterFromWriter::AsyncWrite(
1✔
59
        vector<uint8_t>::const_iterator start,
60
        vector<uint8_t>::const_iterator end,
61
        mio::AsyncIoHandler handler) {
62
        // Simple, "cheating" implementation, we just do it synchronously.
63
        in_progress_ = true;
1✔
64
        loop_.Post([this, start, end, handler]() {
1✔
65
                auto result = writer_->Write(start, end);
1✔
66
                in_progress_ = false;
1✔
67
                handler(result);
1✔
68
        });
3✔
69

70
        return error::NoError;
1✔
71
}
72

73
void AsyncWriterFromWriter::Cancel() {
1✔
74
        // Cancel() is not allowed on normal Writers.
75
        assert(!in_progress_);
1✔
76
}
1✔
77

78
ReaderFromAsyncReader::ReaderFromAsyncReader() {
×
79
}
×
80

81
mio::ExpectedReaderPtr ReaderFromAsyncReader::Construct(AsyncReaderFromEventLoopFunc func) {
1✔
82
        shared_ptr<ReaderFromAsyncReader> reader(new ReaderFromAsyncReader);
2✔
83
        auto async_reader = func(reader->event_loop_);
2✔
84
        if (!async_reader) {
1✔
85
                return expected::unexpected(async_reader.error());
×
86
        }
87

88
        reader->reader_ = async_reader.value();
1✔
89
        return reader;
1✔
90
}
91

92
mio::ExpectedSize ReaderFromAsyncReader::Read(
1✔
93
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
94
        mio::ExpectedSize read;
1✔
95
        error::Error err;
2✔
96
        err = reader_->AsyncRead(start, end, [this, &read](mio::ExpectedSize num_read) {
2✔
97
                read = num_read;
1✔
98
                event_loop_.Stop();
1✔
99
        });
2✔
100
        if (err != error::NoError) {
1✔
101
                return expected::unexpected(err);
×
102
        }
103

104
        event_loop_.Run();
1✔
105

106
        return read;
1✔
107
}
108

109
} // namespace io
110
} // namespace events
111
} // namespace common
112
} // namespace mender
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