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

mavlink / MAVSDK / 6568658631

19 Oct 2023 01:31AM UTC coverage: 31.23% (+0.02%) from 31.215%
6568658631

push

github

web-flow
Merge pull request #2155 from mavlink/pr-static-fixes

Threading fixes, MAVLink sequence number cleanup

1386 of 1386 new or added lines in 46 files covered. (100.0%)

7906 of 25315 relevant lines covered (31.23%)

23.54 hits per line

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

75.0
/src/mavsdk/core/log.cpp
1
#include "log.h"
2
#include "unused.h"
3

4
#include <mutex>
5

6
#if defined(WINDOWS)
7
#include "windows_include.h"
8
#define WIN_COLOR_RED 4
9
#define WIN_COLOR_GREEN 10
10
#define WIN_COLOR_YELLOW 14
11
#define WIN_COLOR_BLUE 1
12
#define WIN_COLOR_GRAY 8
13
#define WIN_COLOR_RESET 7
14
#else
15
#define ANSI_COLOR_RED "\x1b[31m"
16
#define ANSI_COLOR_GREEN "\x1b[32m"
17
#define ANSI_COLOR_YELLOW "\x1b[33m"
18
#define ANSI_COLOR_BLUE "\x1b[34m"
19
#define ANSI_COLOR_GRAY "\x1b[37m"
20
#define ANSI_COLOR_RESET "\x1b[0m"
21
#endif
22

23
namespace mavsdk {
24

25
static std::mutex callback_mutex_{};
26
static log::Callback callback_{nullptr};
27

28
log::Callback& log::get_callback()
330✔
29
{
30
    std::lock_guard<std::mutex> lock(callback_mutex_);
330✔
31
    return callback_;
330✔
32
}
33

34
void log::subscribe(const log::Callback& callback)
×
35
{
36
    std::lock_guard<std::mutex> lock(callback_mutex_);
×
37
    callback_ = callback;
×
38
}
×
39

40
void set_color(Color color)
660✔
41
{
42
#if defined(WINDOWS)
43
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
44
    switch (color) {
45
        case Color::Red:
46
            SetConsoleTextAttribute(handle, WIN_COLOR_RED);
47
            break;
48
        case Color::Green:
49
            SetConsoleTextAttribute(handle, WIN_COLOR_GREEN);
50
            break;
51
        case Color::Yellow:
52
            SetConsoleTextAttribute(handle, WIN_COLOR_YELLOW);
53
            break;
54
        case Color::Blue:
55
            SetConsoleTextAttribute(handle, WIN_COLOR_BLUE);
56
            break;
57
        case Color::Gray:
58
            SetConsoleTextAttribute(handle, WIN_COLOR_GRAY);
59
            break;
60
        case Color::Reset:
61
            SetConsoleTextAttribute(handle, WIN_COLOR_RESET);
62
            break;
63
    }
64
#elif defined(ANDROID) || defined(IOS)
65
    UNUSED(color);
66
#else
67
    switch (color) {
660✔
68
        case Color::Red:
38✔
69
            std::cout << ANSI_COLOR_RED;
38✔
70
            break;
38✔
71
        case Color::Green:
150✔
72
            std::cout << ANSI_COLOR_GREEN;
150✔
73
            break;
150✔
74
        case Color::Yellow:
106✔
75
            std::cout << ANSI_COLOR_YELLOW;
106✔
76
            break;
106✔
77
        case Color::Blue:
36✔
78
            std::cout << ANSI_COLOR_BLUE;
36✔
79
            break;
36✔
80
        case Color::Gray:
×
81
            std::cout << ANSI_COLOR_GRAY;
×
82
            break;
×
83
        case Color::Reset:
330✔
84
            std::cout << ANSI_COLOR_RESET;
330✔
85
            break;
330✔
86
    }
87
#endif
88
}
660✔
89

90
} // namespace mavsdk
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

© 2026 Coveralls, Inc